One-step update tool and store maintenance module for flake-based NixOS
  • Shell 71.3%
  • Nix 28.7%
Find a file
2026-10-10 09:08:55 +02:00
flake.lock nixos-update: update tool and maintenance module 2026-10-03 11:02:21 +02:00
flake.nix Add nixos-activate and harden lock handling, previews and exact-build activation 2026-10-04 13:45:53 +02:00
module.nix nixos-activate: update only configured inputs (activateInputs), fall back to lock offline 2026-10-10 09:08:55 +02:00
nixos-update.sh nixos-activate: update only configured inputs (activateInputs), fall back to lock offline 2026-10-10 09:08:55 +02:00
package.nix nixos-activate: update only configured inputs (activateInputs), fall back to lock offline 2026-10-10 09:08:55 +02:00
README.md nixos-activate: update only configured inputs (activateInputs), fall back to lock offline 2026-10-10 09:08:55 +02:00
tests.sh nixos-activate: update only configured inputs (activateInputs), fall back to lock offline 2026-10-10 09:08:55 +02:00

nixos-update

One-step system update for flake-based NixOS, plus automatic store maintenance.

nixos-update             # flake update -> build -> diff -> confirm -> switch -> commit flake.lock
nixos-update --dry-run   # update and build, show what would change, restore flake.lock
nixos-update --boot      # activate at next boot (kernel updates)
nixos-update --input nixpkgs
nixos-activate           # build -> diff -> confirm -> activate; updates only `activateInputs` (default: none)
nixos-activate --dry-run # preview only, flake.lock remains unchanged

Both commands are installed by the module. nixos-activate applies edited configuration using the existing lock; it is NOT nix flake update. With programs.nixos-update.activateInputs = [ "pi" ]; it additionally updates just those inputs (offline: falls back to the lock; --no-update skips it). Both build without implicit lock updates and activate the exact closure shown in the diff (nixos-rebuild --no-reexec --store-path, required). --no-reexec prevents a legacy self-rebuild looking for <nixpkgs/nixos>/nixos-config. Confirmation uses [Y/n]: Enter confirms, n cancels, EOF cancels. Updates restore the old lock on cancellation/failure/dry-run. Existing uncommitted lock changes require --no-commit or a prior commit; unrelated staged files are never committed. The build stays GC-rooted until activation finishes. bash tests.sh exercises the workflows using command stubs (no real system changes).

The flake directory is $NIXOS_UPDATE_FLAKE, else /etc/nixos (a symlinked flake.nix is followed into its git clone). --flake DIR overrides both.

Use on any NixOS machine

nix run git+https://git.samaschke.de/ksamaschke/nixos-update -- --dry-run
nix run git+https://git.samaschke.de/ksamaschke/nixos-update#nixos-activate -- --dry-run

or as a module in the system flake:

inputs.nixos-update.url = "git+https://git.samaschke.de/ksamaschke/nixos-update";
# in the host's modules:
nixos-update.nixosModules.default
{ programs.nixos-update = { enable = true; flake = "/home/me/nixos-config"; }; }

The module installs the command and turns on weekly garbage collection (keepDays, default 14), store optimisation and a boot-menu limit (bootEntries, default 20). All of it uses mkDefault, so host settings win.