How can I configure multiple systems with the same structure but without repeating code or definitions like the hostname?
You can make your own lib function that returns a nixosSystem exactly the way you want it. That’s what I did in my own modules system. You can, for example, make it so that the hostname is just a function argument specified once then the return value is an attribute set that maps that given hostname to the create nixosSystem value. Anything really.
How can I set up my
home-managerso that it isn’t completely separate from my system configuration such that it only configures software it needs to?
What worked for me was to make an additional ‘profile’ abstraction (naming things are hard
). But it’s basically just a collection of pre-set module options, which by itself is also a module.
Once you’ve captured all your home-manager config as a module, then it’s just a matter of embedding this in a NixOS config (so you’ve to run home-manager as a NixOS module). Another reason I do it this way, is so that I can still use home-manager standalone on external systems (e.g. a remote server).
That said, the question of whether packages should be managed by home-manager or NixOS does not always have a clean answer. It’s up to you to decide how strong this separation should be.