I have a single repo with a configuration that has stuff for multiple different machines and different use cases in it. So far I’ve always copied the /etc/nixos/hardware-configuration.nix into my repo and then built my config. This gets annoying when just trying out things on new machines.
I’ve tried adding /etc/nixos/hardware-configuration.nix to the modules but that doesn’t work without --impure. Adding it as a path input doesn’t work because of the hash in the flake.lock.
I’d rather not use --impure to not miss any other potential problems. Is there an easy way to always use the hardware configuration in /etc/nixos?
See this commit to see the flake.nix I’m working on.
Flakes are specifically designed not to allow this. You’re trying to make evaluation dependent on something not in the flake or its locked inputs. Much of the point of flakes is to guarantee that results of a given flake are deterministic, no matter where or when they are evaluated.
Do I need to import the hardware config every time or do I need to do that just once (when I install nix I always rebuild at least once to install git anyways, so I’d do that once anyways)?
Otherwise, do you think it’s a better idea to have the hardware configs in the repo or to use impure? It’s getting a bit tedious to add the hardware config every time.
The hardware config is part of your config, just as much as configuration.nix. Don’t try to separate it. It should go where your config goes. The only thing that makes it different is how it’s initially generated during an install. I’ve long since moved the settings in it into other files in my own config…
… you only have to generate the config once for each configuration, and it practically never changes. There’s no reason to copy it around after the initial installation.
Personally, I put it in a directory with host-specific config, but if you only have one host placing it anywhere in your flake’s repository is perfectly fine.
Not having one at all is ok, too, if you’re sure you don’t need the hardware auto-detection and can do that manually (or are ok with untangling your config if you re-run the script later).
This tbh, the comments about not touching anything on it are somewhat misleading. You will need not need to change anything, though you can freely move the location or rename the file. New hardware config files are not random events and only triggered when the user manually runs nixos-generate-config or during install.