2020-10-09 21:55:37 +08:00
|
|
|
{
|
|
|
|
stdenv
|
|
|
|
, garlicTools
|
|
|
|
}:
|
|
|
|
|
|
|
|
{
|
|
|
|
nextStage
|
|
|
|
, env ? ""
|
2020-11-17 23:09:38 +08:00
|
|
|
, pre ? ""
|
2020-10-09 21:55:37 +08:00
|
|
|
, argv ? []
|
2020-11-17 23:09:38 +08:00
|
|
|
, post ? ""
|
2020-12-02 18:57:40 +08:00
|
|
|
, nixPrefix ? ""
|
2020-10-09 21:55:37 +08:00
|
|
|
}:
|
|
|
|
|
|
|
|
with builtins;
|
|
|
|
with garlicTools;
|
|
|
|
|
|
|
|
let
|
|
|
|
argvString = concatStringsSep " " (map (e: toString e) argv);
|
2020-11-17 23:09:38 +08:00
|
|
|
execMethod = if (post == "") then "exec " else "";
|
2020-10-09 21:55:37 +08:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "exec";
|
|
|
|
preferLocalBuild = true;
|
|
|
|
phases = [ "installPhase" ];
|
|
|
|
installPhase = ''
|
2020-11-20 20:54:45 +08:00
|
|
|
cat > $out <<'EOF'
|
2021-01-12 01:29:30 +08:00
|
|
|
#!/bin/sh -e
|
2020-10-09 21:55:37 +08:00
|
|
|
${env}
|
|
|
|
|
2020-11-17 23:09:38 +08:00
|
|
|
''+pre+''
|
2020-12-02 18:57:40 +08:00
|
|
|
${execMethod}${nixPrefix}${stageProgram nextStage} ${argvString}
|
2020-11-17 23:09:38 +08:00
|
|
|
''+post+''
|
2020-10-09 21:55:37 +08:00
|
|
|
EOF
|
|
|
|
chmod +x $out
|
|
|
|
'';
|
|
|
|
}
|