naitokosuke · dotfiles

GUI apps are Homebrew casks (hosts/common/homebrew.nix), so a binary that comes with one cannot be referenced by store path. A module that runs such a binary names the cask here, with the reason, and evaluation fails when the cask is dropped, naming the cask and the module that needs it, instead of the binary silently going missing at runtime. ./adrafinil.nix and ./claude.nix use it, so the rule is written once (#553).

Casks

Evaluated from darwinConfigurations.Mac-big.

CaskRequired by
adrafinilhome/adrafinil.nix runs the Adrafinil CLI
blender
claude
dockdoor
ghostty
google-chrome
monitorcontrol
obs
obsidian
productdevbook/tap/portkiller
raycast
scroll-reverser
stablyai/orca/orca
thebrowsercompany-dia
visual-studio-codehome/claude.nix runs `code` in its plan hook

The check

osConfig is nix-darwin's configuration as seen from home-manager, which is what makes the cask list visible here. nix-darwin normalises homebrew.casks into submodules, so the names are read off name rather than the list itself.

lines 29–32
29
30
31
32  config.assertions = lib.mapAttrsToList (cask: reason: {
    assertion = lib.any (declared: declared.name == cask) osConfig.homebrew.casks;
    message = "${reason}, which the ${cask} cask provides, but that cask is not in hosts/common/homebrew.nix.";
  }) config.naitokosuke.requiredCasks;
View the complete file34 lines · required-casks.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34# GUI apps are Homebrew casks (hosts/common/homebrew.nix), so a binary that
# comes with one cannot be referenced by store path. A module that runs such a
# binary names the cask here, with the reason, and evaluation fails when the
# cask is dropped, naming the cask and the module that needs it, instead of
# the binary silently going missing at runtime. ./adrafinil.nix and
# ./claude.nix use it, so the rule is written once (#553).
{
  config,
  lib,
  osConfig,
  ...
}:

{
  options.naitokosuke.requiredCasks = lib.mkOption {
    type = lib.types.attrsOf lib.types.str;
    default = { };
    example = {
      visual-studio-code = "home/claude.nix runs `code` in its plan hook";
    };
    description = "Homebrew casks that home-manager modules depend on, each with the reason.";
  };

  ## The check
  # `osConfig` is nix-darwin's configuration as seen from home-manager, which
  # is what makes the cask list visible here. nix-darwin normalises
  # homebrew.casks into submodules, so the names are read off `name` rather
  # than the list itself.
  config.assertions = lib.mapAttrsToList (cask: reason: {
    assertion = lib.any (declared: declared.name == cask) osConfig.homebrew.casks;
    message = "${reason}, which the ${cask} cask provides, but that cask is not in hosts/common/homebrew.nix.";
  }) config.naitokosuke.requiredCasks;
}
34 lines·1,350 chars·NIX