Commit cb883c36 authored by Jörg Thalheim's avatar Jörg Thalheim
Browse files

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.
parent 368ed53d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@
}:
{
  imports = [
    ./disk.nix
    ./keyboard.nix
    ./system.nix
  ];

+28 −0
Original line number Diff line number Diff line
{ 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;
  };
}
+21 −0
Original line number Diff line number Diff line
{ 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;
  };
}