modules/homebrew: add homebrew.goPackages option

Add support for `go "pkg"` entries in the generated Brewfile. Homebrew
Bundle supports installing Go packages via `go install`; the `go`
formula is automatically installed if not already present.
This commit is contained in:
Malo Bourgon 2026-02-09 21:01:07 -08:00
parent c65c24c87c
commit cbe4a600d4
No known key found for this signature in database
2 changed files with 27 additions and 5 deletions

View file

@ -562,16 +562,18 @@ in
options.homebrew = { options.homebrew = {
enable = mkEnableOption '' enable = mkEnableOption ''
{command}`nix-darwin` to manage installing/updating/upgrading Homebrew taps, formulae, {command}`nix-darwin` to manage installing/updating/upgrading Homebrew taps, formulae,
and casks, as well as Mac App Store apps and Docker containers, using Homebrew Bundle. casks, Mac App Store apps, Go packages, and Docker containers, using Homebrew Bundle.
Note that enabling this option does not install Homebrew, see the Homebrew Note that enabling this option does not install Homebrew, see the Homebrew
[website](https://brew.sh) for installation instructions. [website](https://brew.sh) for installation instructions.
Use the [](#opt-homebrew.brews), [](#opt-homebrew.casks), Use the [](#opt-homebrew.brews), [](#opt-homebrew.casks),
[](#opt-homebrew.masApps), [](#opt-homebrew.whalebrews), [](#opt-homebrew.vscode) options [](#opt-homebrew.masApps), [](#opt-homebrew.goPackages),
to list the Homebrew formulae, casks, Mac App Store apps, Docker containers and Visual Studio [](#opt-homebrew.whalebrews), and [](#opt-homebrew.vscode) options to list the
Code Extensions you'd like to install. Use the [](#opt-homebrew.taps) option, to make additional Homebrew formulae, casks, Mac App Store apps, Go packages, Docker containers,
formula repositories available to Homebrew. This module uses those options (along with the and Visual Studio Code extensions you'd like to install. Use the
[](#opt-homebrew.taps) option, to make additional formula repositories available to
Homebrew. This module uses those options (along with the
[](#opt-homebrew.caskArgs) options) to generate a Brewfile that [](#opt-homebrew.caskArgs) options) to generate a Brewfile that
{command}`nix-darwin` passes to the {command}`brew bundle` command during {command}`nix-darwin` passes to the {command}`brew bundle` command during
system activation. system activation.
@ -775,6 +777,18 @@ in
''; '';
}; };
goPackages = mkOption {
type = with types; listOf str;
default = [ ];
example = [ "github.com/charmbracelet/crush" ];
description = ''
List of Go packages to install using {command}`go install`.
Homebrew will automatically install the {command}`go` formula if it is not already
installed.
'';
};
whalebrews = mkOption { whalebrews = mkOption {
type = with types; listOf str; type = with types; listOf str;
default = [ ]; default = [ ];
@ -852,6 +866,7 @@ in
+ mkBrewfileSectionString "Casks" cfg.casks + mkBrewfileSectionString "Casks" cfg.casks
+ mkBrewfileSectionString "Mac App Store apps" + mkBrewfileSectionString "Mac App Store apps"
(mapAttrsToList (n: id: ''mas "${n}", id: ${toString id}'') cfg.masApps) (mapAttrsToList (n: id: ''mas "${n}", id: ${toString id}'') cfg.masApps)
+ mkBrewfileSectionString "Go packages" (map (v: ''go "${v}"'') cfg.goPackages)
+ mkBrewfileSectionString "Docker containers" (map (v: ''whalebrew "${v}"'') cfg.whalebrews) + mkBrewfileSectionString "Docker containers" (map (v: ''whalebrew "${v}"'') cfg.whalebrews)
+ mkBrewfileSectionString "Visual Studio Code extensions" (map (v: ''vscode "${v}"'') cfg.vscode) + mkBrewfileSectionString "Visual Studio Code extensions" (map (v: ''vscode "${v}"'') cfg.vscode)
+ optionalString (cfg.extraConfig != "") ("# Extra config\n" + cfg.extraConfig); + optionalString (cfg.extraConfig != "") ("# Extra config\n" + cfg.extraConfig);

View file

@ -77,6 +77,10 @@ in
Xcode = 497799835; Xcode = 497799835;
}; };
homebrew.goPackages = [
"github.com/charmbracelet/crush"
];
homebrew.whalebrews = [ homebrew.whalebrews = [
"whalebrew/wget" "whalebrew/wget"
]; ];
@ -112,6 +116,9 @@ in
${mkTest "1Password for Safari" ''mas "1Password for Safari", id: 1569813296''} ${mkTest "1Password for Safari" ''mas "1Password for Safari", id: 1569813296''}
${mkTest "Xcode" ''mas "Xcode", id: 497799835''} ${mkTest "Xcode" ''mas "Xcode", id: 497799835''}
echo "checking go entries in Brewfile" >&2
${mkTest "github.com/charmbracelet/crush" ''go "github.com/charmbracelet/crush"''}
echo "checking whalebrew entries in Brewfile" >&2 echo "checking whalebrew entries in Brewfile" >&2
${mkTest "whalebrew/wget" ''whalebrew "whalebrew/wget"''} ${mkTest "whalebrew/wget" ''whalebrew "whalebrew/wget"''}