modules/homebrew: add postinstall option for brews and casks

Both `brew bundle` formula and cask installers support a `postinstall`
option -- a shell command to run after the package is installed or
upgraded. The command only executes when the package actually changed,
not on every `brew bundle` run.

Examples from the Homebrew docs added to the `homebrew.brews` and
`homebrew.casks` option examples and tests.
This commit is contained in:
Malo Bourgon 2026-02-09 20:21:29 -08:00
parent a3fd89f1bb
commit c65c24c87c
No known key found for this signature in database
2 changed files with 39 additions and 0 deletions

View file

@ -476,6 +476,16 @@ let
linked and keg-only.
'';
};
postinstall = mkNullOrStrOption {
description = ''
A shell command to run after the formula is installed or upgraded. The command is passed
to the system shell and only executes when the formula actually changed (was freshly
installed or upgraded), not on every {command}`brew bundle` run.
'';
};
# `version_file` is intentionally not exposed: it writes the installed version to a file
# path relative to the `brew bundle` working directory, which is not meaningful during
# nix-darwin system activation.
brewfileLine = mkInternalOption { type = types.nullOr types.str; };
};
@ -517,6 +527,13 @@ let
itself.
'';
};
postinstall = mkNullOrStrOption {
description = ''
A shell command to run after the cask is installed or upgraded. The command is passed to
the system shell and only executes when the cask was actually installed or upgraded, not
on every {command}`brew bundle` run.
'';
};
brewfileLine = mkInternalOption { type = types.nullOr types.str; };
};
@ -681,6 +698,12 @@ in
link = true;
conflicts_with = [ "mysql" ];
}
# `brew install`, run a post-install command on version changes
{
name = "postgresql@16";
postinstall = "\''${HOMEBREW_PREFIX}/opt/postgresql@16/bin/postgres -D \''${HOMEBREW_PREFIX}/var/postgresql@16";
}
]
'';
description = ''
@ -712,6 +735,12 @@ in
name = "opera";
greedy = true;
}
# `brew install --cask`, run a post-install command on install or upgrade
{
name = "google-cloud-sdk";
postinstall = "\''${HOMEBREW_PREFIX}/bin/gcloud components update";
}
]
'';
description = ''