bscpkgs/bsc/garlic/argv.nix

32 lines
514 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
}:
{
app
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)''
2020-08-18 18:28:30 +02:00
, program ? "bin/run"
2020-08-12 14:00:04 +02:00
}:
stdenv.mkDerivation {
inherit argv;
name = "${app.name}-argv";
preferLocalBuild = true;
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/bin
cat > $out/bin/run <<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-08-18 18:28:30 +02:00
exec ${app}/${program} \''${argv[@]}
2020-08-12 14:00:04 +02:00
EOF
chmod +x $out/bin/run
'';
}