Skip to content

Commit

Permalink
Patch Homebrew to disable vendored Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaofengli committed Jan 22, 2024
1 parent 6049f4b commit afca106
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,22 @@ let
/bin/ln -shf "${env}" "$HOMEBREW_LIBRARY/Taps"
'';

# Patch Homebrew to disable self-update behavior
patchBrew = brew: pkgs.runCommandLocal "${brew.name or "brew"}-patched" {} ''
patchBrew = brew: let
pinnedRuby = "${pkgs.ruby}/bin/ruby";
in pkgs.runCommandLocal "${brew.name or "brew"}-patched" {} ''
cp -r "${brew}" "$out"
chmod u+w "$out" "$out/Library/Homebrew/cmd"
# Disable self-update behavior
substituteInPlace "$out/Library/Homebrew/cmd/update.sh" \
--replace 'for DIR in "''${HOMEBREW_REPOSITORY}"' "for DIR in "
# Disable vendored Ruby
ruby_sh="$out/Library/Homebrew/utils/ruby.sh"
if [[ -e "$ruby_sh" ]] && grep "setup-ruby-path" "$ruby_sh"; then
chmod u+w "$ruby_sh"
echo -e "setup-ruby-path() { export HOMEBREW_RUBY_PATH=\"${pinnedRuby}\"; }" >>"$ruby_sh"
fi
'';
in {
options = {
Expand Down

0 comments on commit afca106

Please sign in to comment.