diff --git a/nixos/modules/hardware/facter/default.nix b/nixos/modules/hardware/facter/default.nix index f3bd58443dc7..30db0d10e48a 100644 --- a/nixos/modules/hardware/facter/default.nix +++ b/nixos/modules/hardware/facter/default.nix @@ -7,6 +7,7 @@ imports = [ ./disk.nix ./firmware.nix + ./graphics ./keyboard.nix ./networking ./system.nix diff --git a/nixos/modules/hardware/facter/disk.nix b/nixos/modules/hardware/facter/disk.nix index 4bb76f16366d..4158bd171bb9 100644 --- a/nixos/modules/hardware/facter/disk.nix +++ b/nixos/modules/hardware/facter/disk.nix @@ -22,7 +22,7 @@ in ''; }; - config = { + config = lib.mkIf (config.hardware.facter.reportPath != null) { boot.initrd.availableKernelModules = config.hardware.facter.detected.boot.disk.kernelModules; }; } diff --git a/nixos/modules/hardware/facter/firmware.nix b/nixos/modules/hardware/facter/firmware.nix index 10962018890c..b614cab85253 100644 --- a/nixos/modules/hardware/facter/firmware.nix +++ b/nixos/modules/hardware/facter/firmware.nix @@ -8,7 +8,7 @@ let hasIntelCpu = facterLib.hasIntelCpu report; in { - config = lib.mkIf isBaremetal { + config = lib.mkIf (config.hardware.facter.reportPath != null && isBaremetal) { # none (e.g. bare-metal) # provide firmware for devices that might not have been detected by nixos-facter hardware.enableRedistributableFirmware = lib.mkDefault true; diff --git a/nixos/modules/hardware/facter/graphics/amd.nix b/nixos/modules/hardware/facter/graphics/amd.nix new file mode 100644 index 000000000000..b2ec114677a0 --- /dev/null +++ b/nixos/modules/hardware/facter/graphics/amd.nix @@ -0,0 +1,18 @@ +{ lib, config, ... }: +let + facterLib = import ../lib.nix lib; + cfg = config.hardware.facter.detected.graphics.amd; +in +{ + options.hardware.facter.detected.graphics = { + amd.enable = lib.mkEnableOption "Enable the AMD Graphics module" // { + default = builtins.elem "amdgpu" ( + facterLib.collectDrivers (config.hardware.facter.report.hardware.graphics_card or [ ]) + ); + defaultText = "hardware dependent"; + }; + }; + config = lib.mkIf (config.hardware.facter.reportPath != null && cfg.enable) { + services.xserver.videoDrivers = [ "modesetting" ]; + }; +} diff --git a/nixos/modules/hardware/facter/graphics/default.nix b/nixos/modules/hardware/facter/graphics/default.nix new file mode 100644 index 000000000000..cd29040ce67d --- /dev/null +++ b/nixos/modules/hardware/facter/graphics/default.nix @@ -0,0 +1,42 @@ +{ lib, config, ... }: +let + facterLib = import ../lib.nix lib; + cfg = config.hardware.facter.detected.graphics; +in +{ + imports = [ + ./amd.nix + ]; + options.hardware.facter.detected = { + graphics.enable = lib.mkEnableOption "Enable the Graphics module" // { + default = builtins.length (config.hardware.facter.report.hardware.monitor or [ ]) > 0; + defaultText = "hardware dependent"; + }; + boot.graphics.kernelModules = lib.mkOption { + type = lib.types.listOf lib.types.str; + # We currently don't auto import nouveau, in case the user might want to use the proprietary nvidia driver, + # We might want to change this in future, if we have a better idea, how to handle this. + default = lib.remove "nouveau" ( + lib.uniqueStrings ( + facterLib.collectDrivers (config.hardware.facter.report.hardware.graphics_card or [ ]) + ) + ); + defaultText = "hardware dependent"; + description = '' + List of kernel modules to load at boot for the graphics card. + ''; + }; + }; + + config = lib.mkIf (config.hardware.facter.reportPath != null && cfg.enable) ( + { + boot.initrd.kernelModules = config.hardware.facter.detected.boot.graphics.kernelModules; + } + // ( + if lib.versionOlder lib.version "24.11pre" then + { hardware.opengl.enable = lib.mkDefault true; } + else + { hardware.graphics.enable = lib.mkDefault true; } + ) + ); +} diff --git a/nixos/modules/hardware/facter/keyboard.nix b/nixos/modules/hardware/facter/keyboard.nix index d19e17cd6901..62baf5bd32f1 100644 --- a/nixos/modules/hardware/facter/keyboard.nix +++ b/nixos/modules/hardware/facter/keyboard.nix @@ -15,7 +15,7 @@ in ''; }; - config = { + config = lib.mkIf (config.hardware.facter.reportPath != null) { boot.initrd.availableKernelModules = config.hardware.facter.detected.boot.keyboard.kernelModules; }; } diff --git a/nixos/modules/hardware/facter/networking/default.nix b/nixos/modules/hardware/facter/networking/default.nix index dfbc54c8396d..7f662d8785a0 100644 --- a/nixos/modules/hardware/facter/networking/default.nix +++ b/nixos/modules/hardware/facter/networking/default.nix @@ -60,10 +60,12 @@ in ]; }; }; - config = lib.mkIf config.hardware.facter.detected.dhcp.enable { - networking.useDHCP = lib.mkDefault true; + config = + lib.mkIf (config.hardware.facter.reportPath != null && config.hardware.facter.detected.dhcp.enable) + { + networking.useDHCP = lib.mkDefault true; - # Per-interface DHCP configuration - networking.interfaces = perInterfaceConfig; - }; + # Per-interface DHCP configuration + networking.interfaces = perInterfaceConfig; + }; } diff --git a/nixos/modules/hardware/facter/networking/initrd.nix b/nixos/modules/hardware/facter/networking/initrd.nix index 56be802b7cd9..8c3135354f93 100644 --- a/nixos/modules/hardware/facter/networking/initrd.nix +++ b/nixos/modules/hardware/facter/networking/initrd.nix @@ -14,7 +14,7 @@ in ''; }; - config = lib.mkIf config.boot.initrd.network.enable { + config = lib.mkIf (config.hardware.facter.reportPath != null && config.boot.initrd.network.enable) { boot.initrd.kernelModules = config.hardware.facter.detected.boot.initrd.networking.kernelModules; }; } diff --git a/nixos/modules/hardware/facter/networking/intel.nix b/nixos/modules/hardware/facter/networking/intel.nix index 4ae693a3c636..a28e8ecf580d 100644 --- a/nixos/modules/hardware/facter/networking/intel.nix +++ b/nixos/modules/hardware/facter/networking/intel.nix @@ -49,7 +49,7 @@ in }; }; - config = { + config = lib.mkIf (config.hardware.facter.reportPath != null) { networking.enableIntel2200BGFirmware = lib.mkIf cfg._2200BG.enable (lib.mkDefault true); hardware.enableRedistributableFirmware = lib.mkIf cfg._3945ABG.enable (lib.mkDefault true); }; diff --git a/nixos/modules/hardware/facter/system.nix b/nixos/modules/hardware/facter/system.nix index ef51b0e44f1d..2019bfa522d3 100644 --- a/nixos/modules/hardware/facter/system.nix +++ b/nixos/modules/hardware/facter/system.nix @@ -6,9 +6,12 @@ }: { # Skip setting hostPlatform if it's read-only - nixpkgs = + config.nixpkgs = lib.optionalAttrs - (config.hardware.facter.report.system or null != null && !options.nixpkgs.hostPlatform.readOnly) + ( + config.hardware.facter.report.system or null != null + && !(options.nixpkgs.hostPlatform.readOnly or false) + ) { hostPlatform = lib.mkDefault config.hardware.facter.report.system; }; diff --git a/nixos/modules/hardware/facter/virtualisation.nix b/nixos/modules/hardware/facter/virtualisation.nix index 15cf6bab5aee..e1a9a1647708 100644 --- a/nixos/modules/hardware/facter/virtualisation.nix +++ b/nixos/modules/hardware/facter/virtualisation.nix @@ -51,13 +51,20 @@ in }; }; - config = { + config = lib.mkIf (config.hardware.facter.reportPath != null) { # KVM support boot.kernelModules = let hasCPUFeature = - feature: lib.any ({ features, ... }: lib.elem feature features) (report.hardware.cpu or [ ]); + feature: + lib.any ( + { + features ? [ ], + ... + }: + lib.elem feature features + ) (report.hardware.cpu or [ ]); in lib.mkMerge [ (lib.mkIf (hasCPUFeature "vmx") [ "kvm-intel" ])