···11-source $stdenv/setup
22-33-mkdir -p $out/bin
44-cat > $out/bin/nuke-refs <<EOF
55-#! $SHELL -e
66-77-excludes=""
88-while getopts e: o; do
99- case "\$o" in
1010- e) storeId=\$(echo "\$OPTARG" | $perl/bin/perl -ne "print \"\\\$1\" if m|^\Q$NIX_STORE\E/([a-z0-9]{32})-.*|")
1111- if [ -z "\$storeId" ]; then
1212- echo "-e argument must be a Nix store path"
1313- exit 1
1414- fi
1515- excludes="\$excludes(?!\$storeId)"
1616- ;;
1717- esac
1818-done
1919-shift \$((\$OPTIND-1))
2020-2121-for i in "\$@"; do
2222- if test ! -L "\$i" -a -f "\$i"; then
2323- cat "\$i" | $perl/bin/perl -pe "s|\Q$NIX_STORE\E/\$excludes[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" > "\$i.tmp"
2424- if test -x "\$i"; then chmod +x "\$i.tmp"; fi
2525- mv "\$i.tmp" "\$i"
2626- fi
2727-done
2828-EOF
2929-chmod +x $out/bin/nuke-refs
···11+# Fixup hook for nukeReferences, not stdenv
22+33+source @signingUtils@
44+55+fixupHooks+=(signIfRequired)
+26-2
pkgs/build-support/nuke-references/default.nix
···33# path (/nix/store/eeee...). This is useful for getting rid of
44# dependencies that you know are not actually needed at runtime.
5566-{ stdenvNoCC, perl }:
66+{ lib, stdenvNoCC, perl, signingUtils, shell ? stdenvNoCC.shell }:
77+88+let
99+ stdenv = stdenvNoCC;
1010+1111+ darwinCodeSign = stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64;
1212+in
713814stdenvNoCC.mkDerivation {
915 name = "nuke-references";
1010- builder = ./builder.sh;
1616+1717+ dontUnpack = true;
1818+ dontConfigure = true;
1919+ dontBuild = true;
2020+2121+ installPhase = ''
2222+ mkdir -p $out/bin
2323+ substituteAll ${./nuke-refs.sh} $out/bin/nuke-refs
2424+ chmod a+x $out/bin/nuke-refs
2525+ '';
2626+2727+ postFixup = lib.optionalString darwinCodeSign ''
2828+ mkdir -p $out/nix-support
2929+ substituteAll ${./darwin-sign-fixup.sh} $out/nix-support/setup-hooks.sh
3030+ '';
3131+1132 # FIXME: get rid of perl dependency.
1233 inherit perl;
3434+ inherit (builtins) storeDir;
3535+ shell = lib.getBin shell + (shell.shellPath or "");
3636+ signingUtils = if darwinCodeSign then signingUtils else null;
1337}
+33
pkgs/build-support/nuke-references/nuke-refs.sh
···11+#! @shell@
22+33+fixupHooks=()
44+55+if [ -e @out@/nix-support/setup-hooks.sh ]; then
66+ source @out@/nix-support/setup-hooks.sh
77+fi
88+99+excludes=""
1010+while getopts e: o; do
1111+ case "$o" in
1212+ e) storeId=$(echo "$OPTARG" | @perl@/bin/perl -ne "print \"\$1\" if m|^\Q@storeDir@\E/([a-z0-9]{32})-.*|")
1313+ if [ -z "$storeId" ]; then
1414+ echo "-e argument must be a Nix store path"
1515+ exit 1
1616+ fi
1717+ excludes="$excludes(?!$storeId)"
1818+ ;;
1919+ esac
2020+done
2121+shift $(($OPTIND-1))
2222+2323+for i in "$@"; do
2424+ if test ! -L "$i" -a -f "$i"; then
2525+ cat "$i" | @perl@/bin/perl -pe "s|\Q@storeDir@\E/$excludes[a-z0-9]{32}-|@storeDir@/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" > "$i.tmp"
2626+ if test -x "$i"; then chmod +x "$i.tmp"; fi
2727+ mv "$i.tmp" "$i"
2828+2929+ for hook in "${fixupHooks[@]}"; do
3030+ eval "$hook" "$i"
3131+ done
3232+ fi
3333+done