diff options
author | Justin Bedo <cu@cua0.org> | 2020-06-23 17:28:00 +1000 |
---|---|---|
committer | Justin Bedo <cu@cua0.org> | 2020-06-23 17:28:19 +1000 |
commit | 7e5542eadad1db9271fe1d18b5682eacebadbf48 (patch) | |
tree | 283bc8a76223bf69870bbdc729fbb8263303a3ac /lib/slurm.nix | |
parent | 5b60ff475459be4da904fd773ed78f82ed107c23 (diff) |
qsub,slurm: fix string escaping bug
escapeShellArgs calls toString on the passed item, which for paths
converts it to a string containing the full path outside the nix
store. Avoid this by calling escapeShellArg on strings only.
Diffstat (limited to 'lib/slurm.nix')
-rw-r--r-- | lib/slurm.nix | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/lib/slurm.nix b/lib/slurm.nix index 30a5f5e..4ad41ab 100644 --- a/lib/slurm.nix +++ b/lib/slurm.nix @@ -1,28 +1,26 @@ -{stdenv, lib, writeScript, coreutils}: +{ stdenv, lib, writeScript, coreutils }: with lib; -{ ppn, mem, walltime, partition ? null, slurmFlags ? null, salloc ? "/usr/bin/salloc", srun ? "/usr/bin/srun" }: -drv: - let ppnReified = if drv.multicore then ppn else 1; - in lib.overrideDerivation drv ({ args, builder, name, ... }: { - builder = stdenv.shell; - args = let - script = writeScript "slurm-script" '' - #!${stdenv.shell} - ${builder} ${lib.escapeShellArgs args} - ''; +let escape = x: if builtins.typeOf x == "string" then escapeShellArg x else x; - slurm = writeScript "slurm" '' - #!${stdenv.shell} - NIX_BUILD_CORES=${toString ppnReified} +in { ppn, mem, walltime, partition ? null, slurmFlags ? null +, salloc ? "/usr/bin/salloc", srun ? "/usr/bin/srun" }: +drv: +let ppnReified = if drv.multicore then ppn else 1; +in overrideDerivation drv ({ args, builder, name, ... }: { + builder = stdenv.shell; + args = let + slurm = writeScript "slurm" '' + #!${stdenv.shell} + NIX_BUILD_CORES=${toString ppnReified} - ${salloc} -c $NIX_BUILD_CORES --mem=${toString mem}G -t ${walltime} \ - -J "${name}" \ - ${optionalString (partition != null) "-p ${partition}"} \ - ${optionalString (slurmFlags != null) slurmFlags} \ - ${srun} ${script} - ''; + ${salloc} -c $NIX_BUILD_CORES --mem=${toString mem}G -t ${walltime} \ + -J "${name}" \ + ${optionalString (partition != null) "-p ${partition}"} \ + ${optionalString (slurmFlags != null) slurmFlags} \ + ${srun} ${builder} ${concatMapStringsSep " " escape args} + ''; - in [ "-c" slurm ]; - }) + in [ "-c" slurm ]; +}) |