Unverified Commit 59654263 authored by Jörg Thalheim's avatar Jörg Thalheim Committed by GitHub
Browse files

nixos/facter: add initial commit (#450303)

parents 47f92138 3bed74c0
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
{
  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.
      '';
    };
  };
}
+1 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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 −0
Original line number Diff line number Diff line
{ 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 −0
Original line number Diff line number Diff line
{
  "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"
    }
  }
}
Loading