Notes from a multi-host config: what should the Nix language be able to check?

I’ve been running a small fleet from one flake for a while now: a server, a laptop and a Pi, organised as a table of hosts where each host lists the roles it plays. I love Nix and I’m not here to complain about it. I want to start a thread where I collect the places the language forced me to invent some functionality to compensate for a quirk of Nix in its current state, and ask whether other people have hit the same things. I plan to keep adding posts here as I am studying prior art, so treat this first one as my notes in a notebook.

Three things from my own config, to ground this post in something concrete rather than start a vaporware thread where we all agree with each other then carry on as we were before.

1. Most of my lost time came from configs that evaluated cleanly and did nothing. A module I wrote and forgot to add to imports. An option set in a host file that home-manager never saw, because it evaluates separately. Nothing errored in either case. I now carry a pile of eval-time assertions whose only job is to make sure those mistakes fail loudly.

2. Nothing in a module says what it reads or what it affects. To find out what depends on a module I grep. I ended up inventing conventions (each role owns its units, firewall holes, secrets and persisted paths) and the conventions hold only because I’m careful.

3. State. I run an ephemeral root, and every role declares the paths it needs to keep, with a reason next to each. That works well, but I built it by hand on top of the module system, and anything a program writes that nobody listed is lost at the next boot.

I think what these have in common, is that the module system is a library and the language underneath can’t check much about how it’s used. So my questions:

- If option types and module dependencies could be checked before evaluation, what would that have saved you?

- Has anyone used Nickel, PureNix or anything similar for a real system config? What was it like at the boundary with nixpkgs?

- Are there discussions or RFCs I should read before I go further? I know there is work on modular services and I haven’t caught up on it yet.

I’m a Haskell and PureScript person, so I’m biased toward types, and I know that bias has costs. I’m also aware that nixpkgs is the real asset here and nobody is going to rewrite it. I’m more interested in what could sit in front of the existing store and derivation model than in replacing anything.

Next post I’ll write up what I’ve learned about how Guix structures services, since that seems to be the closest existing answer to my second point.

1 Like