WIP stage redesign

This commit is contained in:
2020-10-09 15:55:37 +02:00
parent 654e243735
commit a576be8031
14 changed files with 378 additions and 82 deletions

View File

@@ -1,30 +0,0 @@
{
stdenv
, bash
}:
{
program
, env ? ""
# bash array as string, example: argv=''(-f "file with spaces" -t 10)''
, argv ? "()"
}:
stdenv.mkDerivation {
name = "argv";
preferLocalBuild = true;
phases = [ "installPhase" ];
installPhase = ''
cat > $out <<EOF
#!${bash}/bin/bash --norc
# Requires /nix to use bash
${env}
argv=${argv}
exec ${program} \''${argv[@]}
EOF
chmod +x $out
'';
}

View File

@@ -1,12 +1,15 @@
{
stdenv
, garlicTools
}:
{
program
nextStage
, loops ? 30
}:
with garlicTools;
stdenv.mkDerivation {
name = "control";
preferLocalBuild = true;
@@ -16,7 +19,7 @@ stdenv.mkDerivation {
cat > $out <<EOF
#!/bin/sh
for n in \$(seq 1 ${toString loops}); do
${program}
${stageProgram nextStage}
done
EOF
chmod +x $out

31
garlic/stages/exec.nix Normal file
View File

@@ -0,0 +1,31 @@
{
stdenv
, garlicTools
}:
{
nextStage
, env ? ""
, argv ? []
}:
with builtins;
with garlicTools;
let
argvString = concatStringsSep " " (map (e: toString e) argv);
in
stdenv.mkDerivation {
name = "exec";
preferLocalBuild = true;
phases = [ "installPhase" ];
installPhase = ''
cat > $out <<EOF
#!/bin/sh
${env}
exec ${stageProgram nextStage} ${argvString}
EOF
chmod +x $out
'';
}

View File

@@ -1,9 +1,10 @@
{
stdenv
, nixPrefix ? ""
}:
units:
{
units:
}
with stdenv.lib;

View File

@@ -3,15 +3,17 @@
, nixtools
, busybox
, strace
, garlicTools
}:
{
program
, stage
nextStage
, nixPrefix
, clusterName
}:
with garlicTools;
stdenv.mkDerivation {
name = "isolate";
preferLocalBuild = true;
@@ -23,8 +25,9 @@ stdenv.mkDerivation {
src = ./.;
dontPatchShebangs = true;
programPath = "/bin/stage1";
inherit program nixPrefix clusterName nixtools busybox;
desc = "# $out\n" + (if builtins.hasAttr "desc" stage then stage.desc else "");
inherit nixPrefix clusterName nixtools busybox;
program = stageProgram nextStage;
desc = "# $out\n" + (if builtins.hasAttr "desc" nextStage then nextStage.desc else "");
out = "$out";
installPhase = ''

View File

@@ -2,10 +2,11 @@
stdenv
, numactl
, slurm
, garlicTools
}:
{
program
nextStage
, jobName
, chdirPrefix ? "."
, nixPrefix ? ""
@@ -26,6 +27,8 @@
}:
with stdenv.lib;
with garlicTools;
let
sbatchOpt = name: value: optionalString (value!=null)
@@ -69,7 +72,7 @@ stdenv.mkDerivation rec {
+ optionalString (extra!=null) extra
+
''
exec ${nixPrefix}${program}
exec ${nixPrefix}${stageProgram nextStage}
EOF
cat > $out/${name} <<EOF

View File

@@ -1,23 +1,30 @@
{
stdenv
, slurm
, garlicTools
}:
{
program
, nixPrefix ? ""
nextStage
, cpuBind
, nixPrefix
, srunOptions ? ""
}:
with garlicTools;
stdenv.mkDerivation rec {
name = "srun";
preferLocalBuild = true;
phases = [ "installPhase" ];
preferLocalBuild = true;
dontPatchShebangs = true;
installPhase = ''
cat > $out <<EOF
#!/bin/sh -ex
exec ${slurm}/bin/srun --mpi=pmi2 ${srunOptions} \
${nixPrefix}${program}
exec ${slurm}/bin/srun \
--mpi=pmi2 \
--cpu-bind=${cpuBind} \
${srunOptions} \
${nixPrefix}${stageProgram nextStage}
EOF
chmod +x $out
'';

View File

@@ -14,8 +14,8 @@ let
dStages = foldr (stageFn: {conf, prevStage, stages}: {
conf = conf;
prevStage = stageFn {stage=prevStage; conf=conf;};
stages = [ (stageFn {stage=prevStage; conf=conf;}) ] ++ stages;
prevStage = stageFn {nextStage=prevStage; conf=conf;};
stages = [ (stageFn {nextStage=prevStage; conf=conf;}) ] ++ stages;
})
{conf=conf; stages=[]; prevStage=null;} stages;