naitokosuke · dotfiles

GUI apps are Homebrew casks and CLIs come from Nix (#609). nix-homebrew pins Homebrew itself and the taps as flake inputs, and activation converges the installed casks onto the list below on every rebuild.

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

Homebrew's version label

A flake input reaches modules as a source tree, without the tag it is pinned to, so the tag is read from the lock and the nix-homebrew package below is labelled with it (#432).

lines 17–23
17
18
19
20
21
22
23  brewNode = (lib.importJSON (inputs.self + "/flake.lock")).nodes.brew-src.original;
  brewVersion =
    brewNode.ref or (throw ''
      hosts/common/homebrew.nix expects the brew-src input to be pinned to a tag,
      so the nix-homebrew package can be labelled with that version (#432).
      flake.lock has it as: ${builtins.toJSON brewNode}
    '');

Sudo prompts go to a dialog

Homebrew asks for sudo repeatedly during a cask upgrade, on the terminal nh has nom repainting. With SUDO_ASKPASS set it runs sudo -A, so the prompt becomes a GUI dialog that says what it is for (#416). sudo -A never offers Touch ID, so hosts that have it keep the terminal prompt (#504).

lines 31–35
31
32
33
34
35  sudoAskpass = pkgs.writeShellScript "homebrew-sudo-askpass" ''
    exec /usr/bin/osascript \
      -e 'set reply to display dialog "Homebrew needs administrator rights to update casks during nix-darwin activation." with title "darwin-rebuild" default answer "" with icon caution with hidden answer' \
      -e 'text returned of reply'
  '';

nix-homebrew

Homebrew itself comes from the brew-src input, pinned in flake.nix ahead of the one nix-homebrew locks (#432), and every tap from a flake input. mutableTaps = false disables brew tap, so a new tap arrives as an input.

lines 44–66
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66  nix-homebrew = {
    enable = true;
    # nix-homebrew labels its package with the brew-src ref from its own
    # flake.lock, so the label is rebuilt from the ref pinned here.
    package = inputs.brew-src // {
      name = "brew-${brewVersion}";
      version = brewVersion;
    };
    enableRosetta = false;
    user = config.naitokosuke.username;
    autoMigrate = true;
    taps = {
      "homebrew/homebrew-core" = inputs.homebrew-core;
      "homebrew/homebrew-cask" = inputs.homebrew-cask;
      "productdevbook/homebrew-tap" = inputs.homebrew-productdevbook;
      "stablyai/homebrew-orca" = inputs.homebrew-orca;
    };
    mutableTaps = false;
    # `brew shellenv` would put Homebrew ahead of the Nix profiles on every
    # interactive zsh start; environment.systemPath below adds the one
    # directory needed, after them.
    enableZshIntegration = false;
  };

Homebrew on PATH, after Nix

Cask binaries such as code (the plan hook in home/claude.nix) and Orca's CLI live in /opt/homebrew/bin, which nix-darwin does not put on PATH by itself. Ordered after the Nix profiles and before the system directories.

line 72
72  environment.systemPath = lib.mkOrder 1100 [ "${config.homebrew.prefix}/bin" ];

Taps

Mirror the nix-homebrew-pinned taps into the Brewfile so brew bundle cleanup does not try to untap them.

line 80
80    taps = builtins.attrNames config.nix-homebrew.taps;

Activation policy

Fully declarative (#363): HOMEBREW_NO_INSTALL_FROM_API makes cask definitions come from the flake-pinned taps rather than Homebrew's API, so activation converges the installed apps to flake.lock, and casks removed from the list below are uninstalled. Most of these apps still update themselves independently.

lines 88–98
88
89
90
91
92
93
94
95
96
97
98    onActivation = {
      autoUpdate = false;
      upgrade = true;
      cleanup = "uninstall";
      extraEnv = {
        HOMEBREW_NO_INSTALL_FROM_API = "1";
      }
      // lib.optionalAttrs (!config.security.pam.services.sudo_local.touchIdAuth) {
        SUDO_ASKPASS = "${sudoAskpass}";
      };
    };

Casks

The rule: GUI apps are casks, and CLIs come from Nix (#609). It holds for every app, also the ones nixpkgs could build, so which layer installs an app is never decided per app. Casks keep updating themselves, and their Dock icons and file associations stay put. Third-party taps slot in as <tap>/<cask>.

lines 106–127
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127    casks = [
      # Keeps the Mac awake only while an AI agent is working (see
      # home/adrafinil.nix). Requires macOS 26. Adrafinil updates itself in
      # place, so the flake.lock pin is only the floor version.
      "adrafinil"
      "blender"
      "claude"
      "dockdoor"
      "ghostty"
      "google-chrome"
      "monitorcontrol"
      "obs"
      "obsidian"
      "productdevbook/tap/portkiller"
      "raycast"
      "scroll-reverser"
      # Also ships the `orca` CLI. Orca updates itself in place, so the
      # flake.lock pin is only the floor version.
      "stablyai/orca/orca"
      "thebrowsercompany-dia"
      "visual-studio-code"
    ];
View the complete file130 lines · homebrew.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130# GUI apps are Homebrew casks and CLIs come from Nix (#609). nix-homebrew pins
# Homebrew itself and the taps as flake inputs, and activation converges the
# installed casks onto the list below on every rebuild.
{
  config,
  inputs,
  lib,
  pkgs,
  ...
}:

let
  ## Homebrew's version label
  # A flake input reaches modules as a source tree, without the tag it is
  # pinned to, so the tag is read from the lock and the nix-homebrew package
  # below is labelled with it (#432).
  brewNode = (lib.importJSON (inputs.self + "/flake.lock")).nodes.brew-src.original;
  brewVersion =
    brewNode.ref or (throw ''
      hosts/common/homebrew.nix expects the brew-src input to be pinned to a tag,
      so the nix-homebrew package can be labelled with that version (#432).
      flake.lock has it as: ${builtins.toJSON brewNode}
    '');

  ## Sudo prompts go to a dialog
  # Homebrew asks for sudo repeatedly during a cask upgrade, on the terminal
  # `nh` has `nom` repainting. With SUDO_ASKPASS set it runs `sudo -A`, so
  # the prompt becomes a GUI dialog that says what it is for (#416).
  # `sudo -A` never offers Touch ID, so hosts that have it keep the terminal
  # prompt (#504).
  sudoAskpass = pkgs.writeShellScript "homebrew-sudo-askpass" ''
    exec /usr/bin/osascript \
      -e 'set reply to display dialog "Homebrew needs administrator rights to update casks during nix-darwin activation." with title "darwin-rebuild" default answer "" with icon caution with hidden answer' \
      -e 'text returned of reply'
  '';
in

{
  ## nix-homebrew
  # Homebrew itself comes from the `brew-src` input, pinned in flake.nix ahead
  # of the one nix-homebrew locks (#432), and every tap from a flake input.
  # `mutableTaps = false` disables `brew tap`, so a new tap arrives as an
  # input.
  nix-homebrew = {
    enable = true;
    # nix-homebrew labels its package with the brew-src ref from its own
    # flake.lock, so the label is rebuilt from the ref pinned here.
    package = inputs.brew-src // {
      name = "brew-${brewVersion}";
      version = brewVersion;
    };
    enableRosetta = false;
    user = config.naitokosuke.username;
    autoMigrate = true;
    taps = {
      "homebrew/homebrew-core" = inputs.homebrew-core;
      "homebrew/homebrew-cask" = inputs.homebrew-cask;
      "productdevbook/homebrew-tap" = inputs.homebrew-productdevbook;
      "stablyai/homebrew-orca" = inputs.homebrew-orca;
    };
    mutableTaps = false;
    # `brew shellenv` would put Homebrew ahead of the Nix profiles on every
    # interactive zsh start; environment.systemPath below adds the one
    # directory needed, after them.
    enableZshIntegration = false;
  };

  ## Homebrew on PATH, after Nix
  # Cask binaries such as `code` (the plan hook in home/claude.nix) and Orca's
  # CLI live in /opt/homebrew/bin, which nix-darwin does not put on PATH by
  # itself. Ordered after the Nix profiles and before the system directories.
  environment.systemPath = lib.mkOrder 1100 [ "${config.homebrew.prefix}/bin" ];

  homebrew = {
    enable = true;

    ## Taps
    # Mirror the nix-homebrew-pinned taps into the Brewfile so `brew bundle`
    # cleanup does not try to untap them.
    taps = builtins.attrNames config.nix-homebrew.taps;

    ## Activation policy
    # Fully declarative (#363): HOMEBREW_NO_INSTALL_FROM_API makes cask
    # definitions come from the flake-pinned taps rather than Homebrew's API,
    # so activation converges the installed apps to flake.lock, and casks
    # removed from the list below are uninstalled. Most of these apps still
    # update themselves independently.
    onActivation = {
      autoUpdate = false;
      upgrade = true;
      cleanup = "uninstall";
      extraEnv = {
        HOMEBREW_NO_INSTALL_FROM_API = "1";
      }
      // lib.optionalAttrs (!config.security.pam.services.sudo_local.touchIdAuth) {
        SUDO_ASKPASS = "${sudoAskpass}";
      };
    };

    ## Casks
    # The rule: GUI apps are casks, and CLIs come from Nix (#609). It holds
    # for every app, also the ones nixpkgs could build, so which layer
    # installs an app is never decided per app. Casks keep updating
    # themselves, and their Dock icons and file associations stay put.
    # Third-party taps slot in as `<tap>/<cask>`.
    casks = [
      # Keeps the Mac awake only while an AI agent is working (see
      # home/adrafinil.nix). Requires macOS 26. Adrafinil updates itself in
      # place, so the flake.lock pin is only the floor version.
      "adrafinil"
      "blender"
      "claude"
      "dockdoor"
      "ghostty"
      "google-chrome"
      "monitorcontrol"
      "obs"
      "obsidian"
      "productdevbook/tap/portkiller"
      "raycast"
      "scroll-reverser"
      # Also ships the `orca` CLI. Orca updates itself in place, so the
      # flake.lock pin is only the floor version.
      "stablyai/orca/orca"
      "thebrowsercompany-dia"
      "visual-studio-code"
    ];
  };
}
130 lines·4,944 chars·NIX