From 24655f78040b420c6af6103c714f2c052a533592 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Fri, 26 Jul 2024 16:20:14 +0200 Subject: [PATCH] patch-shebangs: don't patch shebangs with bash builtins 'command -v builtin' returns 'builtin', which doesn't suit us since we're looking for program in the given PATH. This could give us shebangs like this: #!builtin which is surprising. Switch to 'type -P command' which always returns a path, even if command is both a builtin and an executable (for example 'test'), or fail is 'command' is just a builtin. --- pkgs/build-support/setup-hooks/patch-shebangs.sh | 8 ++++---- pkgs/test/stdenv/patch-shebangs.nix | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index 80a29d727c85..0553eb04b111 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -90,8 +90,8 @@ patchShebangs() { if [[ $arg0 == "-S" ]]; then arg0=${args%% *} args=${args#* } - newPath="$(PATH="${!pathName}" command -v "env" || true)" - args="-S $(PATH="${!pathName}" command -v "$arg0" || true) $args" + newPath="$(PATH="${!pathName}" type -P "env" || true)" + args="-S $(PATH="${!pathName}" type -P "$arg0" || true) $args" # Check for unsupported 'env' functionality: # - options: something starting with a '-' besides '-S' @@ -100,7 +100,7 @@ patchShebangs() { echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" >&2 exit 1 else - newPath="$(PATH="${!pathName}" command -v "$arg0" || true)" + newPath="$(PATH="${!pathName}" type -P "$arg0" || true)" fi else if [[ -z $oldPath ]]; then @@ -109,7 +109,7 @@ patchShebangs() { oldPath="/bin/sh" fi - newPath="$(PATH="${!pathName}" command -v "$(basename "$oldPath")" || true)" + newPath="$(PATH="${!pathName}" type -P "$(basename "$oldPath")" || true)" args="$arg0 $args" fi diff --git a/pkgs/test/stdenv/patch-shebangs.nix b/pkgs/test/stdenv/patch-shebangs.nix index db9ca2fcaafe..51edf128f7d5 100644 --- a/pkgs/test/stdenv/patch-shebangs.nix +++ b/pkgs/test/stdenv/patch-shebangs.nix @@ -87,6 +87,20 @@ let }; }; + dont-patch-builtins = stdenv.mkDerivation { + name = "dont-patch-builtins"; + strictDeps = false; + dontUnpack = true; + installPhase = '' + mkdir -p $out/bin + echo "#!/usr/bin/builtin" > $out/bin/test + chmod +x $out/bin/test + dontPatchShebangs= + ''; + passthru = { + assertion = "grep '^#!/usr/bin/builtin' $out/bin/test > /dev/null"; + }; + }; }; in stdenv.mkDerivation {