Files
nixpkgs/nixos/modules/hardware/facter/lib.nix
Jörg Thalheim f1498c9c56 nixos/facter: fix collectDrivers returning nested lists
The collectDrivers function was using lib.catAttrs which extracts
attribute values into a list. Since driver_modules is already a list,
this resulted in nested lists like [["i915"]] instead of ["i915"],
causing boot.initrd.kernelModules to fail with:

  error: expected a string but found a list: [ "i915" ]

Restore the original foldl' implementation from nixos-facter-modules
that properly concatenates driver_modules lists into a flat result.

Add graphics_card and monitor entries to test data to catch this
regression.

Fixes: https://github.com/NixOS/nixpkgs/pull/466808#issuecomment-2749380083
2025-12-17 16:33:41 +01:00

60 lines
1.4 KiB
Nix

# Internal library functions for hardware.facter modules
# Eventually we can think about moving this under lib/
# These are facter-specific helpers for querying nixos-facter reports
lib:
let
inherit (lib) assertMsg;
# Query if a facter report contains a CPU with the given vendor name
hasCpu =
name:
{
hardware ? { },
...
}:
let
cpus = hardware.cpu or [ ];
in
assert assertMsg (hardware != { }) "no hardware entries found in the report";
assert assertMsg (cpus != [ ]) "no cpu entries found in the report";
builtins.any (
{
vendor_name ? null,
...
}:
assert assertMsg (vendor_name != null) "detail.vendor_name not found in cpu entry";
vendor_name == name
) cpus;
# Extract all driver_modules from a list of hardware entries
collectDrivers = list: lib.foldl' (lst: value: lst ++ value.driver_modules or [ ]) [ ] list;
# Convert number to zero-padded 4-digit hex string (for USB device IDs)
toZeroPaddedHex =
n:
let
hex = lib.toHexString n;
len = builtins.stringLength hex;
in
if len == 1 then
"000${hex}"
else if len == 2 then
"00${hex}"
else if len == 3 then
"0${hex}"
else
hex;
in
{
inherit
hasCpu
collectDrivers
toZeroPaddedHex
;
hasAmdCpu = hasCpu "AuthenticAMD";
hasIntelCpu = hasCpu "GenuineIntel";
}