bscpkgs/bsc/garlic/argv.nix

32 lines
514 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
}:
{
app
2020-08-18 00:50:18 +08:00
, env ? ""
2020-08-12 20:00:04 +08:00
, argv # bash array as string, example: argv=''(-f "file with spaces" -t 10)''
2020-08-19 00:28:30 +08:00
, program ? "bin/run"
2020-08-12 20:00:04 +08: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-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-08-19 00:28:30 +08:00
exec ${app}/${program} \''${argv[@]}
2020-08-12 20:00:04 +08:00
EOF
chmod +x $out/bin/run
'';
}