Keep the setup when the machine changes.
A conventional installation accumulates decisions. A package installed for one project. A service enabled months ago. A fix you meant to write down.
On NixOS, you can put those decisions into the system configuration. The files describe what you want installed and enabled; rebuilding turns that description into a system generation.
Upstream references (2)
Here is what that looks like.
A configuration fragment, not a complete installation.
{ pkgs, ... }:{ networking.hostName = "workstation"; programs.firefox.enable = true; programs.git.enable = true; environment.systemPackages = [ pkgs.ripgrep ]; services.printing.enable = true;}- 01Option An ordinary system option: give this machine a name.
- 02Modules Firefox and Git have NixOS modules. Where a module is the right system interface, it installs the program and handles its system-wide setup.
- 03Package list For tools like ripgrep that need no extra system configuration. For anything else, check whether a module exists first.
- 04Service System services are enabled and configured through modules too.
The machine gets a hostname. Firefox and Git are switched on through their NixOS modules, which install them and wire up the system-wide parts. Ripgrep, a command-line search tool with no module of its own, goes in the plain package list. Printing is a service, so it is enabled the same way as the programs.
Upstream references (4)
Build first. Then switch.
Nix prepares the new system before you activate it. You can build a configuration without making it the running one, then switch when you are ready. Some changes still need a reboot; services can restart during activation.
A previous generation is a way back.
Retained generations let you return to earlier system software and configuration. A previous boot entry can help when a new generation will not boot.
That is not a backup. Your home directory, application data and database migrations need their own recovery plan. Deleting old generations and collecting their store paths also removes that route back.
Upstream references (2)
Reuse what is shared. Keep what is different.
A laptop and a server can import the same user or shell configuration while keeping separate hardware and service settings. Store those files in Git and you also get a reviewable history of your own changes.
Hardware configuration, secrets and application data are separate concerns. Copying a repository is not the same as cloning a complete machine.
Upstream references (2)
The part to be honest about.
NixOS asks you to learn a different way of managing Linux. The Nix language takes practice. Software that assumes a conventional filesystem can need extra packaging or a compatibility tool. Keeping multiple generations uses disk space.
Try a VM or spare machine first. A small configuration you understand is a better start than somebody else’s elaborate dotfiles.