Is it a fair expectation to transfer an /etc/nixos/configuration.nix from one system to another and watch Nix build the system? I obviously realize the whole point of the nix package management system is to achieve reproducibility, however my understanding is that such a feature is intended for reproducing packages in environments for teams of developers and QA testers, primarily achieved through Flakes and Home Manager.
In my first steps learning to use NixOS, I question how versatile a list of packages in the legacy config /etc/nixos/configuration.nix can be transposed from one system to the next. I understand there are certain variables which most would not want to be identical across multiple unique machines. For example each NixOS PC should have a unique /etc/nixos/configuration.nix with different hostnames and usernames. My question is: May I literally transplant a list of packages where environment.systemPackages = with pkgs; is declared inside /etc/nixos/configuration.nix to a different machine (with the same architecture but different motherboard, CPU manufacturer, RAM) and expect everything to run seamlessly? Of course dotfiles will need to be transposed as well to ensure all the user’s apps appear and behave the same across different PCs.
The bottom line and main question that I have for all of you: As long as I am not using Flakes with no Home Manage and am instead just using the traditional nixpkgs way of doing things, how easy is it to clone a system if I basically just want to install the same list of packages declared at environment.systemPackages = with pkgs; (and of course import the necessary dotfiles like I would for most other Linux distros after installation)?
And even if the system architecture was different it’d likely still be yes.
And even if it wasn’t, you could programmatically decide which packages are installed on which platform like this:
Trivial. Though you’d likely want to copy more than just the list of packages.
Actually, you probably want to get away from the idea that individual systems are entirely separate configs. Because NixOS turns system config into a software engineering problem, you can just simply abstract most parts of your config into pieces of common configuration used across all (or some) of your machines.
When I set up an entirely new machine that isn’t just a 1:1 replacement for an older one (which doesn’t happen often mind you), I merely declare a few machine-specific things such as hardware stuff, disk layout and broadly how I intend to use it. Pretty much everything else is handled by generic common modules that set up stuff the way I want it to be everywhere.
My desktop config is its own NixOS module used by all my desktop systems for instance and whenever I change it, it changes on all systems equally. I don’t have a per-machine desktop config that I’d need to copy over to others; they all use the same exact one.
Here is everything that I declare about the machine I currently write this on:
That’s not a whole lot and very abstract; basically: this is a desktop using some flavour, has one LUKS device and a btrfs with my standard layout inside.
All the actual nitty-gritty details and things I always want unconditionally are handled by the generic modules that work the same on all of my machines.
Actually, looking at it right now, there’s some more stuff that I should move to common config such as SSH or ADB on desktops.
Thank you for sharing your extensive repo of configs. There are a lot of commonalities as well as variations in your hosts. Learning from other advanced experienced users like yourself is instructive.