3 # since the tests are using a early stdenv, the stdenv will have dontPatchShebangs=1, so it has to be unset
4 # https://github.com/NixOS/nixpkgs/blob/768a982bfc9d29a6bd3beb963ed4b054451ce3d0/pkgs/stdenv/linux/default.nix#L148-L153
6 # strictDeps has to be disabled because the shell isn't in buildInputs
10 bad-shebang = stdenv.mkDerivation {
16 echo "#!/bin/bash" > $out/bin/test
17 echo "echo -n hello" >> $out/bin/test
18 chmod +x $out/bin/test
22 assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null";
26 ignores-nix-store = stdenv.mkDerivation {
27 name = "ignores-nix-store";
32 echo "#!$NIX_STORE/path/to/bash" > $out/bin/test
33 echo "echo -n hello" >> $out/bin/test
34 chmod +x $out/bin/test
38 assertion = "grep \"^#!$NIX_STORE/path/to/bash\" $out/bin/test > /dev/null";
42 updates-nix-store = stdenv.mkDerivation {
43 name = "updates-nix-store";
48 echo "#!$NIX_STORE/path/to/bash" > $out/bin/test
49 echo "echo -n hello" >> $out/bin/test
50 chmod +x $out/bin/test
51 patchShebangs --update $out/bin/test
55 assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null";
59 split-string = stdenv.mkDerivation {
60 name = "split-string";
65 echo "#!/usr/bin/env -S bash --posix" > $out/bin/test
66 echo "echo -n hello" >> $out/bin/test
67 chmod +x $out/bin/test
71 assertion = "grep -v '^#!${pkgs.coreutils}/bin/env -S ${stdenv.shell} --posix' $out/bin/test > /dev/null";
78 name = "test-patch-shebangs";
79 passthru = { inherit (tests) bad-shebang ignores-nix-store updates-nix-store split-string; };
86 echo -n "... $name: " >&2
89 (out=$testout eval "$assertion") || rc=1
91 if [ "$rc" -eq 0 ]; then
100 echo "checking whether patchShebangs works properly... ">&2
103 ${lib.concatStringsSep "\n" (lib.mapAttrsToList (_: test: ''
104 validate "${test.name}" "${test}" ${lib.escapeShellArg test.assertion} || fail=1