From c5b890c4139f854329caa6232c02fe2a592f3847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Fri, 31 Jan 2025 08:29:56 +0100 Subject: [PATCH] patch-shebangs: fix `env -S` with only one argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case `patchShebangs` encounters an `env -S` interpreter with only one argument following, it would duplicate that argument and most likely invalidate the resulting interpreter line. Reproducer: ```nix (import {}).writeTextFile { name = "patch-shebangs-env-s"; text = '' #!/bin/env -S bash ''; executable = true; checkPhase = '' patchShebangs $out ''; } ``` The resulting file would contain ``` #!/nix/store/pw…fk-coreutils-9.5/bin/env -S /nix/store/4f…g60-bash-5.2p37/bin/bash bash ``` instead of the correct ``` #!/nix/store/pw…fk-coreutils-9.5/bin/env -S /nix/store/4f…g60-bash-5.2p37/bin/bash ``` --- pkgs/build-support/setup-hooks/patch-shebangs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index f22da254a791..a7b2b110f23f 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -89,7 +89,7 @@ patchShebangs() { if [[ "$oldPath" == *"/bin/env" ]]; then if [[ $arg0 == "-S" ]]; then arg0=${args%% *} - args=${args#* } + [[ "$args" == *" "* ]] && args=${args#* } || args= newPath="$(PATH="${!pathName}" type -P "env" || true)" args="-S $(PATH="${!pathName}" type -P "$arg0" || true) $args"