Skip to content

Commit

Permalink
Patch Homebrew to embed version number
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zhaofengli committed Apr 3, 2024
1 parent 0b38f9d commit 445f798
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 = {
Expand Down
9 changes: 7 additions & 2 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = {
Expand Down

0 comments on commit 445f798

Please sign in to comment.