trivial-builders.nix: add writeShellScriptBin builder

This commit is contained in:
Sergey Mironov 2016-01-28 01:26:40 +03:00 committed by Graham Christensen
parent d9521c3418
commit f49c2fbf7a
No known key found for this signature in database
GPG Key ID: 06121D366FE9435C

View File

@ -26,6 +26,7 @@ rec {
, text , text
, executable ? false # run chmod +x ? , executable ? false # run chmod +x ?
, destination ? "" # relative path appended to $out eg "/bin/foo" , destination ? "" # relative path appended to $out eg "/bin/foo"
, checkPhase ? "" # syntax checks, e.g. for scripts
}: }:
runCommand name runCommand name
{ inherit text executable; { inherit text executable;
@ -44,6 +45,8 @@ rec {
echo -n "$text" > "$n" echo -n "$text" > "$n"
fi fi
${checkPhase}
(test -n "$executable" && chmod +x "$n") || true (test -n "$executable" && chmod +x "$n") || true
''; '';
@ -54,6 +57,20 @@ rec {
writeScript = name: text: writeTextFile {inherit name text; executable = true;}; writeScript = name: text: writeTextFile {inherit name text; executable = true;};
writeScriptBin = name: text: writeTextFile {inherit name text; executable = true; destination = "/bin/${name}";}; 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'. # Create a forest of symlinks to the files in `paths'.
symlinkJoin = symlinkJoin =