-
Notifications
You must be signed in to change notification settings - Fork 0
/
slurm-submit.patch
80 lines (74 loc) · 3.4 KB
/
slurm-submit.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc
index 2182f0bb4..f4342011f 100644
--- a/src/libstore/build/local-derivation-goal.cc
+++ b/src/libstore/build/local-derivation-goal.cc
@@ -59,6 +59,14 @@
namespace nix {
+#undef NIX_PREFIX
+#undef NIX_LIBEXEC_DIR
+static const std::string SELF{canonPath(readLink("/proc/self/exe"))};
+static const std::string NIX_PREFIX{canonPath(dirOf(dirOf(SELF)))};
+static const std::string NIX_LIBEXEC_DIR{NIX_PREFIX + "/libexec/nix"};
+#define NIX_PREFIX (NIX_PREFIX)
+#define NIX_LIBEXEC_DIR (NIX_LIBEXEC_DIR)
+
void handleDiffHook(
uid_t uid, uid_t gid,
const Path & tryA, const Path & tryB,
@@ -139,8 +147,12 @@ void LocalDerivationGoal::killChild()
::kill(-pid, SIGKILL); /* ignore the result */
buildUser->kill();
pid.wait();
- } else
+ } else {
+ /* since all our builds are salloc/srun jobs we just send
+ a term signal to avoid leaving dead jobs in the queue */
+ pid.setKillSignal(SIGTERM);
pid.kill();
+ }
assert(pid == -1);
}
@@ -377,7 +389,7 @@ void LocalDerivationGoal::startBuilder()
/* Are we doing a chroot build? */
{
- auto noChroot = parsedDrv->getBoolAttr("__noChroot");
+ auto noChroot = true;
if (settings.sandboxMode == smEnabled) {
if (noChroot)
throw Error("derivation '%s' has '__noChroot' set, "
@@ -2022,7 +2034,36 @@ void LocalDerivationGoal::runChild()
posix_spawn(NULL, builder.c_str(), NULL, &attrp, stringsToCharPtrs(args).data(), stringsToCharPtrs(envStrs).data());
#else
- execve(builder.c_str(), stringsToCharPtrs(args).data(), stringsToCharPtrs(envStrs).data());
+
+ // Configure for nix-user-chroot slurm submission building
+ args.pop_front();
+ args.push_front(builder);
+ args.push_front(canonPath(std::getenv("NIX_STOREROOT")) + "/nix");
+ args.push_front(NIX_LIBEXEC_DIR + "/nix-user-chroot");
+ args.push_front(canonPath(std::getenv("NIX_SRUN")));
+ if(env.count("PPN")) {
+ args.push_front(env["PPN"]);
+ envStrs.push_back("NIX_BUILD_CORES=" + env["PPN"]);
+ } else
+ args.push_front(std::to_string(settings.buildCores));
+ args.push_front("-c");
+ if(env.count("PARTITION"))
+ args.push_front("--partition=" + env["PARTITION"]);
+ else if(std::getenv("NIX_SLURM_PARTITION") != NULL)
+ args.push_front("--partition=" + std::string(std::getenv("NIX_SLURM_PARTITION")));
+ if(env.count("MEMORY"))
+ args.push_front("--mem=" + env["MEMORY"]);
+ else if(std::getenv("NIX_SLURM_MEMORY") != NULL)
+ args.push_front("--mem=" + std::string(std::getenv("NIX_SLURM_MEMORY")));
+ if(env.count("WALLTIME"))
+ args.push_front("--time=" + env["WALLTIME"]);
+ else if(std::getenv("NIX_SLURM_WALLTIME") != NULL)
+ args.push_front("--time=" + std::string(std::getenv("NIX_SLURM_WALLTIME")));
+ args.push_front(env["name"]);
+ args.push_front("-J");
+ args.push_front("--begin=now+10second");
+ args.push_front("salloc");
+ execve(canonPath(std::getenv("NIX_SALLOC")).c_str(), stringsToCharPtrs(args).data(), stringsToCharPtrs(envStrs).data());
#endif
throw SysError("executing '%1%'", drv->builder);