130fe39c8e
We need exit on the first error, as otherwise we cannot track a bad execution when no exec is done (when post is not empty).
38 lines
569 B
Nix
38 lines
569 B
Nix
{
|
|
stdenv
|
|
, garlicTools
|
|
}:
|
|
|
|
{
|
|
nextStage
|
|
, env ? ""
|
|
, pre ? ""
|
|
, argv ? []
|
|
, post ? ""
|
|
, nixPrefix ? ""
|
|
}:
|
|
|
|
with builtins;
|
|
with garlicTools;
|
|
|
|
let
|
|
argvString = concatStringsSep " " (map (e: toString e) argv);
|
|
execMethod = if (post == "") then "exec " else "";
|
|
in
|
|
stdenv.mkDerivation {
|
|
name = "exec";
|
|
preferLocalBuild = true;
|
|
phases = [ "installPhase" ];
|
|
installPhase = ''
|
|
cat > $out <<'EOF'
|
|
#!/bin/sh -e
|
|
${env}
|
|
|
|
''+pre+''
|
|
${execMethod}${nixPrefix}${stageProgram nextStage} ${argvString}
|
|
''+post+''
|
|
EOF
|
|
chmod +x $out
|
|
'';
|
|
}
|