diff --git a/modules/homebrew.nix b/modules/homebrew.nix index 61fb5c8..aadec07 100644 --- a/modules/homebrew.nix +++ b/modules/homebrew.nix @@ -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 = '' diff --git a/tests/homebrew.nix b/tests/homebrew.nix index 7815158..beaf5ff 100644 --- a/tests/homebrew.nix +++ b/tests/homebrew.nix @@ -50,6 +50,10 @@ in link = true; conflicts_with = [ "mysql" ]; } + { + name = "postgresql@16"; + postinstall = "\${HOMEBREW_PREFIX}/opt/postgresql@16/bin/postgres -D \${HOMEBREW_PREFIX}/var/postgresql@16"; + } ]; homebrew.casks = [ @@ -62,6 +66,10 @@ in name = "opera"; greedy = true; } + { + name = "google-cloud-sdk"; + postinstall = "\${HOMEBREW_PREFIX}/bin/gcloud components update"; + } ]; homebrew.masApps = { @@ -92,11 +100,13 @@ in ${mkTest "imagemagick" ''brew "imagemagick"''} ${mkTest "denji/nginx/nginx-full" ''brew "denji/nginx/nginx-full", args: ["with-rmtp"], link: :overwrite, restart_service: :always''} ${mkTest "mysql@5.6" ''brew "mysql@5.6", conflicts_with: ["mysql"], link: true, restart_service: true''} + ${mkTest "postgresql@16" ''brew "postgresql@16", postinstall: "''${HOMEBREW_PREFIX}/opt/postgresql@16/bin/postgres -D ''${HOMEBREW_PREFIX}/var/postgresql@16"''} echo "checking cask entries in Brewfile" >&2 ${mkTest "google-chrome" ''cask "google-chrome"''} ${mkTest "firefox" ''cask "firefox", args: { appdir: "~/my-apps/Applications" }''} ${mkTest "opera" ''cask "opera", greedy: true''} + ${mkTest "google-cloud-sdk" ''cask "google-cloud-sdk", postinstall: "''${HOMEBREW_PREFIX}/bin/gcloud components update"''} echo "checking mas entries in Brewfile" >&2 ${mkTest "1Password for Safari" ''mas "1Password for Safari", id: 1569813296''}