modules.hardware.cpu: cleanup

This commit is contained in:
2025-06-12 21:05:17 +08:00
parent e4e85996f5
commit f480369f68
13 changed files with 29 additions and 38 deletions

View File

@@ -21,7 +21,7 @@ inputs:
nixpkgs.march = "silvermont";
network = {};
};
hardware = { cpus = [ "intel" ]; gpu.type = "intel"; };
hardware = { cpu = "intel"; gpu.type = "intel"; };
services =
{
sshd = {};

View File

@@ -20,7 +20,7 @@ inputs:
};
nixpkgs.march = "tigerlake";
};
hardware = { cpus = [ "intel" ]; gpu.type = "intel"; };
hardware = { cpu = "intel"; gpu.type = "intel"; };
services =
{
xray.client = {};

View File

@@ -52,12 +52,7 @@ inputs:
nixpkgs = { march = "znver4"; cuda.capabilities = [ "8.9" ]; };
sysctl.laptop-mode = 5;
};
hardware =
{
cpus = [ "amd" ];
gpu = { type = "nvidia"; nvidia.dynamicBoost = true; };
legion = {};
};
hardware = { cpu = "amd"; gpu = { type = "nvidia"; nvidia.dynamicBoost = true; }; legion = {}; };
services =
{
samba =

View File

@@ -18,7 +18,7 @@ inputs:
swap = [ "/nix/swap/swap" ];
};
};
hardware.cpus = [ "intel" ];
hardware.cpu = "intel";
services =
{
sshd.passwordAuthentication = true;

View File

@@ -5,7 +5,7 @@ inputs:
nixos =
{
model.cluster.nodeType = "master";
hardware.cpus = [ "intel" ];
hardware.cpu = "intel";
system =
{
nixpkgs.march = "skylake";

View File

@@ -4,7 +4,7 @@ inputs:
{
nixos =
{
hardware.cpus = [ "amd" ];
hardware.cpu = "amd";
system =
{
nixpkgs.march = "znver3";

View File

@@ -30,7 +30,7 @@ inputs:
};
};
};
hardware.cpus = [ "intel" ];
hardware.cpu = "intel";
services =
{
beesd."/" = { hashTableSizeMB = 128; threads = 4;};

View File

@@ -17,7 +17,7 @@ inputs:
nixpkgs.march = "znver4";
network = {};
};
hardware.cpus = [ "amd" ];
hardware.cpu = "amd";
services.sshd = {};
};
};

View File

@@ -17,7 +17,7 @@ inputs:
nixpkgs.march = "znver4";
network = { dhcp = [ "nixvirt" ]; bridge.nixvirt.interfaces = [ "enp1s0" ]; };
};
hardware.cpus = [ "amd" ];
hardware.cpu = "amd";
services =
{
sshd = {};

View File

@@ -17,7 +17,7 @@ inputs:
nixpkgs.march = "haswell";
network = {};
};
hardware.cpus = [ "intel" ];
hardware.cpu = "intel";
services =
{
sshd = {};

16
modules/hardware/cpu.nix Normal file
View File

@@ -0,0 +1,16 @@
inputs:
{
options.nixos.hardware.cpu = let inherit (inputs.lib) mkOption types; in mkOption
{ type = types.nullOr (types.enum [ "intel" "amd" ]); default = null; };
config = let inherit (inputs.config.nixos.hardware) cpu; in inputs.lib.mkIf (cpu != null) (inputs.lib.mkMerge
[
(inputs.lib.mkIf (cpu == "intel")
{
hardware.cpu.intel.updateMicrocode = true;
boot.initrd.availableKernelModules =
[ "intel_cstate" "aesni_intel" "intel_cstate" "intel_uncore" "intel_uncore_frequency" "intel_powerclamp" ];
})
(inputs.lib.mkIf (cpu == "amd")
{ hardware.cpu.amd.updateMicrocode = true; environment.systemPackages = [ inputs.pkgs.zenmonitor ]; })
]);
}

View File

@@ -1,16 +0,0 @@
inputs:
{
options.nixos.hardware.cpus = let inherit (inputs.lib) mkOption types; in mkOption
{ type = types.listOf (types.enum [ "intel" "amd" ]); default = []; };
config = let inherit (inputs.config.nixos.hardware) cpus; in inputs.lib.mkIf (cpus != []) (inputs.lib.mkMerge
[
(inputs.lib.mkIf (builtins.elem "intel" cpus)
{
hardware.cpu.intel.updateMicrocode = true;
boot.initrd.availableKernelModules =
[ "intel_cstate" "aesni_intel" "intel_cstate" "intel_uncore" "intel_uncore_frequency" "intel_powerclamp" ];
})
(inputs.lib.mkIf (builtins.elem "amd" cpus)
{ hardware.cpu.amd.updateMicrocode = true; environment.systemPackages = [ inputs.pkgs.zenmonitor ]; })
]);
}

View File

@@ -12,14 +12,10 @@ inputs:
config = let inherit (inputs.config.nixos.services) kvm; in inputs.lib.mkIf (kvm != null)
{
nix.settings.system-features = [ "kvm" ];
boot =
boot = let inherit (inputs.config.nixos.hardware) cpu; in
{
kernelModules =
let modules = { intel = [ "kvm-intel" ]; amd = []; };
in builtins.concatLists (builtins.map (cpu: modules.${cpu}) inputs.config.nixos.hardware.cpus);
extraModprobeConfig =
let configs = { intel = "options kvm_intel nested=1"; amd = ""; };
in builtins.concatStringsSep "\n" (builtins.map (cpu: configs.${cpu}) inputs.config.nixos.hardware.cpus);
kernelModules = { intel = [ "kvm-intel" ]; amd = []; }.${cpu};
extraModprobeConfig = { intel = "options kvm_intel nested=1"; amd = ""; }.${cpu};
};
virtualisation =
{