From 5d7000df689f2ee654cbb45ec440764c54074430 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 16 Feb 2015 11:57:36 +0100 Subject: [PATCH] Automatically set nix.nrBuildUsers to at least nix.maxJobs --- lib/trivial.nix | 6 +++++- nixos/modules/services/misc/nix-daemon.nix | 14 +++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/trivial.nix b/lib/trivial.nix index e073da4900c..ed59eff4847 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -47,7 +47,11 @@ rec { readFile ../.version + (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"; + # 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; + } diff --git a/nixos/modules/services/misc/nix-daemon.nix b/nixos/modules/services/misc/nix-daemon.nix index 9979c6c9815..81fabd1923f 100644 --- a/nixos/modules/services/misc/nix-daemon.nix +++ b/nixos/modules/services/misc/nix-daemon.nix @@ -67,12 +67,12 @@ in type = types.int; default = 1; example = 64; - description = " + description = '' This option defines the maximum number of jobs that Nix will try 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 64 X2). - "; + ''; }; buildCores = mkOption { @@ -204,7 +204,6 @@ in nrBuildUsers = mkOption { type = types.int; - default = 10; description = '' Number of nixbld user accounts created to perform secure concurrent builds. If you receive an error @@ -323,12 +322,9 @@ in fi ''; - users.extraUsers = - if cfg.nrBuildUsers >= cfg.maxJobs then - map makeNixBuildUser (range 1 cfg.nrBuildUsers) - else - throw "Not enough build users (${cfg.nrBuildUsers}) to support ${cfg.maxJobs} build jobs. Change nrBuildUsers or maxJobs." - ; + nix.nrBuildUsers = mkDefault (lib.max 10 cfg.maxJobs); + + users.extraUsers = map makeNixBuildUser (range 1 cfg.nrBuildUsers); system.activationScripts.nix = stringAfter [ "etc" "users" ] ''