Motivation#
Sharing NixOS configuration makes it easier to add software or change settings on several computers. Updates still leave a few things to work out: whether synchronized files need building, whether a switched system needs rebooting, and whether to continue on other computers when one has a problem.
I therefore organized the update procedure. I update and check system inputs in one place, synchronize the same revision to the computers, then build and apply it on each. Containers use their own deployment procedure. This makes it easier to see which step needs attention when something goes wrong.
Here I will describe the update method I use, along with rebooting, recovery and submodule synchronization. The examples assume a working flake and Git repository. laptop is an example name; replace the revisions, paths and host names with your own.
Types of Updates#
An update can mean changing one setting, updating packages or moving to another NixOS release. The work differs, so it helps to classify them:
| Change | Work required |
|---|---|
| Ordinary NixOS configuration | Check, build the relevant host and apply |
| Flake inputs | Review lock changes and scope, then stage deployment |
| NixOS release branch | Separately review upgrade notes and state compatibility |
| Container image or application configuration | Prepare runtime configuration, update the service and verify |
| Documentation or operational records | Synchronize Git; normally no new system generation |
For example, I still manage containers with Compose. After changing an image, the computer running it needs to recreate the container. Copying the source to other computers does not update their running programs.
Computers can share flake.lock while using different hardware and host modules. Each still needs its own output built, following the shared and host-specific organization introduced in post three.
Preparing for Updates#
Checking Configuration and System State#
From the configuration repository, inspect changes and system state:
| |
First look for uncommitted changes and preserve them before deciding how to synchronize. Note any already-failed services so you can compare afterward. Run the systemctl --user checks from the intended user’s session.
The commands show several versions: configuration in Git, the system profile, the active system and the system used for this boot. I have encountered an updated checkout and a switched system while the computer remained booted from an older generation. That is why we also check the running kernel later.
Update Time and Disk Space#
I currently update manually, roughly every two weeks or month when the computers can pause their work. This is a routine arrangement rather than an automatic upgrade setting. Fixes that need prompt attention are handled separately.
Ordinary configuration changes are often quick, while kernels and large dependencies can take much longer. An earlier kernel build took hours and failed for lack of space. I now check disk and temporary storage first and retain the generations needed for recovery. Different computers need different build budgets.
If local resources are insufficient, remote building is another option. It needs builder identity, platform and trust configured separately, and the resulting system still needs applying on the target. See the Nix remote build documentation.
Updating Flake Inputs#
Updating Inputs#
First choose one computer with a clean main checkout:
| |
nix flake update changes the lock file without applying a system. Branch selection remains in flake.nix; changing releases needs a separate upgrade review. A --no-build check cannot prove all packages build or hardware works.
For a deliberate single-input update, use:
| |
Choose this or the full update according to what you need. Even one selected input can change other dependency nodes, so read the complete diff. See the Nix input update documentation.
Saving the Updated Configuration#
After checking, commit and push the updated lock file:
| |
If adapting to new inputs required module changes, review and commit those files too. The last command prints the full revision, which we will use to compare configuration across computers. Whether the system was applied still needs checking on each one.
Other computers can synchronize this configuration directly without running nix flake update again. Updating independently might obtain inputs from different times, making problems harder to compare.
Updating Each Computer#
Synchronizing Configuration#
From the target’s configuration repository:
| |
Replace the placeholder with the recorded revision. The commands check the worktree, synchronize, then compare revisions, stopping on any failure. If newer commits have reached the remote, first decide which version to use. A separate checkout at the intended revision can help.
I generally start with a computer that is easy to observe and recover, then continue after checking it. Desktop use, unfinished compute jobs or services that cannot pause can change the order. There is no need to reboot all computers together.
Building and Applying#
Build the target’s output on that computer:
| |
--no-update-lock-file keeps the reviewed inputs during the build. Over SSH, an existing tmux session lets you reconnect to a long build after losing the connection. Rebooting and insufficient disk space still need separate handling.
After review, when ready to apply:
| |
switch applies the system and sets the next boot default. If building or applying fails, address that computer before updating others. An activation error may occur after some services have changed, so use the error and current state to work out what happened. See post five for the stages.
Rebooting and Checking#
Checking Boot Files#
After switching, compare boot components separately:
| |
When kernel or module paths change, schedule a reboot after saving work and stopping affected jobs. A changed initrd also needs a new boot to validate it. uname -r alone is insufficient: identical version strings can describe different builds.
The records also include different active and booted generations with identical kernel, module and initrd paths. Different generations alone therefore do not establish a required reboot. Other driver, service or session changes can still require a restart or new login; inspect the actual change.
Checking the System and Common Functions#
| |
After rebooting, reconnect and inspect the system that actually started. Then try the desktop, SSH, hardware, compute programs or services you use on that computer. The absence of failed units is useful, but common functions still need trying.
For example, try a service locally and then through its usual entry point. Desktop settings may need a new login. Finish checking this computer before moving on, noting anything still untested.
Using Git Submodules#
The application source, Compose definitions and system configuration I maintain do not all live in one repository. Some applications are Git submodules, which need publishing in this order:
- Commit and push application changes in the child repository.
- Record that published child revision in the parent and push the parent.
- Synchronize the parent and its recorded submodule revisions on targets.
- Prepare runtime configuration, deploy the service and verify access and function.
The parent records a child revision; it does not upload unpublished child commits automatically. Source synchronization does not rebuild a running application image either.
After preserving checkout and submodule edits and confirming updates are appropriate, use:
| |
Default submodule updates use the parent’s recorded revision and may leave a detached HEAD. They do not follow the child’s newest branch. Arrange branch synchronization separately when maintaining your own child branch; avoid forced updates that overwrite work. See the Git submodule documentation.
I have also used Git bundles to transfer published commits when remote access or credential tooling was unreliable. After transfer, compare revisions, check worktrees and submodules, then deploy the service as usual.
Troubleshooting#
If a new system boots but is unsuitable, the recovery plan can include returning to the previous profile generation:
| |
This assumes the previous profile generation is usable, so retain a known-working recovery target before updating. Restoring its kernel requires rebooting; if the system cannot boot, select a usable older generation in the boot menu. Git changes and application data are not restored by system rollback.
Update Notes#
I record the configuration revision, application result, whether a reboot occurred and the functions checked. A documentation synchronization is recorded as such. Unperformed reboots or tests stay in the notes so the next maintenance session can continue from there.
Old generations can wait until the computer has worked normally for a while. When an update fails, keep the recovery system while investigating build references and disk space.
Recommended Usage#
For computers sharing configuration, I recommend updating inputs once and applying them one at a time. Update ordinary settings, system software and container applications through their respective methods; changing one item need not require upgrading everything together.
When asking AI for help, say whether it should only prepare configuration or also apply it and reboot. At the end, check which commands and tests it actually completed and record the results.
The next post will reflect on maintaining NixOS with AI: which work suits an assistant and how actual results reveal its mistakes.
