nixos/facter: add graphics hardware detection (#458177)

This commit is contained in:
Jörg Thalheim
2025-11-20 12:05:43 +00:00
committed by GitHub
11 changed files with 87 additions and 14 deletions
@@ -7,6 +7,7 @@
imports = [
./disk.nix
./firmware.nix
./graphics
./keyboard.nix
./networking
./system.nix
+1 -1
View File
@@ -22,7 +22,7 @@ in
'';
};
config = {
config = lib.mkIf (config.hardware.facter.reportPath != null) {
boot.initrd.availableKernelModules = config.hardware.facter.detected.boot.disk.kernelModules;
};
}
+1 -1
View File
@@ -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;
@@ -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" ];
};
}
@@ -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; }
)
);
}
+1 -1
View File
@@ -15,7 +15,7 @@ in
'';
};
config = {
config = lib.mkIf (config.hardware.facter.reportPath != null) {
boot.initrd.availableKernelModules = config.hardware.facter.detected.boot.keyboard.kernelModules;
};
}
@@ -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;
};
}
@@ -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;
};
}
@@ -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);
};
+5 -2
View File
@@ -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;
};
@@ -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" ])