What is the best practice for let’s say putting my NixOS config on my laptop?
I have NixOS running in a VM right now and I really like it. I put all my stuff into a /nixos folder and then pushed it to a github repo. While doing that I originally intended to put the hardware-configuration.nix in the .gitignore BUT NixOS didn’t let me do that. The OS insisted on pushing the whole folder.
Anyhow, let’s say I’d now like to put my NixOS config on my laptop. I could:
Run the graphical installer
Connect a USB with the config folder
Rebuild the system
Would that be the best way?
The other question I have: If that is the best way then how do I handle the git repo with the two different hardware-configuration.nix files?
I have no idea what you mean by “nixos didn’t let me do that”, but I will say, don’t leave out the hardware-configuration.nix. It’s part of your config. Don’t pretend otherwise.
To answer your main question, my advice would be to just do a normal install, then replace the config and rebuild after you’re running the system. It generally has less pitfalls to do it that way than to try to install the “final” config from the get-go.
Have different configuration entry points, which list some of the same files in imports, but use different hardware-configuration.nix’s.
When trying to rebuild I got a hard error, something like “path doesn’t exist” or “file missing” or something like that. I wasn’t able to rebuild until all files in the repo were tracked.
Yeah, I thought something like that would be possible. Could you maybe give me a pointer on how to create different entry points? If you have an example or know a concise guide that would really help me a lot.
When trying to rebuild I got a hard error, something like “path doesn’t exist” or “file missing” or something like that. I wasn’t able to rebuild until all files in the repo were tracked.
Flakes, I’m guessing? The purity of flakes does require that paths are seen by git (although not necessarily actually committed, IIRC, YMMV), as it relies on git-tracked paths in determining what gets 1) copied to /nix/store and then 2) actually built.
But in that case, yes you either
A: define your baremetal install as a new host, which will have it’s own imports line for it’s own hardware-configuration.nix (you might consider reorganizing so that you have these in different hosts/<hostname>/{configuration,hardware-configuration}.nix paths.
Not a flakes user, so this might not be 100% correct, but reading the flakes schema I would expect that in the simplest case I would expect the outputs part of the flake will likely look something like this:
B: Just clone your repo into your new install, swap out the hardware-configuration.nix with the one that gets generated during nixos-generate-config and let business be as usual.