From 8457628ee6f3311e0e93888634e79c3747bd62a0 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Thu, 7 Apr 2022 01:35:18 +0200 Subject: [PATCH] [General] Add option to set nix thread count Build log2(cores) derivations at once at most --- general.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/general.nix b/general.nix index c60a380..6d4e962 100644 --- a/general.nix +++ b/general.nix @@ -20,6 +20,9 @@ let settings) ); + log2 = let + mylog = x: y: if (x >= 2) then mylog (x / 2) (y + 1) else y; + in x: mylog x 0; buildUserKeyFile = "remote_builder/id_builder"; buildUserPubKey = readFile ./nix/id_builder.pub; buildUserKey = readFile ./nix/id_builder; @@ -53,6 +56,13 @@ in description = "Enable aviallon's general tuning"; type = types.bool; }; + cores = mkOption { + default = null; + example = 4; + description = "Number of physical threads of the machine"; + type = types.nullOr (types.addCheck types.int (x: x > 0)); + }; + cpuArch = mkOption { default = "x86-64"; example = "x86-64-v2"; @@ -162,9 +172,11 @@ in (optionals cfg.flakes.enable ["nix-command" "flakes"]) ]; download-attempts = 5; + cores = ifEnable (cfg.cores != null) cfg.cores; stalled-download-timeout = 20; }; + nix.maxJobs = mkIf (cfg.cores != null) (log2 cfg.cores); }; }