From aa83cf62af78ab299be3a36474d1532908fbd563 Mon Sep 17 00:00:00 2001 From: cnst Date: Wed, 2 Jul 2025 20:16:20 +0200 Subject: [PATCH] refactor kernel module --- hosts/cnixlab/modules.nix | 5 ++- hosts/cnixpad/modules.nix | 4 +-- hosts/cnixtop/modules.nix | 4 +-- hosts/toothpc/modules.nix | 4 +-- modules/nixos/boot/kernel/default.nix | 49 +++++++++++++++++---------- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/hosts/cnixlab/modules.nix b/hosts/cnixlab/modules.nix index daa5e7ca..85053e7e 100644 --- a/hosts/cnixlab/modules.nix +++ b/hosts/cnixlab/modules.nix @@ -2,9 +2,8 @@ nixos = { boot = { kernel = { - extraBlacklistedModules = []; - extraKernelParams = []; - variant = "stable"; + variant = "latest"; + hardware = ["intel"]; }; loader = { default = { diff --git a/hosts/cnixpad/modules.nix b/hosts/cnixpad/modules.nix index c869a906..9723adf0 100644 --- a/hosts/cnixpad/modules.nix +++ b/hosts/cnixpad/modules.nix @@ -2,10 +2,8 @@ nixos = { boot = { kernel = { - extraBlacklistedModules = []; - extraKernelParams = []; - hardware = "amd"; variant = "latest"; + hardware = ["amd"]; }; loader = { default = { diff --git a/hosts/cnixtop/modules.nix b/hosts/cnixtop/modules.nix index 95ba3e85..a46f4cd4 100644 --- a/hosts/cnixtop/modules.nix +++ b/hosts/cnixtop/modules.nix @@ -2,10 +2,8 @@ nixos = { boot = { kernel = { - extraBlacklistedModules = []; - extraKernelParams = []; - hardware = "amd"; variant = "latest"; + hardware = ["amd"]; }; loader = { default = { diff --git a/hosts/toothpc/modules.nix b/hosts/toothpc/modules.nix index 4256ea7e..79ba3709 100644 --- a/hosts/toothpc/modules.nix +++ b/hosts/toothpc/modules.nix @@ -2,10 +2,8 @@ nixos = { boot = { kernel = { - extraBlacklistedModules = []; - extraKernelParams = []; - hardware = "nvidia"; variant = "latest"; + hardware = ["nvidia"]; }; loader = { default = { diff --git a/modules/nixos/boot/kernel/default.nix b/modules/nixos/boot/kernel/default.nix index dc8ae028..061c0223 100644 --- a/modules/nixos/boot/kernel/default.nix +++ b/modules/nixos/boot/kernel/default.nix @@ -6,6 +6,8 @@ }: let inherit (lib) mkOption types; cfg = config.nixos.boot.kernel; + + hasHardware = hw: builtins.elem hw cfg.hardware; in { options = { nixos.boot.kernel = { @@ -16,21 +18,21 @@ in { }; hardware = mkOption { - type = types.enum ["amd" "nvidia"]; - default = ""; - description = "Hardware type (GPU) configuration."; + type = types.listOf (types.enum ["amd" "intel" "nvidia"]); + default = []; + description = "List of hardware types (e.g. GPU and CPU vendors) to configure kernel settings for."; }; extraKernelParams = mkOption { - type = types.listOf lib.types.str; + type = types.listOf types.str; default = []; description = "Additional kernel parameters."; }; extraBlacklistedModules = mkOption { - type = types.listOf lib.types.str; + type = types.listOf types.str; default = []; - description = "Additional kernel nixos.to blacklist."; + description = "Additional kernel modules to blacklist."; }; }; }; @@ -40,7 +42,7 @@ in { consoleLogLevel = 3; kernelPackages = let - variant = cfg.variant or "latest"; # Ensure a default value + variant = cfg.variant or "latest"; in if variant == "stable" then pkgs.linuxPackages @@ -51,28 +53,41 @@ in { else throw "Unknown kernel variant: ${variant}"; kernelParams = - [ - "quiet" - "splash" - ] + ["quiet" "splash"] ++ ( - if cfg.hardware == "amd" + if hasHardware "amd" then ["amd_pstate=active"] else [] ) + ++ ( + if hasHardware "intel" + then [] + else [] + ) + ++ ( + if hasHardware "nvidia" + then [] + else [] + ) ++ cfg.extraKernelParams; blacklistedKernelModules = ( - if cfg.hardware == "nvidia" + if hasHardware "amd" + then [] + else [] + ) + ++ ( + if hasHardware "intel" + then [] + else [] + ) + ++ ( + if hasHardware "nvidia" then ["nouveau"] else [] ) ++ cfg.extraBlacklistedModules; }; - - # chaotic = mkIf (cfg.variant == "cachyos") { - # environment.systemPackages = [pkgs.scx.lavd]; - # }; }; }