bscpkgs/garlic/stages/experiment.nix

60 lines
1.1 KiB
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);
unitsLinks = builtins.concatStringsSep "\n"
(map (x: "ln -s ../${baseNameOf x} ${baseNameOf x}") units);
2020-10-09 01:00:55 +08:00
in
stdenv.mkDerivation {
name = "experiment";
phases = [ "installPhase" ];
preferLocalBuild = true;
dontPatchShebangs = true;
inherit units;
isExperiment = true;
2020-10-09 01:00:55 +08:00
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
cd "\$GARLIC_OUT"
2020-10-13 19:00:59 +08:00
export GARLIC_EXPERIMENT=$(basename $out)
if [ -e "\$GARLIC_EXPERIMENT" ]; then
2020-10-30 00:40:59 +08:00
>&2 echo "skipping, experiment exists: \$(pwd)/\$GARLIC_EXPERIMENT"
exit 0
2020-10-13 19:00:59 +08:00
fi
mkdir -p "\$GARLIC_EXPERIMENT"
2020-10-30 00:40:59 +08:00
2020-10-13 19:00:59 +08:00
cd "\$GARLIC_EXPERIMENT"
${unitsLinks}
echo "Running experiment \$GARLIC_EXPERIMENT"
2020-10-13 19:00:59 +08:00
2020-10-09 01:00:55 +08:00
# This is an experiment formed by the following units:
${unitsString}
EOF
chmod +x $out
'';
}