From 1cfb083a20ffdc5d961357af944aafb129a6e638 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 27 Oct 2018 13:14:56 +0200 Subject: pkgs: document makeScriptwriter, write & writeBash --- pkgs/default.nix | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkgs/default.nix b/pkgs/default.nix index a56042c..084702d 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -54,6 +54,14 @@ pkgs: oldpkgs: { execBin = name: cfg: pkgs.exec name (cfg // { destination = "/bin/${name}"; }); + /* Base implementation for non-compiled executables. + Takes an interpreter, for example `${pkgs.bash}/bin/bash` + + Examples: + writebash = makeScriptWriter { interpreter = "${pkgs.bash}/bin/bash"; } + makeScriptWriter { interpreter = "${pkgs.dash}/bin/dash"; } "hello" "echo hello world" + */ + makeScriptWriter = { interpreter, check ? null }: name: text: assert (with types; either absolute-pathname filename).check name; pkgs.write (baseNameOf name) { @@ -64,6 +72,22 @@ pkgs: oldpkgs: { }; }; + /* Take a name and specification and build a derivation out of it + Examples: + write "name" { "/etc/test" = { text = "hello world"; }; } + + write "name" { "" = { executable = true; text = "echo hello world"; }; } + + write "name" { "/bin/test" = { executable = true; text = "echo hello world"; }; } + + write "name" { "" = { executable = true; + check = "${pkgs.shellcheck}/bin/shellcheck"; + text = '' + #!/bin/sh + echo hello world + ''; + }; } + */ write = name: specs0: let env = filevars // { passAsFile = attrNames filevars; }; @@ -133,6 +157,13 @@ pkgs: oldpkgs: { ) ''; + /* Like writeScript but the first line is a shebang to bash + + Example: + writeBash "example" '' + echo hello world + '' + */ writeBash = name: text: assert (with types; either absolute-pathname filename).check name; pkgs.write (baseNameOf name) { -- cgit v1.2.3