Patch Homebrew to disable vendored Ruby

This commit is contained in:
Zhaofeng Li
2024-01-22 12:26:10 -07:00
parent d517a7ad8a
commit 62c13be6f0
+11 -2
View File
@@ -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 = {