Merge pull request #255463 from emilylange/stdenv/patch-shebangs-trailing-newline

patch-shebangs: fix crash with shebang without trailing newline

authored by Rick van Schijndel and committed by GitHub b728d76d 98c30519

+20 -2
+4 -1
pkgs/build-support/setup-hooks/patch-shebangs.sh
··· 72 72 while IFS= read -r -d $'\0' f; do 73 73 isScript "$f" || continue 74 74 75 - read -r oldInterpreterLine < "$f" 75 + # read exits unclean if the shebang does not end with a newline, but still assigns the variable. 76 + # So if read returns errno != 0, we check if the assigned variable is non-empty and continue. 77 + read -r oldInterpreterLine < "$f" || [ "$oldInterpreterLine" ] 78 + 76 79 read -r oldPath arg0 args <<< "${oldInterpreterLine:2}" 77 80 78 81 if [[ -z "${pathName:-}" ]]; then
+16 -1
pkgs/test/stdenv/patch-shebangs.nix
··· 72 72 }; 73 73 }; 74 74 75 + without-trailing-newline = stdenv.mkDerivation { 76 + name = "without-trailing-newline"; 77 + strictDeps = false; 78 + dontUnpack = true; 79 + installPhase = '' 80 + mkdir -p $out/bin 81 + printf "#!/bin/bash" > $out/bin/test 82 + chmod +x $out/bin/test 83 + dontPatchShebangs= 84 + ''; 85 + passthru = { 86 + assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null"; 87 + }; 88 + }; 89 + 75 90 }; 76 91 in 77 92 stdenv.mkDerivation { 78 93 name = "test-patch-shebangs"; 79 - passthru = { inherit (tests) bad-shebang ignores-nix-store updates-nix-store split-string; }; 94 + passthru = { inherit (tests) bad-shebang ignores-nix-store updates-nix-store split-string without-trailing-newline; }; 80 95 buildCommand = '' 81 96 validate() { 82 97 local name=$1