diff --git a/garlic/stages/experiment.nix b/garlic/stages/experiment.nix index 0195780..95535e8 100644 --- a/garlic/stages/experiment.nix +++ b/garlic/stages/experiment.nix @@ -13,6 +13,9 @@ with garlicTools; let unitsString = builtins.concatStringsSep "\n" (map (x: "${stageProgram x}") units); + + unitsLinks = builtins.concatStringsSep "\n" + (map (x: "ln -s ../${baseNameOf x} ${baseNameOf x}") units); in stdenv.mkDerivation { name = "experiment"; @@ -30,16 +33,20 @@ stdenv.mkDerivation { exit 1 fi + cd "\$GARLIC_OUT" + export GARLIC_EXPERIMENT=$(basename $out) - echo "Running experiment \$GARLIC_EXPERIMENT" if [ -e "\$GARLIC_EXPERIMENT" ]; then - >&2 echo "Already exists \$GARLIC_EXPERIMENT, aborting" - exit 1 + >&2 echo "skipping, experiment path already exists: \$GARLIC_EXPERIMENT" + exit 0 fi mkdir -p "\$GARLIC_EXPERIMENT" cd "\$GARLIC_EXPERIMENT" + ${unitsLinks} + + echo "Running experiment \$GARLIC_EXPERIMENT" # This is an experiment formed by the following units: ${unitsString} diff --git a/garlic/stages/unit.nix b/garlic/stages/unit.nix index 87650f8..3f32f37 100644 --- a/garlic/stages/unit.nix +++ b/garlic/stages/unit.nix @@ -50,9 +50,21 @@ stdenv.mkDerivation { ${desc} + if [ -z "\$GARLIC_OUT" ]; then + >&2 echo "GARLIC_OUT not defined, aborting" + exit 1 + fi + + cd "\$GARLIC_OUT" + # Set the experiment unit in the environment export GARLIC_UNIT=$(basename $out) + if [ -e "\$GARLIC_UNIT" ]; then + >&2 echo "skipping, unit path already exists: \$GARLIC_UNIT" + exit 0 + fi + # And change the working directory mkdir \$GARLIC_UNIT cd \$GARLIC_UNIT