bscpkgs/garlic/stages/argv.nix

31 lines
431 B
Nix
Raw Normal View History

2020-08-12 20:00:04 +08:00
{
stdenv
2020-08-18 00:50:18 +08:00
, bash
2020-08-12 20:00:04 +08:00
}:
{
2020-09-02 23:07:09 +08:00
program
2020-08-18 00:50:18 +08:00
, env ? ""
2020-09-21 20:34:08 +08:00
# bash array as string, example: argv=''(-f "file with spaces" -t 10)''
, argv ? "()"
2020-08-12 20:00:04 +08:00
}:
stdenv.mkDerivation {
2020-09-02 23:07:09 +08:00
name = "argv";
2020-08-12 20:00:04 +08:00
preferLocalBuild = true;
phases = [ "installPhase" ];
installPhase = ''
2020-09-02 23:07:09 +08:00
cat > $out <<EOF
2020-08-18 00:50:18 +08:00
#!${bash}/bin/bash
# Requires /nix to use bash
${env}
2020-08-12 20:00:04 +08:00
argv=${argv}
2020-09-02 23:07:09 +08:00
exec ${program} \''${argv[@]}
2020-08-12 20:00:04 +08:00
EOF
2020-09-02 23:07:09 +08:00
chmod +x $out
2020-08-12 20:00:04 +08:00
'';
}