bscpkgs/garlic/stages/experiment.nix

50 lines
886 B
Nix
Raw Normal View History

2020-10-09 01:00:55 +08:00
{
stdenv
2020-10-10 02:28:00 +08:00
, garlicTools
2020-10-09 01:00:55 +08:00
}:
2020-10-09 21:55:37 +08:00
{
2020-10-09 22:13:16 +08:00
units
}:
2020-10-09 01:00:55 +08:00
with stdenv.lib;
2020-10-10 02:28:00 +08:00
with garlicTools;
2020-10-09 01:00:55 +08:00
let
unitsString = builtins.concatStringsSep "\n"
(map (x: "${stageProgram x}") units);
in
stdenv.mkDerivation {
name = "experiment";
phases = [ "installPhase" ];
preferLocalBuild = true;
dontPatchShebangs = true;
inherit units;
installPhase = ''
cat > $out << EOF
#!/bin/sh
2020-10-13 19:00:59 +08:00
if [ -z "\$GARLIC_OUT" ]; then
>&2 echo "GARLIC_OUT not defined, aborting"
exit 1
fi
export GARLIC_EXPERIMENT=$(basename $out)
2020-10-14 22:28:27 +08:00
echo "Running experiment \$GARLIC_EXPERIMENT"
2020-10-13 19:00:59 +08:00
if [ -e "\$GARLIC_EXPERIMENT" ]; then
>&2 echo "Already exists \$GARLIC_EXPERIMENT, aborting"
exit 1
fi
mkdir -p "\$GARLIC_EXPERIMENT"
cd "\$GARLIC_EXPERIMENT"
2020-10-09 01:00:55 +08:00
# This is an experiment formed by the following units:
${unitsString}
EOF
chmod +x $out
'';
}