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";
75 without-trailing-newline = stdenv.mkDerivation {
76 name = "without-trailing-newline";
81 printf "#!/bin/bash" > $out/bin/test
82 chmod +x $out/bin/test
86 assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null";
90 dont-patch-builtins = stdenv.mkDerivation {
91 name = "dont-patch-builtins";
96 echo "#!/usr/bin/builtin" > $out/bin/test
97 chmod +x $out/bin/test
101 assertion = "grep '^#!/usr/bin/builtin' $out/bin/test > /dev/null";
106 stdenv.mkDerivation {
107 name = "test-patch-shebangs";
108 passthru = { inherit (tests) bad-shebang ignores-nix-store updates-nix-store split-string without-trailing-newline; };
115 echo -n "... $name: " >&2
118 (out=$testout eval "$assertion") || rc=1
120 if [ "$rc" -eq 0 ]; then
129 echo "checking whether patchShebangs works properly... ">&2
132 ${lib.concatStringsSep "\n" (lib.mapAttrsToList (_: test: ''
133 validate "${test.name}" "${test}" ${lib.escapeShellArg test.assertion} || fail=1