Managing complex Nix (and NixOS) configurations

I’m creating more complex configurations lately - with multiple files for each machine, and for multiple machines.

Are there tools or techniques to help clarify which imports are used for a given configuration (helping with completeness) and to compare configurations for different machines, to help where machines may differ very little in their config Perhaps even only machine name and network id).

All suggestions welcomed!

I have a top-level tree that looks like

modules/
pkgs/
hosts/
assets/

and I auto-import everything in modules, leaving host-specific config in hosts.

Nixos modules within modules are written with both options and config allowing finer per-host control when they are consumed by a config. This is the same style used by NixOS modules in nixpkgs.

pkgs contains package expressions, one in each subdir, and are consumed via lib.packagesFromDirectoryRecursive.

assets contains non-nix files that aren’t used in any package either.

4 Likes