diff options
author | makefu <github@syntax-fehler.de> | 2016-02-15 17:07:48 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2016-02-15 17:07:48 +0100 |
commit | 3ceff0ec29a36119ea83f02c8943752d91b250e9 (patch) | |
tree | 7b179bc972ea01c9305ea64697e14237346885d8 /krebs/5pkgs/builders.nix | |
parent | 9a4071b66ff45e99a30e9a314eb43c6efc7e921f (diff) | |
parent | 372f2d77f301719e396a6f943657325e2f8b2cf4 (diff) |
Merge remote-tracking branch 'cd/master'
Diffstat (limited to 'krebs/5pkgs/builders.nix')
-rw-r--r-- | krebs/5pkgs/builders.nix | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/krebs/5pkgs/builders.nix b/krebs/5pkgs/builders.nix index b3cb1c943..fa51857ba 100644 --- a/krebs/5pkgs/builders.nix +++ b/krebs/5pkgs/builders.nix @@ -1,19 +1,30 @@ -{ lib, pkgs, ... }: -with lib; -{ - execve = name: { filename, argv, envp ? {}, destination ? "" }: - writeC name { inherit destination; } '' - #include <unistd.h> - int main () { - const char *filename = ${toC filename}; - char *const argv[] = ${toC (argv ++ [null])}; - char *const envp[] = ${toC ( - mapAttrsToList (k: v: "${k}=${v}") envp ++ [null] - )}; - execve(filename, argv, envp); - return -1; - } - ''; +{ config, lib, pkgs, ... }: +with config.krebs.lib; +rec { + execve = name: { filename, argv ? null, envp ? {}, destination ? "" }: let + in writeC name { inherit destination; } '' + #include <unistd.h> + + static char *const filename = ${toC filename}; + + ${if argv == null + then /* Propagate arguments */ '' + #define MAIN_ARGS int argc, char **argv + '' + else /* Provide fixed arguments */ '' + #define MAIN_ARGS void + static char *const argv[] = ${toC (argv ++ [null])}; + ''} + + static char *const envp[] = ${toC ( + mapAttrsToList (k: v: "${k}=${v}") envp ++ [null] + )}; + + int main (MAIN_ARGS) { + execve(filename, argv, envp); + return -1; + } + ''; execveBin = name: cfg: execve name (cfg // { destination = "/bin/${name}"; }); |