Something went wrong. Try again.
What happens if I push all of nixpkgs
Something went wrong. Try again.
Nix
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301{ lib, stdenv, pkgs,}:
# since the tests are using a early stdenv, the stdenv will have dontPatchShebangs=1, so it has to be unset# https://github.com/NixOS/nixpkgs/blob/768a982bfc9d29a6bd3beb963ed4b054451ce3d0/pkgs/stdenv/linux/default.nix#L148-L153
# strictDeps has to be disabled because the shell isn't in buildInputs
let tests = { bad-shebang = stdenv.mkDerivation { name = "bad-shebang"; strictDeps = false; dontUnpack = true; installPhase = '' mkdir -p $out/bin echo "#!/bin/bash" > $out/bin/test echo "echo -n hello" >> $out/bin/test chmod +x $out/bin/test dontPatchShebangs= ''; passthru = { assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null"; }; };
ignores-nix-store = stdenv.mkDerivation { name = "ignores-nix-store"; strictDeps = false; dontUnpack = true; installPhase = '' mkdir -p $out/bin echo "#!$NIX_STORE/path/to/bash" > $out/bin/test echo "echo -n hello" >> $out/bin/test chmod +x $out/bin/test dontPatchShebangs= ''; passthru = { assertion = "grep \"^#!$NIX_STORE/path/to/bash\" $out/bin/test > /dev/null"; }; };
updates-nix-store = stdenv.mkDerivation { name = "updates-nix-store"; strictDeps = false; dontUnpack = true; installPhase = '' mkdir -p $out/bin echo "#!$NIX_STORE/path/to/bash" > $out/bin/test echo "echo -n hello" >> $out/bin/test chmod +x $out/bin/test patchShebangs --update $out/bin/test dontPatchShebangs=1 ''; passthru = { assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null"; }; };
split-string = stdenv.mkDerivation { name = "split-string"; strictDeps = false; dontUnpack = true; installPhase = '' mkdir -p $out/bin echo "#!/usr/bin/env -S bash --posix" > $out/bin/test echo "echo -n hello" >> $out/bin/test chmod +x $out/bin/test dontPatchShebangs= ''; passthru = { assertion = "grep -v '^#!${pkgs.coreutils}/bin/env -S ${stdenv.shell} --posix' $out/bin/test > /dev/null"; }; };
without-trailing-newline = stdenv.mkDerivation { name = "without-trailing-newline"; strictDeps = false; dontUnpack = true; installPhase = '' mkdir -p $out/bin printf "#!/bin/bash" > $out/bin/test chmod +x $out/bin/test dontPatchShebangs= ''; passthru = { assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null"; }; };
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"; }; };
read-only-script = (derivation { name = "read-only-script"; system = stdenv.buildPlatform.system; builder = "${stdenv.__bootPackages.stdenv.__bootPackages.bashNonInteractive}/bin/bash"; initialPath = [ stdenv.__bootPackages.stdenv.__bootPackages.coreutils ]; strictDeps = false; args = [ "-c" '' set -euo pipefail . ${../../stdenv/generic/setup.sh} . ${../../build-support/setup-hooks/patch-shebangs.sh} mkdir -p $out/bin echo "#!/bin/bash" > $out/bin/test echo "echo -n hello" >> $out/bin/test chmod 555 $out/bin/test patchShebangs $out/bin/test '' ]; assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null"; }) // { meta = { }; };
preserves-read-only = (derivation { name = "preserves-read-only"; system = stdenv.buildPlatform.system; builder = "${stdenv.__bootPackages.stdenv.__bootPackages.bashNonInteractive}/bin/bash"; initialPath = [ stdenv.__bootPackages.stdenv.__bootPackages.coreutils ]; strictDeps = false; args = [ "-c" '' set -euo pipefail . ${../../stdenv/generic/setup.sh} . ${../../build-support/setup-hooks/patch-shebangs.sh} mkdir -p $out/bin echo "#!/bin/bash" > $out/bin/test echo "echo -n hello" >> $out/bin/test chmod 555 $out/bin/test original_perms=$(stat -c %a $out/bin/test) patchShebangs $out/bin/test new_perms=$(stat -c %a $out/bin/test) if ! [ "$original_perms" = "$new_perms" ]; then echo "Permissions changed from $original_perms to $new_perms" exit 1 fi '' ]; assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null"; }) // { meta = { }; };
# Preserve times, see: https://github.com/NixOS/nixpkgs/pull/33281 preserves-timestamp = (derivation { name = "preserves-timestamp"; system = stdenv.buildPlatform.system; builder = "${stdenv.__bootPackages.stdenv.__bootPackages.bashNonInteractive}/bin/bash"; initialPath = [ stdenv.__bootPackages.stdenv.__bootPackages.coreutils ]; strictDeps = false; args = [ "-c" '' set -euo pipefail . ${../../stdenv/generic/setup.sh} . ${../../build-support/setup-hooks/patch-shebangs.sh} mkdir -p $out/bin echo "#!/bin/bash" > $out/bin/test echo "echo -n hello" >> $out/bin/test chmod +x $out/bin/test # Set a specific timestamp (2000-01-01 00:00:00) touch -t 200001010000 $out/bin/test original_timestamp=$(stat -c %Y $out/bin/test) patchShebangs $out/bin/test new_timestamp=$(stat -c %Y $out/bin/test) if ! [ "$original_timestamp" = "$new_timestamp" ]; then echo "Timestamp changed from $original_timestamp to $new_timestamp" exit 1 fi '' ]; assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null"; }) // { meta = { }; };
preserves-binary-data = (derivation { name = "preserves-binary-data"; system = stdenv.buildPlatform.system; builder = "${stdenv.__bootPackages.stdenv.__bootPackages.bashNonInteractive}/bin/bash"; initialPath = [ stdenv.__bootPackages.stdenv.__bootPackages.coreutils ]; strictDeps = false; args = [ "-c" '' set -euo pipefail . ${../../stdenv/generic/setup.sh} . ${../../build-support/setup-hooks/patch-shebangs.sh} mkdir -p $out/bin # Create a script with binary data after the shebang echo "#!/bin/bash" > $out/bin/test echo "echo 'script start'" >> $out/bin/test # Add some binary data (null bytes and other non-printable chars) printf '\x00\x01\x02\xff\xfe' >> $out/bin/test echo >> $out/bin/test echo "echo 'script end'" >> $out/bin/test chmod +x $out/bin/test patchShebangs $out/bin/test # Verify binary data is still present by checking file size and content if ! printf '\x00\x01\x02\xff\xfe' | cmp -s - <(sed -n '3p' $out/bin/test | tr -d '\n'); then echo "Binary data corrupted during patching" exit 1 fi '' ]; assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null"; }) // { meta = { }; }; };instdenv.mkDerivation { name = "test-patch-shebangs"; passthru = { inherit (tests) bad-shebang ignores-nix-store updates-nix-store split-string without-trailing-newline dont-patch-builtins read-only-script preserves-read-only preserves-timestamp preserves-binary-data ; }; buildCommand = '' validate() { local name=$1 local testout=$2 local assertion=$3
echo -n "... $name: " >&2
local rc=0 (out=$testout eval "$assertion") || rc=1
if [ "$rc" -eq 0 ]; then echo "yes" >&2 else echo "no" >&2 fi
return "$rc" }
echo "checking whether patchShebangs works properly... ">&2
fail= ${lib.concatStringsSep "\n" ( lib.mapAttrsToList (_: test: '' validate "${test.name}" "${test}" ${lib.escapeShellArg test.assertion} || fail=1 '') tests )}
if [ "$fail" ]; then echo "failed" exit 1 else echo "succeeded" touch $out fi '';}