2021-01-24 01:40:18 +01:00
|
|
|
{ lib, stdenv, runCommand }:
|
2018-09-16 19:53:45 +02:00
|
|
|
|
|
|
|
let
|
2021-02-09 04:50:20 +01:00
|
|
|
tests = {
|
|
|
|
bad-shebang = stdenv.mkDerivation {
|
|
|
|
name = "bad-shebang";
|
|
|
|
dontUnpack = true;
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
echo "#!/bin/sh" > $out/bin/test
|
|
|
|
echo "echo -n hello" >> $out/bin/test
|
|
|
|
chmod +x $out/bin/test
|
|
|
|
'';
|
|
|
|
passthru = {
|
|
|
|
assertion = "grep -v '^#!/bin/sh' $out/bin/test > /dev/null";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
ignores-nix-store = stdenv.mkDerivation {
|
|
|
|
name = "ignores-nix-store";
|
|
|
|
dontUnpack = true;
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
echo "#!$NIX_STORE/path/to/sh" > $out/bin/test
|
|
|
|
echo "echo -n hello" >> $out/bin/test
|
|
|
|
chmod +x $out/bin/test
|
|
|
|
'';
|
|
|
|
passthru = {
|
|
|
|
assertion = "grep \"^#!$NIX_STORE/path/to/sh\" $out/bin/test > /dev/null";
|
|
|
|
};
|
|
|
|
};
|
2018-09-16 19:53:45 +02:00
|
|
|
};
|
|
|
|
in runCommand "patch-shebangs-test" {
|
2021-02-09 04:50:20 +01:00
|
|
|
passthru = { inherit (tests) bad-shebang ignores-nix-store; };
|
2021-01-24 01:40:18 +01:00
|
|
|
meta.platforms = lib.platforms.all;
|
2018-09-16 19:53:45 +02:00
|
|
|
} ''
|
2021-02-09 04:50:20 +01:00
|
|
|
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"
|
2018-09-16 19:53:45 +02:00
|
|
|
exit 1
|
2021-02-09 04:50:20 +01:00
|
|
|
else
|
|
|
|
echo "succeeded"
|
|
|
|
touch $out
|
2018-09-16 19:53:45 +02:00
|
|
|
fi
|
2019-06-19 17:45:34 +02:00
|
|
|
''
|