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

End-to-End Walkthrough and Glossary

Build a tiny ImageMagick profile, inspect the evidence for its package record, and trace two signed generations through activation and rollback.

Build and inspect the demo

Use vug 0.2.29, a shell and jq for the registry portion. It runs in an ordinary temporary directory. For the live lifecycle portion, use a disposable Linux VM with an x86-64 Nix daemon, a running systemd user manager, Linger=yes, and an immutable vug executable as described in Installation, Trust Policy, and Host Checks. The VM is where the example writes a home dotfile and changes the active generation.

1. Write the declaration and registry

Start in a new directory and give the profile an unambiguous target. Set the VM’s hostname and user to the example values or substitute its actual lowercase hostname and account name in the declaration.

lab="$(mktemp -d)"
mkdir -p "$lab/registry/packages/im/imagemagick/versions" "$lab/v1" "$lab/v2"
cd "$lab"

cat > v1/vug.star <<'STAR'
def configure(ctx):
    return {
        "schema_version": 1,
        "profile": {
            "id": "demo",
            "kind": "home",
            "host": "example-host",
            "user": "example-user",
            "system": "x86_64-linux",
            "store_backend": "nix-daemon",
        },
        "nixpkgs": {
            "rev": "2786a2a72088ecf32aea5b3ec52099e6a7cff78f",
            "allow_unfree": False,
            "permitted_insecure": [],
        },
        "packages": {
            "imagemagick": {"attr": ["imagemagick"], "outputs": ["out"]},
        },
        "dotfiles": {
            ".config/vug-book-demo.conf": {"owner": "vug", "source": "demo.conf"},
        },
        "commands": {
            "image-info": {
                "package": "imagemagick",
                "output": "out",
                "executable": "bin/magick",
                "args": ["--version"],
            },
        },
    }
STAR
printf 'profile=first\n' > v1/demo.conf

cat > registry/packages/im/imagemagick/package.star <<'STAR'
PACKAGE = {
    "schema_version": 1,
    "name": "imagemagick",
    "license": "Apache-2.0",
    "upstream": {"sources": ["https://cache.nixos.org/"]},
}
STAR

cat > registry/packages/im/imagemagick/versions/7.1.2-35.star <<'STAR'
RECORD = {
    "schema_version": 1,
    "version": "7.1.2-35",
    "build": {
        "kind": "nix-output",
        "nix_system": "x86_64-linux",
        "nixpkgs_rev": "2786a2a72088ecf32aea5b3ec52099e6a7cff78f",
        "nix_attribute": ["imagemagick"],
        "outputs": ["out"],
    },
}
STAR

vug record check-tree --root registry
vug record check-tree --root registry --evaluated > records.json

The mini-registry has one package and one version, with Errors: []. Its package and version correspond to the declaration’s Nixpkgs attribute, but the declaration already has the information to resolve this ordinary Nix output. A registry checkout becomes a direct lock input when the declaration selects an overlay. Writing declarations ImageMagick version record

2. Compute a merge decision

Model both records as additions. The repeated hex strings are fixture IDs, and the only supplied evidence is the local format check. In a real workflow the caller takes the identity and diff from Git, hashes the actual policy, and authenticates each check result.

jq '{
  base_sha: ("0" * 40),
  head_sha: ("1" * 40),
  tree_oid: ("2" * 40),
  policy_digest: ("3" * 64)
} as $id | {
  schema_version: 1,
  identity: $id,
  core_packages: [],
  changes: [.Records | to_entries[] | {
    path: .key, before: null, after: {mode: "100644", evaluated: .value}
  }],
  required_checks: [1, 3, 4, 5, 6, 7, 8] | map({check: ., target: "imagemagick"}),
  results: [{check: 1, target: "imagemagick", identity: $id, status: "passed"}]
}' records.json > request.json

vug record decide-merge --input file://request.json > decision.json
jq '{ChangeClass, Scope, Decision, missing: [.IncompleteChecks[].Check]}' decision.json

Expect record_change, a passed scope and an incomplete verdict, with Checks 3–8 missing. decide-merge computes from the supplied results. Merge request contract

3. Set up trust and create signed locks

Use the management role to create the lock-signing key. In this one-VM lab the same person can perform both roles. Save the trust file below with mode 0600 at $XDG_CONFIG_HOME/vug/trust.toml (default ~/.config/vug/trust.toml). Replace the placeholder with the part after demo-lock: from lock.pub. Keep lock.sec private on the management side.

(umask 077
 nix-store --generate-binary-cache-key demo-lock "$lab/lock.sec" "$lab/lock.pub")
schema_version = 1

[lock_keys]
demo-lock = "<base64 public half from lock.pub>"

[substituters."https://cache.nixos.org"]
profiles = ["demo"]

[substituters."https://cache.nixos.org".keys]
"cache.nixos.org-1" = "6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="

Set VUG_RUNTIME to the store output of vug 0.2.29 that contains bin/vug. Management needs signed cache metadata for that output and every reference, including any new runtime paths it introduces. If the official cache does not have the runtime, use a provisioned HTTPS lab cache with signed contents. Add its URL, key and profiles = ["demo"] to the trust file, and configure that public-to-the-VM origin and key in the daemon. A locally built runtime alone does not supply the cache metadata that the lock command checks. Use a currently cached Nixpkgs revision if the example’s package closure is no longer served, and update both declaration and registry accordingly. Lock inputs and cache requirements Cache trust schema

trust="${XDG_CONFIG_HOME:-$HOME/.config}/vug/trust.toml"
cd "$lab"

vug record lock --file v1/vug.star --trust "$trust" \
  --signing-key "$lab/lock.sec" --runtime "vug=${VUG_RUNTIME:?set VUG_RUNTIME}:bin/vug"

The lock is written next to v1/vug.star. The initial trust file, the signed lock and the declaration’s inputs are what the client needs. Keep the signing key out of the client bundle. Lock implementation

4. Plan, apply, run and roll back

In the VM, start with no demo generation and no existing demo dotfile. Review each plan before its apply command. Run apply as the target user.

cd "$lab"
vug store doctor --file v1/vug.star
vug home plan --file v1/vug.star > plan-v1.json
jq . plan-v1.json
vug home apply --plan plan-v1.json --wait
first="$(vug home status --profile demo | jq -er '.active_generation')"
vug home dev --file v1/vug.star -- magick --version
vug home run --file v1/vug.star --command image-info
cat "$HOME/.config/vug-book-demo.conf"

For generation two, retain the first inputs and create a second declaration with changed fixed command arguments and dotfile bytes. Sign its lock on the management side before planning the new generation.

sed 's/"--version"/"-list", "format"/' v1/vug.star > v2/vug.star
printf 'profile=second\n' > v2/demo.conf

vug record lock --file v2/vug.star --trust "$trust" \
  --signing-key "$lab/lock.sec" --runtime "vug=$VUG_RUNTIME:bin/vug"

vug home plan --file v2/vug.star > plan-v2.json
jq . plan-v2.json
vug home apply --plan plan-v2.json --wait
vug home run --file v2/vug.star --command image-info
cat "$HOME/.config/vug-book-demo.conf"

The first invocation prints version information. The second generation lists available formats. The dotfile changes from profile=first to profile=second. With the first generation still retained, plan the rollback from the current profile and apply it separately.

vug home rollback --file v2/vug.star --generation "$first" > rollback.json
jq . rollback.json
vug home apply --plan rollback.json --wait
vug home status --profile demo
vug home run --file v1/vug.star --command image-info
cat "$HOME/.config/vug-book-demo.conf"

The declared command returns to version reporting and the file returns to profile=first. Compare the observable content and command behavior after each apply. If a precondition changes, make a fresh plan from the intended inputs. If the operation stops in an uncertain state, inspect its operation status and follow the recovery procedure. For system-level changes in the VM, use NixOS observation on an already built toplevel. Home rollback applies to the home profile. Home lifecycle Home command implementation

Glossary

TermDefinition
ABIApplication binary interface, the binary-level contract among executables, loaders and libraries.
ActivationThe operations that make a prepared generation active. Home activation and NixOS system activation are separate.
ApplyExecute a saved home plan after rechecking its assumptions under the operation lock.
Attic / CachixServices for hosting Nix binary caches. A private cache requires authentication as well as trusted signatures.
Binary cacheA server that supplies prebuilt Nix store objects and their metadata.
Bind mountA mount that makes a host file, directory, device or socket visible at a path in another filesystem view.
BubblewrapLinux namespace launcher used by vug for isolation and mount setup.
Candidate identityThe base commit, head commit, tree ID and policy digest that bind check results to one candidate.
ClosureA set of store objects together with every transitively referenced object.
DeclarationThe environment data returned by configure(ctx) in vug.star.
DerivationNix’s recipe for building an output, identified by its .drv store path.
Drop-inA supplemental systemd configuration file merged with a unit definition.
Dry activationThe candidate’s switch-to-configuration dry-activate action, guarded by root authorization and used to observe prospective system actions.
Durable ObjectCloudflare’s stateful execution and storage component. The gate uses one SQLite-backed object for its queue.
ELFExecutable and Linkable Format, the Linux format for native executables and shared libraries.
FHSFilesystem Hierarchy Standard. In vug, a command can request a locked x86-64 layout with familiar paths under /usr.
Garbage collection (GC)Removal of unreferenced store objects and unneeded generations. Roots and leases keep the relevant data live.
GC rootA reference that keeps a store object and its closure reachable for garbage collection.
GenerationA saved activation snapshot of a profile with its declaration, lock and managed state.
Generation leaseA shared lock held while a command uses a generation, protecting it from GC.
Git tree IDThe Git object ID of a file hierarchy, including its entries’ modes and object IDs.
LingerA logind setting that keeps a user’s systemd manager available beyond an interactive login.
LockThe signed vug.lock binding a normalized declaration, package outputs, fixed tools and closure metadata.
Management CIThe trusted workflow that resolves and signs locks or runs gate checks using managed inputs.
Merge haltThe durable merge_halted flag that blocks further merge calls when a merge outcome cannot be reconciled.
NARNix Archive, the canonical serialized form of a Nix store object.
NarinfoCache metadata for a store path, including its NAR hash, references and signatures.
NixOS toplevelThe store path representing one built NixOS system generation.
NixpkgsThe package collection and Nix expressions that vug resolves at a pinned commit.
OIDCOpenID Connect. GitHub Actions uses it to issue a short-lived token that identifies the callback job.
OutputOne named result of a derivation, such as out or dev.
OverlayA change to the Nixpkgs package set used to substitute a reviewed package recipe.
PlanA saved read-only report of intended changes and observed preconditions.
ProfileThe declared environment identity for a target host, user, system and store backend.
Protected unitA systemd unit subject to vug’s protective guard, including tmux-server.service.
Provenance policyThe trusted rules and pinned origins used to verify source and patch evidence.
RealisationMaking the output of a Nix derivation available locally by substitution or building it.
RecoveryRetrying guarded restoration after an interrupted or uncertain home operation.
RegistryA ledger of Starlark package and version records in a defined directory layout.
Reverse dependencyA package that depends on the package under review. The gate follows build-time edges for Check 7.
RollbackPlanning and applying a return to a retained home generation.
ShardA directory grouping determined by the first two package-name characters, or one character plus _.
Smoke testA limited execution check. The gate invokes enumerated executables with --version.
SONAMEA shared object’s loader-visible name, for example libexample.so.1.
StarlarkA deterministic Python-like language used to describe environments and registry data.
Store backendThe mechanism that houses the closure. nix-daemon uses the shared Nix store and vug-owned uses a private store.
Strict branch protectionGitHub’s up-to-date requirement for a PR head when checking whether the protected branch can accept its merge.
SubstituterA configured binary cache origin used to fetch store objects instead of building them.
Systemd managerThe service manager for the system or a particular user. Vug can query a reachable manager’s loaded units.
Test merge refrefs/pull/<n>/merge, GitHub’s synthetic merge of a pull request used to compare its parents and resulting tree.
Trust policytrust.toml, which sets allowed lock-signing keys, substituters, cache keys and local protections.
User / PID namespaceIndependent Linux views of user and group IDs or process IDs, respectively.
Verified merge treeThe tree whose parents and contents the gate has checked before publishing vug/verified-merge-tree on the head.