bscpkgs/garlic/pp/fetch.nix

65 lines
1.4 KiB
Nix
Raw Normal View History

2020-10-16 00:48:50 +08:00
{
stdenv
, rsync
, openssh
, nix
, curl
, garlicTools
}:
{
sshHost
, prefix
2020-10-16 21:53:28 +08:00
, experimentStage
, trebuchetStage
2020-10-16 00:48:50 +08:00
, garlicTemp
# We only fetch the config, stdout and stderr by default
, fetchAll ? false
2020-10-16 00:48:50 +08:00
}:
with garlicTools;
let
experimentName = baseNameOf (toString experimentStage);
rsyncFilter = if (fetchAll) then "" else ''
--include='*/*/garlic_config.json' \
--include='*/*/std*.log' \
--include='*/*/*/std*.log' \
--exclude='*/*/*/*' '';
2020-10-16 00:48:50 +08:00
in
stdenv.mkDerivation {
name = "fetch";
preferLocalBuild = true;
2020-10-27 02:43:02 +08:00
buildInputs = [ rsync openssh curl nix ];
2020-10-16 00:48:50 +08:00
phases = [ "installPhase" ];
2020-10-27 02:43:02 +08:00
# This doesn't work when multiple users have different directories where the
# results are stored.
#src = /. + "${prefix}${experimentName}";
2020-10-16 00:48:50 +08:00
installPhase = ''
cat > $out << EOF
#!/bin/sh -e
mkdir -p ${garlicTemp}
2020-10-27 02:43:02 +08:00
export PATH=$PATH
2020-10-16 00:48:50 +08:00
rsync -av \
2020-10-16 21:53:28 +08:00
--copy-links \
${rsyncFilter} \
2020-10-16 00:48:50 +08:00
'${sshHost}:${prefix}/${experimentName}' ${garlicTemp}
res=\$(nix-build -E '(with import ./default.nix; garlic.pp.getExpResult { \
2020-10-16 21:53:28 +08:00
experimentStage = "${experimentStage}"; \
trebuchetStage = "${trebuchetStage}"; \
garlicTemp = "${garlicTemp}"; \
})')
2020-10-16 00:48:50 +08:00
2020-10-27 02:43:02 +08:00
rm -rf ${garlicTemp}/${experimentName}
2020-10-16 00:48:50 +08:00
echo "The results for experiment ${experimentName} are at:"
echo " \$res"
2020-10-27 02:43:02 +08:00
2020-10-16 00:48:50 +08:00
EOF
chmod +x $out
'';
}