diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index 2a4e93f82dff..8694c602a3b9 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -149,9 +149,11 @@ rec { echo -n "$text" > "$target" fi - eval "$checkPhase" + if [ -n "$executable" ]; then + chmod +x "$target" + fi - (test -n "$executable" && chmod +x "$target") || true + eval "$checkPhase" ''; /* @@ -412,7 +414,10 @@ rec { mkdir -p "$(dirname "$file")" cat $files > "$file" - (test -n "$executable" && chmod +x "$file") || true + if [ -n "$executable" ]; then + chmod +x "$file" + fi + eval "$checkPhase" ''; diff --git a/pkgs/build-support/trivial-builders/test/write-shell-script.nix b/pkgs/build-support/trivial-builders/test/write-shell-script.nix new file mode 100644 index 000000000000..a5c9f1fae42f --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/write-shell-script.nix @@ -0,0 +1,14 @@ +{ lib, writeShellScript }: let + output = "hello"; +in (writeShellScript "test-script" '' + echo ${lib.escapeShellArg output} +'').overrideAttrs (old: { + checkPhase = old.checkPhase or "" + '' + expected=${lib.escapeShellArg output} + got=$("$target") + if [[ "$got" != "$expected" ]]; then + echo "wrong output: expected $expected, got $got" + exit 1 + fi + ''; +}) diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 5d154d1630b6..bc810790a3dd 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -70,6 +70,7 @@ with pkgs; trivial-builders = recurseIntoAttrs { writeStringReferencesToFile = callPackage ../build-support/trivial-builders/test/writeStringReferencesToFile.nix {}; writeTextFile = callPackage ../build-support/trivial-builders/test/write-text-file.nix {}; + writeShellScript = callPackage ../build-support/trivial-builders/test/write-shell-script.nix {}; references = callPackage ../build-support/trivial-builders/test/references.nix {}; overriding = callPackage ../build-support/trivial-builders/test-overriding.nix {}; concat = callPackage ../build-support/trivial-builders/test/concat-test.nix {};