summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorSergey Mironov <grrwlf@gmail.com>2016-01-28 01:26:40 +0300
committerGraham Christensen <graham@grahamc.com>2017-08-01 20:23:08 -0400
commitf49c2fbf7a0594717a16432295983512091fba26 (patch)
treeefeacfb439ae09c2473492fbbd9e1310711b47c1 /pkgs
parentd9521c3418adc7d8883c6965c0083e8b9486543a (diff)
downloadnixpkgs-f49c2fbf7a0594717a16432295983512091fba26.tar
nixpkgs-f49c2fbf7a0594717a16432295983512091fba26.tar.gz
nixpkgs-f49c2fbf7a0594717a16432295983512091fba26.tar.bz2
nixpkgs-f49c2fbf7a0594717a16432295983512091fba26.tar.lz
nixpkgs-f49c2fbf7a0594717a16432295983512091fba26.tar.xz
nixpkgs-f49c2fbf7a0594717a16432295983512091fba26.tar.zst
nixpkgs-f49c2fbf7a0594717a16432295983512091fba26.zip
trivial-builders.nix: add writeShellScriptBin builder
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/build-support/trivial-builders.nix17
1 files changed, 17 insertions, 0 deletions
diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix
index 16bd4e8e405..14553c33e03 100644
--- a/pkgs/build-support/trivial-builders.nix
+++ b/pkgs/build-support/trivial-builders.nix
@@ -26,6 +26,7 @@ rec {
     , text
     , executable ? false # run chmod +x ?
     , destination ? ""   # relative path appended to $out eg "/bin/foo"
+    , checkPhase ? ""    # syntax checks, e.g. for scripts
     }:
     runCommand name
       { inherit text executable;
@@ -44,6 +45,8 @@ rec {
           echo -n "$text" > "$n"
         fi
 
+        ${checkPhase}
+
         (test -n "$executable" && chmod +x "$n") || true
       '';
 
@@ -54,6 +57,20 @@ rec {
   writeScript = name: text: writeTextFile {inherit name text; executable = true;};
   writeScriptBin = name: text: writeTextFile {inherit name text; executable = true; destination = "/bin/${name}";};
 
+  # Create a Shell script, check its syntax
+  writeShellScriptBin = name : text :
+    writeTextFile {
+      inherit name;
+      executable = true;
+      destination = "/bin/${name}";
+      text = ''
+        #!${stdenv.shell}
+        ${text}
+        '';
+      checkPhase = ''
+        ${stdenv.shell} -n $out
+      '';
+    };
 
   # Create a forest of symlinks to the files in `paths'.
   symlinkJoin =