From 445f7989e096fb90902eed4256b04d8b57c8b358 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Wed, 3 Apr 2024 16:01:49 -0600 Subject: [PATCH] Patch Homebrew to embed version number homebrew-bundle now depends on $HOMEBREW_VERSION, which is set by `brew.sh` using the output of `git describe`. We don't have a git repo, so let's embed the version directly. Fixes #19. --- flake.nix | 8 +++++++- modules/default.nix | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 64813e8..70b15dc 100644 --- a/flake.nix +++ b/flake.nix @@ -14,6 +14,9 @@ outputs = { self, nixpkgs, nix-darwin, flake-utils, brew-src, ... } @ inputs: let # System types to support. supportedSystems = [ "x86_64-darwin" "aarch64-darwin" ]; + + flakeLock = builtins.fromJSON (builtins.readFile ./flake.lock); + brewVersion = flakeLock.nodes.brew-src.original.ref; in flake-utils.lib.eachSystem supportedSystems (system: let pkgs = nixpkgs.legacyPackages.${system}; in { @@ -32,7 +35,10 @@ imports = [ ./modules ]; - nix-homebrew.package = lib.mkOptionDefault brew-src.outPath; + nix-homebrew.package = lib.mkOptionDefault (brew-src // { + name = "brew-${brewVersion}"; + version = brewVersion; + }); }; }; darwinConfigurations = { diff --git a/modules/default.nix b/modules/default.nix index 3f5fd62..561c034 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -287,7 +287,7 @@ let patchBrew = brew: let pinnedRuby = "${pkgs.ruby}/bin/ruby"; - in pkgs.runCommandLocal "${brew.name or "brew"}-patched" {} '' + in pkgs.runCommandLocal "${brew.name or "brew"}-patched" {} ('' cp -r "${brew}" "$out" chmod u+w "$out" "$out/Library/Homebrew/cmd" @@ -301,7 +301,12 @@ let chmod u+w "$ruby_sh" echo -e "setup-ruby-path() { export HOMEBREW_RUBY_PATH=\"${pinnedRuby}\"; }" >>"$ruby_sh" fi - ''; + '' + lib.optionalString (brew ? version) '' + # Embed version number instead of checking with git + brew_sh="$out/Library/Homebrew/brew.sh" + chmod u+w "$out/Library/Homebrew" "$brew_sh" + sed -i -e 's/^HOMEBREW_VERSION=.*/HOMEBREW_VERSION="${brew.version}"/g' "$brew_sh" + ''); in { options = { nix-homebrew = {