From 7e5542eadad1db9271fe1d18b5682eacebadbf48 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Tue, 23 Jun 2020 17:28:00 +1000 Subject: 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. --- lib/slurm.nix | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'lib/slurm.nix') 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 ]; +}) -- cgit v1.2.3