nixos/facter: add core library and system detection

This adds foundational functionality for nixos-facter hardware detection:

- lib.nix: Internal helper functions for querying facter reports
  - hasCpu/hasAmdCpu/hasIntelCpu: CPU vendor detection
  - collectDrivers: Extract driver_modules from hardware entries
  - toZeroPaddedHex: Format USB device IDs (for fingerprint matching)

- system.nix: Auto-detect nixpkgs.hostPlatform from facter report
  Automatically sets the correct platform (x86_64-linux, aarch64-linux, etc.)
  based on the hardware report, reducing manual configuration.

This builds on the base infrastructure added in PR #450303 and provides
the foundation for upcoming hardware detection modules (boot, networking,
graphics, etc.).

Part of the incremental upstreaming effort from:
https://github.com/nix-community/nixos-facter-modules
This commit is contained in:
Jörg Thalheim
2025-10-21 16:56:14 +02:00
parent 85a03d7c98
commit ab49e37a02
3 changed files with 78 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
{
config,
options,
lib,
...
}:
{
# Skip setting hostPlatform in test VMs where it's read-only
# Tests have virtualisation.test options and import read-only.nix
config.nixpkgs = lib.optionalAttrs (!(options ? virtualisation.test)) {
hostPlatform = lib.mkIf (
config.hardware.facter.report.system or null != null && !options.nixpkgs.pkgs.isDefined
) (lib.mkDefault config.hardware.facter.report.system);
};
}