nixos/facter: add initial commit (#450303)
This commit is contained in:
40
nixos/modules/hardware/facter/default.nix
Normal file
40
nixos/modules/hardware/facter/default.nix
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
{
|
||||
meta.maintainers = with lib.maintainers; [ mic92 ];
|
||||
|
||||
options.hardware.facter = with lib; {
|
||||
report = mkOption {
|
||||
type = types.attrsOf types.anything;
|
||||
default =
|
||||
if config.hardware.facter.reportPath == null then
|
||||
{ }
|
||||
else
|
||||
builtins.fromJSON (builtins.readFile config.hardware.facter.reportPath);
|
||||
defaultText = "A JSON import from config.hardware.facter.reportPath (if not null), {} otherwise.";
|
||||
description = ''
|
||||
Hardware report data generated by nixos-facter.
|
||||
|
||||
See <https://nix-community.github.io/nixos-facter/> for more information.
|
||||
'';
|
||||
};
|
||||
|
||||
reportPath = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
default = null;
|
||||
description = ''
|
||||
Path to a hardware report generated by nixos-facter.
|
||||
|
||||
To generate a report, run the following as root:
|
||||
```
|
||||
nix-shell -p nixos-facter --run nixos-facter > facter.json
|
||||
```
|
||||
|
||||
See <https://nix-community.github.io/nixos-facter/> for more information.
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -66,6 +66,7 @@
|
||||
./hardware/decklink.nix
|
||||
./hardware/device-tree.nix
|
||||
./hardware/digitalbitbox.nix
|
||||
./hardware/facter
|
||||
./hardware/flipperzero.nix
|
||||
./hardware/flirc.nix
|
||||
./hardware/fw-fanctrl.nix
|
||||
|
||||
@@ -520,6 +520,7 @@ in
|
||||
etebase-server = runTest ./etebase-server.nix;
|
||||
etesync-dav = runTest ./etesync-dav.nix;
|
||||
evcc = runTest ./evcc.nix;
|
||||
facter = runTest ./facter;
|
||||
fail2ban = runTest ./fail2ban.nix;
|
||||
fakeroute = runTest ./fakeroute.nix;
|
||||
fancontrol = runTest ./fancontrol.nix;
|
||||
|
||||
29
nixos/tests/facter/default.nix
Normal file
29
nixos/tests/facter/default.nix
Normal file
@@ -0,0 +1,29 @@
|
||||
{ lib, pkgs, ... }:
|
||||
{
|
||||
name = "facter";
|
||||
meta = with lib.maintainers; {
|
||||
maintainers = [ mic92 ];
|
||||
};
|
||||
|
||||
nodes.machine = {
|
||||
hardware.facter.reportPath = ./facter.json;
|
||||
environment.systemPackages = [ pkgs.nixos-facter ];
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
from pprint import pprint
|
||||
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
with subtest("Run nixos-facter and verify it produces valid JSON"):
|
||||
import json
|
||||
# Run nixos-facter and check it produces valid output
|
||||
output = machine.succeed("nixos-facter")
|
||||
# Parse JSON to verify it's valid
|
||||
report = json.loads(output)
|
||||
pprint(report)
|
||||
assert "version" in report, "Expected version field in nixos-facter output"
|
||||
assert "system" in report, "Expected system field in nixos-facter output"
|
||||
assert report["version"] == 1, f"Expected version 1, got {report['version']}"
|
||||
'';
|
||||
}
|
||||
31
nixos/tests/facter/facter.json
Normal file
31
nixos/tests/facter/facter.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"version": 1,
|
||||
"system": "x86_64-linux",
|
||||
"virtualisation": "kvm",
|
||||
"hardware": {
|
||||
"bios": {
|
||||
"smbios_version": 520
|
||||
},
|
||||
"cpu": [
|
||||
{
|
||||
"architecture": "x86_64",
|
||||
"vendor_name": "AuthenticAMD",
|
||||
"family": 25,
|
||||
"model": 33
|
||||
}
|
||||
],
|
||||
"system": {
|
||||
"form_factor": "desktop"
|
||||
}
|
||||
},
|
||||
"smbios": {
|
||||
"bios": {
|
||||
"vendor": "SeaBIOS",
|
||||
"version": "test"
|
||||
},
|
||||
"system": {
|
||||
"manufacturer": "QEMU",
|
||||
"product": "Standard PC"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
gcc,
|
||||
pkg-config,
|
||||
makeWrapper,
|
||||
nixosTests,
|
||||
stdenv,
|
||||
systemdMinimal,
|
||||
}:
|
||||
@@ -61,6 +62,10 @@ buildGoModule rec {
|
||||
"-X github.com/numtide/nixos-facter/pkg/build.System=${stdenv.hostPlatform.system}"
|
||||
];
|
||||
|
||||
passthru.tests = {
|
||||
inherit (nixosTests) facter;
|
||||
};
|
||||
|
||||
meta = {
|
||||
description = "Declarative hardware configuration for NixOS";
|
||||
homepage = "https://github.com/numtide/nixos-facter";
|
||||
|
||||
Reference in New Issue
Block a user