A small tool designed to replace nixos-generate-config
Go to file
2023-08-13 19:31:25 +02:00
README.md README: more notes 2023-08-13 19:31:25 +02:00

nixos-generate-facts - a data-driven alternative to nixos-generate-config

nixos-generate-config has two problems:

  1. It only ships on machines that already have Nix available.
  2. It outputs Nix code instead of data.

The first point is mostly relevant to cases where you want to bootstrap a new server with a remote tool like nixos-anywhere. It should be possible to gather the machine facts without first installing Nix. Otherwise there is a bootstrap problem.

The second point is for everybody. If instead of generating Nix code we would be generating a JSON-like data structure of facts about the machine. This can be recorded and loaded by Nix. Or added to the nixos-hardware repo. It can be used for user diagnostics. It inverts the control where the NixOS module system can now make decisions on which kernel modules to load over time.

Status: vaporware

The project is currently just a README.

The next step is going to generate the minimal binary and adapter so that I can replace my machine's hardware-configuration.nix.

Once proven, I'm hoping to integrate that project upstream.

How the project works

The project has two parts:

  1. The binary that scans the system and outputs JSON or TOML.
  2. A NixOS module that can load that data and make decisions.

That's it.

Some more considerations

The generated data should be generic enough to be embeddable in public Git repos. We can show things like hardware models, what type of graphics card is running, ... Avoid serial numbers and MAC addresses.

Another way to look at it is that the generated data should be the same if two people have the same model of hardware.

Downsides of this approach

The main downside is that it adds a layer of indirection. New hardware detection requires updating both the tool and the Nix schema.

  • gohai, ohai, facter, ...: I would love to re-use them, but they are not providing the right type of information.