From a481ab4da6064ec89b46cf36f61f1dc3f68ee5e4 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Sat, 23 Apr 2022 22:02:35 +0200 Subject: [PATCH] [Nix] Move nix-specific config to dedicated file --- general.nix | 53 ++------------------------------------------ nix.nix | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 51 deletions(-) create mode 100644 nix.nix diff --git a/general.nix b/general.nix index d8d9824..959e6d8 100644 --- a/general.nix +++ b/general.nix @@ -1,28 +1,8 @@ -{ config, pkgs, lib, ... }: +{ config, pkgs, lib, myLib, ... }: with lib; let cfg = config.aviallon.general; desktopCfg = config.aviallon.desktop; - nixConfigValue = value: - if value == true then "true" - else if value == false then "false" - else if isList value then toString value - else generators.mkValueStringDefault { } value; - - isNullOrEmpty = v: (v == null) || - (isList v && (length v == 0)); - - nixConfig = settings: (generators.toKeyValue { - mkKeyValue = generators.mkKeyValueDefault { - mkValueString = nixConfigValue; - } " = "; - } (filterAttrs (n: v: !(isNullOrEmpty v)) - 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; @@ -60,7 +40,7 @@ in default = null; example = 4; description = "Number of physical threads of the machine"; - type = types.nullOr (types.addCheck types.int (x: x > 0)); + type = with types; nullOr ints.positive; }; cpuArch = mkOption { @@ -111,21 +91,6 @@ in enableSSHSupport = true; }; - nix.gc.automatic = mkDefault true; - nix.gc.dates = mkDefault "Monday,Wednesday,Friday,Sunday 03:00:00"; - nix.gc.randomizedDelaySec = "3h"; - nix.optimise.automatic = mkDefault true; - nix.optimise.dates = mkForce [ "Tuesday,Thursday,Saturday 03:00:00" ]; - nix.autoOptimiseStore = mkDefault true; - - nix.daemonIOSchedPriority = 5; - nix.daemonCPUSchedPolicy = "batch"; - nix.daemonIOSchedClass = "idle"; - - system.autoUpgrade.enable = mkDefault true; - system.autoUpgrade.allowReboot = mkIf (!desktopCfg.enable) (mkDefault true); - system.autoUpgrade.dates = "Sunday *-*-* 00:00"; - documentation.nixos.includeAllModules = true; documentation.nixos.enable = true; documentation.dev.enable = true; @@ -166,20 +131,6 @@ in users.groups.builder = {}; nix.trustedUsers = [ "builder" ]; nix.distributedBuilds = mkDefault false; - - nix.package = mkIf cfg.flakes.enable (if (builtins.compareVersions pkgs.nix.version "2.4" >= 0) then pkgs.nix else pkgs.nix_2_4); - nix.extraOptions = nixConfig { - builders-use-substitutes = true; - experimental-features = concatLists [ - (optionals cfg.flakes.enable ["nix-command" "flakes"]) - ]; - download-attempts = 5; - cores = ifEnable (cfg.cores != null) cfg.cores; - stalled-download-timeout = 20; - connect-timeout = 5; - }; - - nix.maxJobs = mkIf (cfg.cores != null) (log2 cfg.cores); }; } diff --git a/nix.nix b/nix.nix new file mode 100644 index 0000000..c7c753a --- /dev/null +++ b/nix.nix @@ -0,0 +1,64 @@ +{config, pkgs, lib, myLib, ...}: +with lib; +with myLib; +let + generalCfg = config.aviallon.general; + desktopCfg = config.aviallon.desktop; + + + nixConfigValue = value: + if value == true then "true" + else if value == false then "false" + else if isList value then toString value + else generators.mkValueStringDefault { } value; + + isNullOrEmpty = v: (v == null) || + (isList v && (length v == 0)); + + nixConfig = settings: (generators.toKeyValue { + mkKeyValue = generators.mkKeyValueDefault { + mkValueString = nixConfigValue; + } " = "; + } (filterAttrs (n: v: !(isNullOrEmpty v)) + settings) + ); +in +{ + config = { + + system.autoUpgrade.enable = mkDefault true; + system.autoUpgrade.allowReboot = mkIf (!desktopCfg.enable) (mkDefault true); + system.autoUpgrade.dates = "Sunday *-*-* 00:00"; + + + nix.gc.automatic = mkDefault true; + nix.gc.dates = mkDefault "Monday,Wednesday,Friday,Sunday 03:00:00"; + nix.gc.randomizedDelaySec = "3h"; + nix.optimise.automatic = mkDefault true; + nix.optimise.dates = mkForce [ "Tuesday,Thursday,Saturday 03:00:00" ]; + nix.autoOptimiseStore = mkDefault true; + + nix.daemonIOSchedPriority = 5; + nix.daemonCPUSchedPolicy = "batch"; + nix.daemonIOSchedClass = "idle"; + + + nix.package = mkIf generalCfg.flakes.enable ( + if (builtins.compareVersions pkgs.nix.version "2.4" >= 0) + then pkgs.nix + else pkgs.nix_2_4 + ); + nix.extraOptions = nixConfig { + builders-use-substitutes = true; + experimental-features = concatLists [ + (optionals generalCfg.flakes.enable ["nix-command" "flakes"]) + ]; + download-attempts = 5; + stalled-download-timeout = 20; + }; + + nix.buildCores = mkIf (generalCfg.cores != null) generalCfg.cores; + nix.maxJobs = mkIf (generalCfg.cores != null) (math.log2 generalCfg.cores); + + }; +}