Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Observing NixOS Candidates

Compare a built NixOS generation with the running system and distinguish static changes from effects that only activation can reveal.

A NixOS toplevel is the store object for a complete system generation. Pass the exact already-built /nix/store/…-nixos-system-* path. If a build left a ./result symlink, resolve it first and review the resulting path. The default observation reads the running generation from /run/current-system, queries the local Nix daemon, and inspects store files and reachable systemd managers. It evaluates no Nix expressions, builds nothing and performs no switch. The candidate is validated as a direct store path with both system and user unit directories in the store. Observation implementation

vug system observe-os --candidate "$candidate" > observation.json

The relative symlink spelling is rejected before any observation. Captured with vug 0.2.29:

$ vug system observe-os --candidate ./result
invalid Nix store path "./result"
$ echo $?
254

Read the static diff

Field under static_diffInterpretation
from_toplevel, candidate_toplevelThe exact running and proposed store paths. Vug checks whether the running generation changed during observation.
packagesbasis: "local_store_closure", with added and removed store paths. The candidate toplevel is excluded from additions and the running toplevel from removals.
unitsAdded, removed or modified definitions under etc/systemd/system and etc/systemd/user. Entries compare definitions, masks, aliases, per-unit drop-ins and dependency links, including .wants, .requires and .upholds links. A drop-in is a supplementary configuration file that systemd merges with a unit.
shared_drop_insChanges to shared configuration such as service-wide, template or dash-prefix drop-ins, listed by selector. Effective precedence is resolved at runtime.
runtime_observationsSuccessful system or invoking-UID user manager queries. Each observation has scope, uid, observed_at_unix_seconds and loaded_units, restricted to changed units that appeared in the manager’s snapshot.

A changed NixOS user tmux-server.service reports protected: true and guard: "blocked". Other unit changes show guard: "observe_only". All unit changes report restart_prediction: "unknown" and can_override_restart_policy: false. An empty manager list means that no manager was observed. Static diff and unit traversal

Request privileged observation

Dry activation invokes the candidate’s bin/switch-to-configuration dry-activate to report prospective system actions. The child acquires the system switch lock, performs pre-switch checks and accesses privileged state in /run/nixos. Only an administrator should authorize the exact candidate after reviewing the privileged code it can run.

sudo vug system observe-os --candidate "$candidate" --dry-activate > observation.json

The administrator allowlist is /etc/vug-observe-os.allow, a root-owned, non-symlink regular file that group and others cannot write. It accepts one exact store path per line, with blank lines and lines beginning with # permitted. Vug also checks the candidate’s directory, its bin directory and the resolved activation executable before launching it. The pinned Nixpkgs dry activation returns from its system branch before enumerating user unit actions. System observation documentation Authorization and child process

Without the flag, dry_activate.status is not_requested. A child that exits successfully yields completed. A failed child yields failed and vug still prints JSON before returning 255. The report includes exit_code, system_stdout and system_stderr, with signal for a spawned child and error if spawning fails. An authorization or candidate validation error can stop the command before it writes a report.

Describe post-switch work separately

Pass --postprocess nixos-configuration:make-switch to look up the operations registered for that ID. Vug hashes the provisioned /etc/vug/observe-os/Makefile with SHA-256. A matching file yields makefile_postprocess.status: "registered" and an operations list. Vug reads the Makefile for the version check and does not execute it. An unrecognized ID, a missing or unreadable file, or different bytes yields unknown with a reason. Omitting the flag yields not_requested. Postprocess implementation

Interpret the report

This sanitized projection shows three of the four top-level sections. The paths and empty arrays are illustrative.

{
  "static_diff": {
    "from_toplevel": "/nix/store/00000000000000000000000000000000-nixos-system-example-host-old",
    "candidate_toplevel": "/nix/store/11111111111111111111111111111111-nixos-system-example-host-new",
    "packages": {"basis": "local_store_closure", "added": [], "removed": []},
    "units": [],
    "shared_drop_ins": [],
    "runtime_observations": []
  },
  "dry_activate": {"status": "not_requested"},
  "makefile_postprocess": {"status": "not_requested"}
}

The fourth section, unobservable_effects, gives each item an effect, reason and suggested verification. Use it as a checklist:

  • Review activation code and compare application state before and after activation in an isolated VM.
  • Compare swapon --show for swapfile effects.
  • Check whether Docker and Compose workloads stay up.
  • Inspect systemctl --user list-units in each relevant user’s session.
  • Inspect effective units and systemd generator output for runtime units, instance expansion and shared drop-in precedence.

Reports can include local paths and child output. Review those fields before sharing. Report and checklist definitions