bscpkgs/bsc/garlic/argv.nix

29 lines
423 B
Nix
Raw Normal View History

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