mirror of
https://github.com/aviallon/nixos-lib.git
synced 2026-04-06 01:38:06 +00:00
[Nix] Move nix-specific config to dedicated file
This commit is contained in:
parent
53c1c77144
commit
a481ab4da6
2 changed files with 66 additions and 51 deletions
53
general.nix
53
general.nix
|
|
@ -1,28 +1,8 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, myLib, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
let
|
let
|
||||||
cfg = config.aviallon.general;
|
cfg = config.aviallon.general;
|
||||||
desktopCfg = config.aviallon.desktop;
|
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";
|
buildUserKeyFile = "remote_builder/id_builder";
|
||||||
buildUserPubKey = readFile ./nix/id_builder.pub;
|
buildUserPubKey = readFile ./nix/id_builder.pub;
|
||||||
buildUserKey = readFile ./nix/id_builder;
|
buildUserKey = readFile ./nix/id_builder;
|
||||||
|
|
@ -60,7 +40,7 @@ in
|
||||||
default = null;
|
default = null;
|
||||||
example = 4;
|
example = 4;
|
||||||
description = "Number of physical threads of the machine";
|
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 {
|
cpuArch = mkOption {
|
||||||
|
|
@ -111,21 +91,6 @@ in
|
||||||
enableSSHSupport = true;
|
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.includeAllModules = true;
|
||||||
documentation.nixos.enable = true;
|
documentation.nixos.enable = true;
|
||||||
documentation.dev.enable = true;
|
documentation.dev.enable = true;
|
||||||
|
|
@ -166,20 +131,6 @@ in
|
||||||
users.groups.builder = {};
|
users.groups.builder = {};
|
||||||
nix.trustedUsers = [ "builder" ];
|
nix.trustedUsers = [ "builder" ];
|
||||||
nix.distributedBuilds = mkDefault false;
|
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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
64
nix.nix
Normal file
64
nix.nix
Normal file
|
|
@ -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);
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue