Nixos Facter

NixOS Facter aims to be an alternative to projects such as NixOS Hardware and nixos-generate-config. It solves the problem of bootstrapping NixOS configurations by deferring decisions about hardware and other aspects of the target platform to NixOS modules.

We do this by first generating a machine-readable report (JSON) which captures detailed information about the machine or virtual environment it was executed within.

This report is then passed to a series of NixOS modules which can make a variety of decisions, some simple, some more complex, enabling things like automatic configuration of network controllers or graphics cards, USB devices, and so on.

Usage

Generate a report:

sudo nix run nixpkgs#nixos-facter -- -o facter.json

Setup NixOS Configuration:

# flake.nix
{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    nixos-facter-modules.url = "github:nix-community/nixos-facter-modules";
  };
 
  outputs =
    inputs@{ nixpkgs, ... }:
    {
      nixosConfigurations.basic = nixpkgs.lib.nixosSystem {
 
        modules = [
          inputs.nixos-facter-modules.nixosModules.facter
          { config.facter.reportPath = ./facter.json; }
          # If you want to test out nixos-facter, you can add these dummy
          # values to make the configuration valid. Note that this likely won't boot if
          # it doesn't match your own partitioning
          # {
          #   users.users.root.initialPassword = "fnord23";
          #   boot.loader.grub.devices = lib.mkForce [ "/dev/sda" ];
          #   fileSystems."/".device = lib.mkDefault "/dev/sda";
          # }
          # ...
          ## You also need to define your bootloader if you are not using grub
          #{ boot.loader.systemd-boot.enable = true; }
        ];
      };
    };
}

We are currently assuming that a the system uses disko, so we have not implemented fileSystems configuration. If you don’t use disko, you have to currently specify that part of the configuration yourself or take it from nixos-generate-config.