From 3479b795aa60c641a641bab11172b57f3c6ff9a6 Mon Sep 17 00:00:00 2001 From: Malo Bourgon Date: Mon, 9 Feb 2026 21:04:53 -0800 Subject: [PATCH] modules/homebrew: add `homebrew.cargoPackages` option Add support for `cargo "pkg"` entries in the generated Brewfile. Homebrew Bundle supports installing Rust crates via `cargo install`; the `rust` formula is automatically installed if not already present. --- modules/homebrew.nix | 23 +++++++++++++++++++---- tests/homebrew.nix | 7 +++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/modules/homebrew.nix b/modules/homebrew.nix index f41877d..a47d677 100644 --- a/modules/homebrew.nix +++ b/modules/homebrew.nix @@ -562,16 +562,18 @@ in options.homebrew = { enable = mkEnableOption '' {command}`nix-darwin` to manage installing/updating/upgrading Homebrew taps, formulae, - casks, Mac App Store apps, Go packages, and Docker containers, using Homebrew Bundle. + casks, Mac App Store apps, Go packages, Cargo crates, and Docker containers, using Homebrew + Bundle. Note that enabling this option does not install Homebrew, see the Homebrew [website](https://brew.sh) for installation instructions. Use the [](#opt-homebrew.brews), [](#opt-homebrew.casks), [](#opt-homebrew.masApps), [](#opt-homebrew.goPackages), - [](#opt-homebrew.whalebrews), and [](#opt-homebrew.vscode) options to list the - Homebrew formulae, casks, Mac App Store apps, Go packages, Docker containers, - and Visual Studio Code extensions you'd like to install. Use the + [](#opt-homebrew.cargoPackages), [](#opt-homebrew.whalebrews), and + [](#opt-homebrew.vscode) options to list the Homebrew formulae, casks, Mac App + Store apps, Go packages, Cargo crates, Docker containers, 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 @@ -789,6 +791,18 @@ in ''; }; + cargoPackages = mkOption { + type = with types; listOf str; + default = [ ]; + example = [ "ripgrep" ]; + description = '' + List of Rust packages to install using {command}`cargo install`. + + Homebrew will automatically install the {command}`rust` formula if it is not already + installed. + ''; + }; + whalebrews = mkOption { type = with types; listOf str; default = [ ]; @@ -867,6 +881,7 @@ in + mkBrewfileSectionString "Mac App Store apps" (mapAttrsToList (n: id: ''mas "${n}", id: ${toString id}'') cfg.masApps) + mkBrewfileSectionString "Go packages" (map (v: ''go "${v}"'') cfg.goPackages) + + mkBrewfileSectionString "Cargo packages" (map (v: ''cargo "${v}"'') cfg.cargoPackages) + mkBrewfileSectionString "Docker containers" (map (v: ''whalebrew "${v}"'') cfg.whalebrews) + mkBrewfileSectionString "Visual Studio Code extensions" (map (v: ''vscode "${v}"'') cfg.vscode) + optionalString (cfg.extraConfig != "") ("# Extra config\n" + cfg.extraConfig); diff --git a/tests/homebrew.nix b/tests/homebrew.nix index 1f83d59..b87a176 100644 --- a/tests/homebrew.nix +++ b/tests/homebrew.nix @@ -81,6 +81,10 @@ in "github.com/charmbracelet/crush" ]; + homebrew.cargoPackages = [ + "ripgrep" + ]; + homebrew.whalebrews = [ "whalebrew/wget" ]; @@ -119,6 +123,9 @@ in echo "checking go entries in Brewfile" >&2 ${mkTest "github.com/charmbracelet/crush" ''go "github.com/charmbracelet/crush"''} + echo "checking cargo entries in Brewfile" >&2 + ${mkTest "ripgrep" ''cargo "ripgrep"''} + echo "checking whalebrew entries in Brewfile" >&2 ${mkTest "whalebrew/wget" ''whalebrew "whalebrew/wget"''}