From cb883c36e3ee6551fa2b67c481a58d1186e83c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 21 Oct 2025 16:59:53 +0200 Subject: [PATCH] nixos/facter: add boot and storage detection This adds automatic kernel module detection for boot-critical hardware: - disk.nix: Detects and loads kernel modules for storage controllers Auto-detects modules for: disk controllers, storage controllers, and FireWire controllers (for FireWire-attached disks). Modules are automatically added to boot.initrd.availableKernelModules. - keyboard.nix: Detects USB controller drivers for keyboard support Ensures USB HID drivers are loaded in initrd for keyboard access during boot (critical for LUKS password entry, etc.). Follow up to #454237. Part of incremental upstreaming from nixos-facter-modules. --- nixos/modules/hardware/facter/default.nix | 2 ++ nixos/modules/hardware/facter/disk.nix | 28 ++++++++++++++++++++++ nixos/modules/hardware/facter/keyboard.nix | 21 ++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 nixos/modules/hardware/facter/disk.nix create mode 100644 nixos/modules/hardware/facter/keyboard.nix diff --git a/nixos/modules/hardware/facter/default.nix b/nixos/modules/hardware/facter/default.nix index 471bee49b95b..324471b16e70 100644 --- a/nixos/modules/hardware/facter/default.nix +++ b/nixos/modules/hardware/facter/default.nix @@ -5,6 +5,8 @@ }: { imports = [ + ./disk.nix + ./keyboard.nix ./system.nix ]; diff --git a/nixos/modules/hardware/facter/disk.nix b/nixos/modules/hardware/facter/disk.nix new file mode 100644 index 000000000000..4bb76f16366d --- /dev/null +++ b/nixos/modules/hardware/facter/disk.nix @@ -0,0 +1,28 @@ +{ lib, config, ... }: +let + facterLib = import ./lib.nix lib; + + inherit (config.hardware.facter) report; +in +{ + options.hardware.facter.detected.boot.disk.kernelModules = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = lib.uniqueStrings ( + facterLib.collectDrivers ( + # A disk might be attached. + (report.hardware.firewire_controller or [ ]) + # definitely important + ++ (report.hardware.disk or [ ]) + ++ (report.hardware.storage_controller or [ ]) + ) + ); + defaultText = "hardware dependent"; + description = '' + List of kernel modules that are needed to access the disk. + ''; + }; + + config = { + boot.initrd.availableKernelModules = config.hardware.facter.detected.boot.disk.kernelModules; + }; +} diff --git a/nixos/modules/hardware/facter/keyboard.nix b/nixos/modules/hardware/facter/keyboard.nix new file mode 100644 index 000000000000..d19e17cd6901 --- /dev/null +++ b/nixos/modules/hardware/facter/keyboard.nix @@ -0,0 +1,21 @@ +{ lib, config, ... }: +let + facterLib = import ./lib.nix lib; + + inherit (config.hardware.facter) report; +in +{ + options.hardware.facter.detected.boot.keyboard.kernelModules = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = lib.uniqueStrings (facterLib.collectDrivers (report.hardware.usb_controller or [ ])); + defaultText = "hardware dependent"; + example = [ "usbhid" ]; + description = '' + List of kernel modules to include in the initrd to support the keyboard. + ''; + }; + + config = { + boot.initrd.availableKernelModules = config.hardware.facter.detected.boot.keyboard.kernelModules; + }; +}