Automatically set nix.nrBuildUsers to at least nix.maxJobs
This commit is contained in:
parent
5a0208d117
commit
5d7000df68
|
@ -47,7 +47,11 @@ rec {
|
||||||
readFile ../.version
|
readFile ../.version
|
||||||
+ (if pathExists suffixFile then readFile suffixFile else "pre-git");
|
+ (if pathExists suffixFile then readFile suffixFile else "pre-git");
|
||||||
|
|
||||||
# Whether we're being called by nix-shell. This is useful to
|
# Whether we're being called by nix-shell.
|
||||||
inNixShell = builtins.getEnv "IN_NIX_SHELL" == "1";
|
inNixShell = builtins.getEnv "IN_NIX_SHELL" == "1";
|
||||||
|
|
||||||
|
# Return minimum/maximum of two numbers.
|
||||||
|
min = x: y: if x < y then x else y;
|
||||||
|
max = x: y: if x > y then x else y;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,12 +67,12 @@ in
|
||||||
type = types.int;
|
type = types.int;
|
||||||
default = 1;
|
default = 1;
|
||||||
example = 64;
|
example = 64;
|
||||||
description = "
|
description = ''
|
||||||
This option defines the maximum number of jobs that Nix will try
|
This option defines the maximum number of jobs that Nix will try
|
||||||
to build in parallel. The default is 1. You should generally
|
to build in parallel. The default is 1. You should generally
|
||||||
set it to the number of CPUs in your system (e.g., 2 on an Athlon
|
set it to the number of CPUs in your system (e.g., 2 on an Athlon
|
||||||
64 X2).
|
64 X2).
|
||||||
";
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
buildCores = mkOption {
|
buildCores = mkOption {
|
||||||
|
@ -204,7 +204,6 @@ in
|
||||||
|
|
||||||
nrBuildUsers = mkOption {
|
nrBuildUsers = mkOption {
|
||||||
type = types.int;
|
type = types.int;
|
||||||
default = 10;
|
|
||||||
description = ''
|
description = ''
|
||||||
Number of <literal>nixbld</literal> user accounts created to
|
Number of <literal>nixbld</literal> user accounts created to
|
||||||
perform secure concurrent builds. If you receive an error
|
perform secure concurrent builds. If you receive an error
|
||||||
|
@ -323,12 +322,9 @@ in
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
users.extraUsers =
|
nix.nrBuildUsers = mkDefault (lib.max 10 cfg.maxJobs);
|
||||||
if cfg.nrBuildUsers >= cfg.maxJobs then
|
|
||||||
map makeNixBuildUser (range 1 cfg.nrBuildUsers)
|
users.extraUsers = map makeNixBuildUser (range 1 cfg.nrBuildUsers);
|
||||||
else
|
|
||||||
throw "Not enough build users (${cfg.nrBuildUsers}) to support ${cfg.maxJobs} build jobs. Change nrBuildUsers or maxJobs."
|
|
||||||
;
|
|
||||||
|
|
||||||
system.activationScripts.nix = stringAfter [ "etc" "users" ]
|
system.activationScripts.nix = stringAfter [ "etc" "users" ]
|
||||||
''
|
''
|
||||||
|
|
Loading…
Reference in New Issue