Best practices for managing hardware-configuration.nix in a dynamic NixOS fleet

Current Process

I manage multiple NixOS machines using a flake. When adding a new machine, I follow this manual process:

  1. Boot from NixOS installation ISO
  2. Partition, format, and mount disks
  3. Run nixos-generate-config
  4. Copy the generated hardware-config.nix to my flake repo
  5. Edit configuration.nix to enable SSH and root login
  6. Run nixos-install
  7. Perform remote build using nix run nixpkgs#nixos-rebuild -- --fast --target-host root@<machine> --build-host root@<machine> --flake . --use-remote-sudo switch

Proposed Improvement

I want to streamline this using colmena and nixos-anywhere for fleet management. While these tools solve many aspects, handling hardware configurations remains challenging.

Current Pain Points

Currently, I must:

  • Manually copy each machine’s hardware-config.nix to my repo
  • Maintain separate hardware configs for each machine
  • Clean up hardware-config.nix files when machines are destroyed
  • Repeat the process for each new machine in bulk deployments
  • Deal with configuration drift if hardware changes
  • Manage an ever-growing collection of hardware-specific files

Is there a more efficient way to handle hardware configurations in a dynamic fleet environment? Thanks to nixos-anywhere, automating the initial installation process is straightforward, but managing hardware configurations after deployment remains challenging. Ideally, I’d like a solution that reduces manual intervention and makes machine addition/removal more seamless.