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

Planning, Applying, Rollback, and Recovery

vug separates a read-only host plan from activation. It records an apply operation durably, keeps earlier generations available and guards restoration after an interruption.

Save and review a plan

From the declaration directory on a configured test host:

vug home plan > plan.json
jq '{state, kind, plan_id, fixed: (.fixed | {from_generation, to_generation, files, units})}' plan.json

Use the default JSON output for the saved plan. If the plan command fails, the file can contain a JSON error or be empty, so check the command’s exit status before using it. The plan binds the target profile, declaration, lock, policy, source inputs, current and proposed generations, file snapshots and affected systemd unit state. Those observed values are preconditions, facts that must still hold when the worker acts. Planning reads these inputs and local state without activating the profile or acquiring the closure. Use --file and --lock to point to other input files. Plan types and rechecks, Plan command.

Apply with an independent worker

vug home apply --plan plan.json --wait
# Look up the profile after the operation finishes.
vug home status --profile demo

home apply starts a transient systemd unit, a service defined at launch rather than installed permanently. The worker runs under the systemd user manager as vug-apply-<UUID>.service. With Linger=yes, an SSH disconnect can end the client command while the worker keeps running. With --wait, the client waits for the outcome and returns the worker’s result code. Without it, exit 0 can mean the operation was accepted and is still running.

The worker takes an exclusive operation lock for the state directory, rebuilds and checks the plan, and acquires and pins the closure for a new generation. Before switching it verifies roots, checks credentials and rechecks preconditions. It updates the current-generation link and managed links, reloads systemd definitions when needed and runs the planned unit jobs. The saved plan, status and append-only events.jsonl journal are under ${XDG_STATE_HOME:-~/.local/state}/vug/operations/<UUID>/. Journal records let a later worker determine which changes were attempted. Worker launch, Operation implementation.

The journal distinguishes an early abort from a failed switch that needs restoration.

Coexist with local files and services

vug installs managed dotfiles as links to generation files. It can create an absent destination or replace a link it can prove belongs to the current profile. An unmanaged destination, a missing or changed link that vug expected to own, and a .backup sibling all prevent replacement. Trust policy can reserve additional home-relative paths. vug detects Home Manager, another Nix-based user environment manager, by looking for destinations placed by its profile generation or a generation named in home-manager-<user>.service or relevant drop-ins. A file or symlink above the destination in a Home Manager generation counts as ownership of the subtree.

Managed user units are also subject to ownership checks. An existing unit from another owner, an unexpected drop-in or an unexpected alias can block the plan. A drop-in is a supplementary systemd configuration file that modifies the unit. File and Home Manager checks, Unit ownership checks.

Protect running services

The protected set includes tmux-server.service, names in trust.toml, and units marked protected = True by the current or proposed declaration. For an actual unit job, vug walks dependency and propagation links including PartOf, BindsTo, Requires, Wants, Conflicts, trigger links, reverse relations and stop or reload propagation. It checks aliases and inactive units as well, tracks visits to terminate cycles, and includes the observed chain in the preconditions. Targets and slices are checked for protection. Membership alone is insufficient to continue the walk through them. The pinned implementation follows the links that can carry the job reaching that group, for example dependencies or conflicts reached by a start job. vug checks the relevant graph again before dispatch.

To explicitly permit a change to a directly managed protected unit, name that unit when planning, for example vug home plan --allow-protected vug-demo.service > plan.json. The override is captured in the plan. It does not authorize reaching a different protected unit through dependencies. Protection and graph walk.

Defer changes and deliver credentials

With restart_policy = "next-login", vug keeps the presently installed unit definition, if any, until a new qualifying session for the profile UID. A generated user service listens to logind, the systemd login manager, and ignores sessions already present when the deferral was queued. It creates and rechecks a fresh plan from the saved inputs. If the inputs changed, create and apply a fresh ordinary plan. Linger keeps the service available, but only a qualifying login triggers activation. The login watcher cannot override protection. Login watcher, Login plan.

For credentials, list secret IDs in a unit’s credentials. Each ID selects a string, number or Boolean from an encrypted YAML file. Point sops_age_key_file in trust.toml to a private, user-owned age identity file, and lock a pinned runtime.sops entry in vug.lock. vug retains encrypted inputs with the generation and tests decryption before switching. A generated oneshot service, which runs a task to completion, prepares the selected values in a private runtime directory. systemd LoadCredential makes those values available as credential files to the target unit. Credential preparation and delivery.

Inspect, roll back and recover

vug home status --profile demo
vug home status --operation UUID

Profile status shows the active generation, pending operations, the latest operation and deferred units. Operation status is for a particular attempt and reports its phase, result and recovery information. An early failure can leave an operation aborted. After switching starts, vug attempts guarded restoration. A successful restoration gives rolled_back, while an interruption or uncertain restoration can leave needs_recovery.

To deliberately return to a retained generation such as generation 1, generate and review a rollback plan and then apply it:

vug home rollback --generation 1 > rollback.json
vug home apply --plan rollback.json --wait

For a stopped operation that reports needs_recovery, inspect its status, journal and the affected systemd units first. An uncertain job may have changed a service even when the worker could not record the outcome. Use the operation’s ID to retry guarded restoration from its journal:

vug home recover --operation UUID --wait

Recovery checks whether observed file and systemd state still permit safe restoration. It can leave the operation in needs_recovery if it cannot establish the result of a unit job. Status and restoration.

Prune old generations

vug store gc --profile demo --keep 3

This reports proposed removals. Add --apply to remove the eligible generations and unreferenced private store objects. --keep defaults to 2 and counts the newest generations with manifests. Additional roots survive for active generations, deferred unit definitions, relevant unfinished operations and generations leased by running commands. A lease is a lock that holds a generation live while a program uses it. Garbage collection, Operation roots.