| 1 | # A guide to working in the valley |
| 2 | |
| 3 | This guide follows the jobs people do in a valley. Start with the [README](../README.md) for a short |
| 4 | tour, [Concepts and glossary](./concepts.md) for the terms used here, and |
| 5 | [Reference](./reference.md) for every command flag, environment variable, ref rule, and schema. |
| 6 | |
| 7 | - [Client setup](#client-setup) gets an author or reviewer connected. |
| 8 | - [Authoring a change](#authoring-a-change) takes a local commit to review. |
| 9 | - [Reviewing and approving changes](#reviewing-and-approving-changes) takes a ready change to |
| 10 | `main`. |
| 11 | - [Planning work with knots](#planning-work-with-knots) records and connects work. |
| 12 | - [Recovering from failure](#recovering-from-failure) explains what to do when work stops. |
| 13 | - [Running a valley host](#running-a-valley-host) sets up a NixOS deployment. |
| 14 | - [Contributing to the-valley](#contributing-to-the-valley) runs the project's development checks. |
| 15 | |
| 16 | The commands below describe implemented behavior. Host names, principals, verification policy, and |
| 17 | service settings are deployment choices. Replace the example values with those your administrator |
| 18 | provides. The [README's current status](../README.md#configuration-and-current-status) lists what is |
| 19 | not built. |
| 20 | |
| 21 | ## Client setup |
| 22 | |
| 23 | The client lets you propose work, review changes, and read the live plan. You need git, SSH access |
| 24 | to the valley host, and Nix with flakes enabled, on `x86_64-linux` or an Apple silicon Mac |
| 25 | (`aarch64-darwin`). [Platforms](./reference.md#platforms) lists what differs on a Mac. |
| 26 | |
| 27 | 1. Clone the-valley's source from the URL your administrator provides. From that checkout, run: |
| 28 | |
| 29 | ```sh |
| 30 | nix run .#valley -- help |
| 31 | nix shell .#valley |
| 32 | valley --version |
| 33 | ``` |
| 34 | |
| 35 | `nix run` runs one command. `nix shell` puts the packaged `valley` on your path for the rest of |
| 36 | this guide. `valley help` prints a command summary; `valley help <verb>` prints help for one |
| 37 | verb. The package supplies the helpers its commands need. |
| 38 | |
| 39 | 2. Clone the project you will work on and name the principal associated with your SSH key: |
| 40 | |
| 41 | ```sh |
| 42 | git clone git@valley.example:demo |
| 43 | cd demo |
| 44 | git config valley.principal operator |
| 45 | git config user.name "Your name" |
| 46 | git config user.email you@example.com |
| 47 | ``` |
| 48 | |
| 49 | Use your own git author name and email. `valley.principal` names you in change records and knots. |
| 50 | It does not grant permission. The host checks the principal associated with the key you actually |
| 51 | use. |
| 52 | |
| 53 | 3. Check that the client can verify recorded landings. No client configuration is needed: the client |
| 54 | reads the host's trusted signers file and integrator signing name from the instance repository |
| 55 | (**implemented**). Show the host's publication: |
| 56 | |
| 57 | ```sh |
| 58 | git ls-remote git@valley.example:instance refs/the-valley/signers |
| 59 | ``` |
| 60 | |
| 61 | Use the instance repository your project's `policy/valley` names. If it prints nothing, the host |
| 62 | publishes nothing, and some submitted versions appear `uncertain`; see |
| 63 | [recovery](#an-uncertain-landing). To use other values than the host's, set them yourself. A |
| 64 | setting wins over the publication: |
| 65 | |
| 66 | ```sh |
| 67 | export VALLEY_KNOWN_SIGNERS="$HOME/.config/valley/known-signers" |
| 68 | export VALLEY_INTEGRATOR_SIGNER=integrator |
| 69 | ``` |
| 70 | |
| 71 | 4. If approval runs checks on your machine, configure your Ed25519 attestation key and its |
| 72 | registered signing name: |
| 73 | |
| 74 | ```sh |
| 75 | export VALLEY_ATTEST_KEY="$HOME/.ssh/valley-attest" |
| 76 | export VALLEY_ATTEST_NAME=operator |
| 77 | ``` |
| 78 | |
| 79 | When every required check already has eligible evidence on `origin` (for example, from a check |
| 80 | worker), approval needs no signing key. Approval runs `command` checks locally, and builds `nix` |
| 81 | checks only when you pass `--build-here`. When a check runs locally, the host must trust that |
| 82 | signing key. Your SSH principal must also be allowed to approve. These are separate parts of |
| 83 | [identity](./concepts.md#principals-and-grants); see |
| 84 | [Environment variables and configuration](./reference.md#environment-variables-and-configuration) |
| 85 | for every client setting. |
| 86 | |
| 87 | 5. To sign your approvals, select your approval key: a YubiKey's PIV slot, or a software key file. |
| 88 | The host must list it in the approval keys it publishes. |
| 89 | |
| 90 | ```sh |
| 91 | export VALLEY_APPROVAL_PIV=9c |
| 92 | # or: export VALLEY_APPROVAL_KEY="$HOME/.ssh/valley-approve" |
| 93 | ``` |
| 94 | |
| 95 | This key is yours alone: it is not the attestation key, and an agent runner never holds it. |
| 96 | |
| 97 | To install updates into your user Nix profile, name the-valley's source repository: |
| 98 | |
| 99 | ```sh |
| 100 | valley self-update --repo git@valley.example:the-valley --branch main |
| 101 | ``` |
| 102 | |
| 103 | It builds the selected commit, tests the new client, and installs it. For repeated use, save the |
| 104 | repository with `git config --global valley.selfUpdate.repo git@valley.example:the-valley`, then run |
| 105 | `valley self-update`. Without a configured repository, self-update is off. Run |
| 106 | `valley self-update --help` for rollback and pinning. |
| 107 | |
| 108 | The installed package includes Bash and Zsh completions. For a shell using the checkout directly, |
| 109 | source `completions/valley.bash` in Bash. In Zsh, add the checkout's `completions` directory to |
| 110 | `fpath` before running `autoload -Uz compinit; compinit`. |
| 111 | |
| 112 | ## Authoring a change |
| 113 | |
| 114 | A change starts with a local commit. This example uses a new git branch called `greeting` to carry |
| 115 | it. Run it in a project with an initial `main` and verification policy already set up. |
| 116 | |
| 117 | ### Create and ready the first version |
| 118 | |
| 119 | ```sh |
| 120 | git fetch origin |
| 121 | git switch -c greeting origin/main |
| 122 | printf 'Hello from the valley.\n' > greeting.txt |
| 123 | git add greeting.txt |
| 124 | git commit -m 'Add a greeting' |
| 125 | valley checks |
| 126 | ``` |
| 127 | |
| 128 | `valley checks` lists what this diff requires. It does not run the checks. Run the commands named by |
| 129 | your project's policy before asking for review. For a Nix check named `prose-format` in this |
| 130 | repository, for example: |
| 131 | |
| 132 | ```sh |
| 133 | nix build --no-link .#checks.x86_64-linux.prose-format -L |
| 134 | ``` |
| 135 | |
| 136 | Or let the host's check worker build them. With a key that holds the telemetry `observe` grant: |
| 137 | |
| 138 | ```sh |
| 139 | valley checks --build |
| 140 | ``` |
| 141 | |
| 142 | It asks the worker to build the `nix` checks `HEAD` requires and waits up to two hours (`--wait`). |
| 143 | It passes (exit 0) once `origin` holds evidence for every check. Otherwise (exit 1) it says why it |
| 144 | stopped and shows what the worker recorded for this tree: each check's result and, for any failed |
| 145 | check, a `nix log` command for its build log or the error that stopped evaluation. `nix log` reaches |
| 146 | that log where the deployment lets this machine read the worker's Nix store or a binary cache of it |
| 147 | that serves build logs. Approval reuses the evidence the worker publishes once the change is marked |
| 148 | `ready` at the same tree. |
| 149 | |
| 150 | For this new, unpushed commit, stamp a stable Change ID and publish the first version: |
| 151 | |
| 152 | ```sh |
| 153 | valley ready --stamp |
| 154 | valley status greeting |
| 155 | ``` |
| 156 | |
| 157 | `ready` prints a handle and version, such as `demo kqxm v1 ready`. Use the handle it actually prints |
| 158 | in later commands. The handle identifies the change even when its commit changes. `status` reports |
| 159 | readiness, any request, and the latest integration result. `valley pending` counts each ready |
| 160 | change's checks; `valley pending --checks` names the ones that failed, those that failed in the |
| 161 | host's check worker's build before any note recorded them, and what they cost. Read a draft's |
| 162 | results and a failed build with `valley pending --drafts --checks`: a failed build comes with the |
| 163 | command that reads the worker's log. |
| 164 | |
| 165 | If the commit already carries a `Change-Id` trailer or a jj `change-id` header, push it first and |
| 166 | run `valley ready` without `--stamp`: |
| 167 | |
| 168 | ```sh |
| 169 | git push -u origin HEAD |
| 170 | valley ready |
| 171 | ``` |
| 172 | |
| 173 | Without `--stamp`, `ready` uses the pushed tip by default. Keep the full Change ID when recording a |
| 174 | new revision. The [change concept](./concepts.md#a-change-ready-approve-submitted) explains how |
| 175 | headers, trailers, and `--change <id>` preserve it. |
| 176 | |
| 177 | ### Revise or pause |
| 178 | |
| 179 | Pause a ready change before editing it: |
| 180 | |
| 181 | ```sh |
| 182 | valley unready kqxm |
| 183 | ``` |
| 184 | |
| 185 | It becomes a draft. If it has an approval, ask a principal allowed to approve to |
| 186 | [delete the outstanding request](#withdraw-or-revoke-an-approval) before you ready a replacement. |
| 187 | Otherwise, readying the edited change can let the old version land: its request still names the old |
| 188 | head. |
| 189 | |
| 190 | Edit the files, then amend the commit while keeping its `Change-Id` trailer: |
| 191 | |
| 192 | ```sh |
| 193 | git add greeting.txt |
| 194 | git commit --amend --no-edit |
| 195 | git push --force-with-lease origin HEAD |
| 196 | valley ready |
| 197 | valley status kqxm |
| 198 | ``` |
| 199 | |
| 200 | The new head becomes the next version of the same change. On the same branch, `valley ready` keeps |
| 201 | the live change even without a header or trailer; on a different branch, use |
| 202 | `valley ready --change <full-change-id>` after pushing it. |
| 203 | |
| 204 | ### Withdraw or revoke an approval |
| 205 | |
| 206 | To abandon the change, run `valley withdraw kqxm`. This marks it withdrawn. The integrator removes |
| 207 | outstanding requests on its next pass while the change is still withdrawn. Do not ready a withdrawn |
| 208 | change again until that removal is confirmed. For immediate revocation, a principal allowed to |
| 209 | approve can delete its request: |
| 210 | |
| 211 | ```sh |
| 212 | git push origin :refs/the-valley/integration-requests/main/c-<full-change-id> |
| 213 | ``` |
| 214 | |
| 215 | Replace the whole `<full-change-id>` placeholder before running this command. If an older request |
| 216 | uses a branch name, delete that request too. Use |
| 217 | `git ls-remote origin 'refs/the-valley/integration-requests/main/*'` to list them. Neither pausing |
| 218 | nor withdrawing undoes a completed landing. See the |
| 219 | [integrator's final readiness check](./concepts.md#the-host-the-hook-and-the-integrator) for the |
| 220 | limit when a landing is already in progress. |
| 221 | |
| 222 | ### Restack onto main |
| 223 | |
| 224 | Rebase a ready change when it needs the latest `main`. Before replacing an approved version, |
| 225 | [revoke its outstanding request](#withdraw-or-revoke-an-approval). |
| 226 | |
| 227 | ```sh |
| 228 | valley rebase kqxm |
| 229 | valley status kqxm |
| 230 | ``` |
| 231 | |
| 232 | This rebases the whole stack beneath the named change, pushes the new heads, and records new |
| 233 | versions. It leaves your local checkout in place. Read its output before editing locally again; |
| 234 | fetch the remote updates and reconcile your local branch with them. If a record update fails, finish |
| 235 | with the exact `valley ready` command it prints. |
| 236 | |
| 237 | Get the rebased version reviewed and approved again. A host that runs the restacker rebases ready |
| 238 | changes for you after each landing, and its versions need approval in the same way. Automatic |
| 239 | approval carry is not built. For conflicts or an uncertain landing, use |
| 240 | [recovery](#recovering-from-failure). |
| 241 | |
| 242 | ## Reviewing and approving changes |
| 243 | |
| 244 | A principal allowed to approve can turn a ready change into an integration request. Start in a clone |
| 245 | of the project with the [client signing settings](#client-setup). |
| 246 | |
| 247 | ```sh |
| 248 | valley pending |
| 249 | valley review kqxm |
| 250 | ``` |
| 251 | |
| 252 | A change can land on its fast checks while slower ones follow it: the host's worker runs those on |
| 253 | `main` when nothing waits, one run covering every landing since their last pass. `pending` opens |
| 254 | with whether `main` is `clear`, `clearing` while they run, or `muddy` when one failed, with the |
| 255 | landings it covers. If your key has the telemetry `observe` grant, look there for `host` entries |
| 256 | about failed, stale, or unavailable automation. Each entry points you to its logs. |
| 257 | |
| 258 | `pending` lists the changes waiting on your approval under `needs you`, one row each, numbered in |
| 259 | the order they would land, with their checks and how long they have been ready. A stack is one row, |
| 260 | its top's, since approving the top lands every layer. Changes that need nothing from you are under |
| 261 | `moving`: approved ones waiting on their checks and the integrator, and those whose check failed or |
| 262 | whose restack stopped, which their author fixes. A row says `conflicts with mytm` when it and |
| 263 | another ready change conflict: approving one makes the other need a rebase and a second look. |
| 264 | `--checks` and `-v` name the conflicted paths. A last line counts the drafts and stray branches; |
| 265 | `--drafts` and `--branches` list them, and `-v` shows each row's commits and diff. |
| 266 | |
| 267 | Use a handle from `pending`. Review pages the diff and offers actions at the terminal. Choose |
| 268 | `[s]kip` to leave it alone or `[a]pprove` to approve the head you saw. `[r]eject` deletes the |
| 269 | change's branch once you confirm, then withdraws the change, so it leaves `needs you`; if the |
| 270 | withdrawal fails, review names the `valley withdraw` command to run. A draft or withdrawn layer |
| 271 | stops review from offering approval for that layer or anything above it. A stack is shown from the |
| 272 | bottom up; approving its top includes the layers below. Review lists a layer below the top that is |
| 273 | already approved but does not page it. Name that layer to review it. |
| 274 | |
| 275 | Run `valley review` with no handle to review everything under `needs you`, across every project the |
| 276 | host serves, in landing order. Each change gets the same prompt, and the walk ends with what you did |
| 277 | to each and what still needs you. |
| 278 | |
| 279 | A change behind `main` is approved as it is. The integrator applies the change onto `main` as `main` |
| 280 | stands, and a host that runs the restacker rebases ready changes itself. The prompt's header says |
| 281 | so, as in `kqxm v3 · behind main (integrator merges)`. When the restacker reports a conflict, it |
| 282 | says `conflicts with main (owner resolving)` instead. Review offers no rebase; an author rebases |
| 283 | their own change with `valley rebase`. |
| 284 | |
| 285 | A change can move while you read it: its owner may return it to draft, ready a new version, or |
| 286 | withdraw it, and it may land. Review reads the change again before `[a]pprove` or `[r]eject` acts. |
| 287 | When the change has moved, review says what changed in one line and does nothing. For a new version |
| 288 | it says why your answer does not carry, offers what changed since the version you read, and offers |
| 289 | to approve the new version: at once when only main moved under its commits, after you view what |
| 290 | changed when a commit changed. A restack that brings the same changes keeps your answer instead: |
| 291 | `kqxm moved to v4 while you were reviewing. v4 is v3 rebased onto the new main with no other changes, so your approval covers it.` |
| 292 | Approving then lands v4, and the verdict names it with its checks, such as |
| 293 | `◐ kqxm v4 approved · 19 checks running · lands when they pass`. |
| 294 | |
| 295 | For a revised change, review automatically compares it with an earlier approved version when one can |
| 296 | be identified. Its first line says whether the change's own commits changed: rebased, with the same |
| 297 | file changes, gets a short summary; rebased onto files main also edited names the landings that |
| 298 | edited them; edited carries the approved version onto main and shows only what the new version |
| 299 | changes beyond that, and how it resolved any conflict. Use `[v]iew diff` to see the whole change. |
| 300 | The [comparison rules](./architecture.md#review-against-the-approved-version) explain what can be |
| 301 | compared. |
| 302 | |
| 303 | You can also approve from the command line: |
| 304 | |
| 305 | ```sh |
| 306 | valley approve kqxm |
| 307 | valley status kqxm |
| 308 | ``` |
| 309 | |
| 310 | On a terminal, `approve` asks you to confirm the head and title. For automation, pass the exact |
| 311 | reviewed commit with `valley approve --head <sha> kqxm`. Approval reuses eligible evidence already |
| 312 | on `origin` for the commit's content tree (see [`valley approve`](./reference.md#valley-approve)). |
| 313 | It runs and signs the required `command` checks, and publishes the new evidence and request |
| 314 | together. When every required check is covered, nothing runs and no signing key is needed. Approval |
| 315 | does not wait for landing. An enabled integrator processes the request; `status` tells you what |
| 316 | happened. Approval ends in one line that says what happened and what comes next: |
| 317 | |
| 318 | ```text |
| 319 | ✓ kqxm v3 approved · checks passed · landing on main |
| 320 | ``` |
| 321 | |
| 322 | A refusal says what stands in the way, and what to run about it: |
| 323 | |
| 324 | ```text |
| 325 | ⊘ kqxm v3 not approved · change is a draft |
| 326 | run: valley ready --change <id> kqxm |
| 327 | ``` |
| 328 | |
| 329 | `valley approve -v` also prints the refs, evidence and signers behind that line. |
| 330 | |
| 331 | With an approval key selected, approval signs the approved version and publishes the signed note |
| 332 | with the request. A YubiKey asks for its PIN and a touch, as its slot's policies say: |
| 333 | |
| 334 | ```text |
| 335 | ✓ kqxm v3 signed and approved · checks passed · landing on main |
| 336 | ``` |
| 337 | |
| 338 | `--approval-piv` or `--approval-key <file>` selects a key for one command. If the key does not sign, |
| 339 | nothing is published and you must approve again. With no key selected, approval files the request |
| 340 | and says that no signed approval was written. |
| 341 | |
| 342 | When a required `nix` check has no evidence on `origin` yet, approval still files the request at |
| 343 | once, after the required `command` checks pass. Your approval is recorded, and no `nix` check is |
| 344 | built on your machine. The integrator keeps the request, and approval says how many checks it is |
| 345 | waiting for, such as `◐ kqxm v3 approved · lands when 3 checks pass (1/4 passed)`. When evidence is |
| 346 | published, an enabled integrator considers the request again, and you do not need to approve again. |
| 347 | Landing still requires the change to apply cleanly and carry acceptable evidence for every required |
| 348 | check. |
| 349 | |
| 350 | An enabled worker that serves the project attempts the missing `nix` checks of a ready change's |
| 351 | unlanded active version. It cannot add checks to its own existing evidence ref for the same tree, |
| 352 | and a failed build publishes nothing. No worker builds a branch no record is on, or a version that |
| 353 | is not the active one. Waiting does not ensure that the missing evidence will be published. |
| 354 | |
| 355 | Use `--build-here` on the initial approval if you need to build missing `nix` checks on your own |
| 356 | machine. Once this signer has published evidence for the tree, another approval cannot add checks to |
| 357 | that ref. |
| 358 | |
| 359 | ```sh |
| 360 | valley approve --build-here kqxm |
| 361 | valley review --build-here kqxm |
| 362 | ``` |
| 363 | |
| 364 | After a successful landing, update your local `main`: |
| 365 | |
| 366 | ```sh |
| 367 | git fetch origin |
| 368 | git switch main |
| 369 | git merge --ff-only origin/main |
| 370 | ``` |
| 371 | |
| 372 | To inspect all recorded changes, including submitted and withdrawn ones, use |
| 373 | `valley changes --json`. For changes across the instance, use `valley pending --all` or |
| 374 | `valley changes --json --all`; see [CLI JSON outputs](./reference.md#cli-json-outputs) for their |
| 375 | output schemas. These need access to the instance and project repositories. |
| 376 | |
| 377 | ### Watch activity and inspect results |
| 378 | |
| 379 | `status` and `changes --json` read the records on the host. Use them to inspect landing results. If |
| 380 | your deployment provides access to its NATS bus, configure a NATS context for that endpoint and run: |
| 381 | |
| 382 | ```sh |
| 383 | valley tail |
| 384 | ``` |
| 385 | |
| 386 | It streams events until you interrupt it. Bus access is a deployment choice; the default host bus |
| 387 | listens on loopback. An administrator can use `journalctl -u valley-integrator@demo` on the host for |
| 388 | service logs. |
| 389 | |
| 390 | An administrator can republish the host's current refs with `replay`. On a host with |
| 391 | `services.valley.bus.enable = true` at its default address, enter `nix shell .#valley` from a |
| 392 | checkout of the-valley, then run: |
| 393 | |
| 394 | ```sh |
| 395 | sudo -u git env NATS_URL=nats://127.0.0.1:4222 "$(command -v valley)" replay /srv/git/demo.git |
| 396 | ``` |
| 397 | |
| 398 | Use the deployment's bus address and credentials if they differ. This writes current-state events to |
| 399 | the bus; it is not a history viewer. See |
| 400 | [events and mirrors](./architecture.md#after-a-push-events-and-mirrors). |
| 401 | |
| 402 | ### Read the host's telemetry |
| 403 | |
| 404 | Telemetry lets a session see what the host's components are doing without a shell on the host: the |
| 405 | check worker and the builds it runs, the integrators, the registry compiler, the signers publisher, |
| 406 | the publish queues, the bus, the web publisher, backups, `valley-init` and the build slice. Use |
| 407 | telemetry to diagnose host behaviour. It has no role in approval or evidence. |
| 408 | |
| 409 | An observer reads it with the same SSH key it pushes with: |
| 410 | |
| 411 | ```sh |
| 412 | valley telemetry sources # what the host runs, and each source's state |
| 413 | valley telemetry snapshot # the worker's pass, its failures and open runs |
| 414 | valley telemetry read --source=worker # the worker's records and its systemd lifecycle |
| 415 | valley telemetry read --source=worker --logs # with the build output, marked untrusted |
| 416 | valley telemetry follow --seconds=300 --logs # what happens next, for five minutes |
| 417 | valley telemetry --remote git@valley-host:app.git sources # outside a checkout |
| 418 | ``` |
| 419 | |
| 420 | `follow` and `read` end with a cursor. Pass it to `--since` to carry on where the last one stopped. |
| 421 | A gap in what the host still holds, an error, or an answer that broke off is said, so silence always |
| 422 | means nothing happened. Each answer is bounded: a read returns at most 1000 records and 4 MiB, and a |
| 423 | follow lasts at most 300 seconds. |
| 424 | |
| 425 | `--logs` shows what checks and services printed. That text comes from whoever wrote the check, so it |
| 426 | is marked untrusted and its control characters are escaped. Leave `--logs` off unless the output is |
| 427 | what you need. |
| 428 | |
| 429 | To publish a workstation's commands, approvals and check runs to the host, so a session can see them |
| 430 | while they run: |
| 431 | |
| 432 | ```sh |
| 433 | git config --global valley.telemetry true |
| 434 | ``` |
| 435 | |
| 436 | Every `valley` command then records its verb, flag names, project, exit status, and wall time (plus |
| 437 | each phase's time and processes for `valley pending` and `valley status`), never an argument's |
| 438 | value, path, title, or body. Each approval attempt from `valley approve` or `valley review` also |
| 439 | records its steps and check progress. Records wait in a local spool and go in the background to the |
| 440 | valley named by the checkout's telemetry remote, and to no other. An unreachable host never slows, |
| 441 | fails, or alters a command's output; `valley telemetry flush` sends what is left later. |
| 442 | |
| 443 | ## Planning work with knots |
| 444 | |
| 445 | The plan graph records work and the relationships between its knots. Read it from a clone of the |
| 446 | primary valley repository: |
| 447 | |
| 448 | ```sh |
| 449 | valley plan |
| 450 | valley plan --all |
| 451 | ``` |
| 452 | |
| 453 | The first command shows this project's plan. The second reads projects published by the serving |
| 454 | host. A source mirror does not carry the plan graph. See |
| 455 | [project storage](./concepts.md#records-project-storage-the-plan-graph-and-knots). |
| 456 | |
| 457 | Create an outcome and inspect the ID it prints: |
| 458 | |
| 459 | ```sh |
| 460 | valley knot new outcome 'Greeting reaches readers' --owner operator |
| 461 | valley knot list --status active |
| 462 | ``` |
| 463 | |
| 464 | Use that ID in place of `oc-1234567` below: |
| 465 | |
| 466 | ```sh |
| 467 | valley knot show oc-1234567 |
| 468 | valley knot set oc-1234567 status=in-progress |
| 469 | valley knot new bug 'Greeting needs an example' --parent oc-1234567 |
| 470 | valley knot link oc-1234567 --change valley:demo/<full-change-id> |
| 471 | ``` |
| 472 | |
| 473 | Replace `<full-change-id>` with the change's full ID. The link connects the plan to the work that |
| 474 | fulfills it. A dependency uses `--blocked-by <knot-id>` instead. When the outcome is complete: |
| 475 | |
| 476 | ```sh |
| 477 | valley knot set oc-1234567 status=done |
| 478 | valley plan |
| 479 | ``` |
| 480 | |
| 481 | Comments record findings on a knot. `valley knot show` prints each comment's ID in brackets. A |
| 482 | comment's author or a holder of the `approve` grant can replace a comment's text with `--edit`: |
| 483 | |
| 484 | ```sh |
| 485 | valley knot comment oc-1234567 -m 'Waiting on the example.' |
| 486 | valley knot show oc-1234567 |
| 487 | valley knot comment oc-1234567 --edit <comment-id> -m 'The example landed.' |
| 488 | ``` |
| 489 | |
| 490 | The plan graph keeps every earlier text in its commit history. `valley knot log` lists the commits |
| 491 | that touched a knot or its comments, and `valley knot show --at <commit>` shows the knot at that |
| 492 | commit: |
| 493 | |
| 494 | ```sh |
| 495 | valley knot log oc-1234567 |
| 496 | valley knot show oc-1234567 --at <commit> |
| 497 | ``` |
| 498 | |
| 499 | Use `valley knot schema` to see each type's fields and allowed statuses. Knot writes validate the |
| 500 | resulting graph and push it directly; they do not go through change approval. See |
| 501 | [`valley knot`](./reference.md#valley-knot) for every subcommand and flag, and |
| 502 | [the plan graph](./architecture.md#the-plan-graph) for validation and concurrent edits. |
| 503 | |
| 504 | ## Recovering from failure |
| 505 | |
| 506 | Start with `valley status <handle>`. It distinguishes work waiting for an integrator from a request |
| 507 | that the integrator has judged. Keep the command's full output when asking your administrator for |
| 508 | help. |
| 509 | |
| 510 | ### A stale or rejected request |
| 511 | |
| 512 | A `stale` result means the change conflicts with `main` or required evidence is missing or does not |
| 513 | transfer across `main` movement. Read the reason in `status`. Right after an approval that named |
| 514 | missing `nix` checks, `stale` for missing evidence is expected: the integrator keeps the request and |
| 515 | considers it again when evidence is published. If the base moved, |
| 516 | [revoke the outstanding request](#withdraw-or-revoke-an-approval), restack the ready change, then |
| 517 | ask for a fresh review and approval: |
| 518 | |
| 519 | ```sh |
| 520 | valley rebase kqxm |
| 521 | valley status kqxm |
| 522 | ``` |
| 523 | |
| 524 | Missing evidence can be published independently of approval. Rerun approval when you need it to |
| 525 | produce local evidence, with trusted signing settings, using `--build-here` for uncovered `nix` |
| 526 | checks, and observing the same-tree signer restriction. If approval reports that evidence from this |
| 527 | signer already exists for the tree, follow its recovery message; retrying the same head does not |
| 528 | replace that evidence. |
| 529 | |
| 530 | A `reject` result means the evidence is invalid, such as a signature or statement that does not |
| 531 | match what it claims. Keep the reason and ask the administrator to inspect the evidence and signing |
| 532 | configuration before trying again. See [checks and evidence](./concepts.md#checks-and-evidence). |
| 533 | |
| 534 | If `valley rebase` reports a conflict, it pushes nothing. For a single change, start from its remote |
| 535 | head on a clean local branch, run `git fetch origin` and `git rebase origin/main`, resolve the |
| 536 | reported files, and use `git add <resolved-files>` followed by `git rebase --continue`. Use |
| 537 | `git rebase --abort` to abandon that local attempt. Push with `--force-with-lease`, then run |
| 538 | `valley ready --change <full-change-id>`. For a stack, resolve each layer in order; do not publish |
| 539 | only the top while lower change records still name old heads. |
| 540 | |
| 541 | ### A refused push |
| 542 | |
| 543 | A refusal means the host did not accept that ref update. The message identifies the boundary: |
| 544 | |
| 545 | - **Protected ref:** push the work to a topic branch and use readiness and approval. A deployment |
| 546 | may seal `main` against every SSH principal. |
| 547 | - **Push hold:** ask the administrator to finish maintenance and remove the hold. Client settings |
| 548 | cannot bypass it. |
| 549 | - **Record ownership or non-fast-forward record update:** fetch again and use `valley ready`, |
| 550 | `unready`, or `withdraw` as the owner or a principal allowed to approve. Do not force a |
| 551 | hand-edited record over someone else's update. |
| 552 | - **A ref named like another ref:** push the branch or tag under a name that does not begin with |
| 553 | `refs/`. |
| 554 | - **Malformed or oversized record or knot:** read the named validation error. Use the CLI to make |
| 555 | valid records and `valley knot schema` to inspect the knot model. Reduce oversized content before |
| 556 | retrying. |
| 557 | |
| 558 | The [push rules](./architecture.md#what-a-push-may-write) and |
| 559 | [ref layout table](./reference.md#project-storage-ref-layout-and-bounds) explain each boundary. |
| 560 | |
| 561 | ### An uncertain landing |
| 562 | |
| 563 | An `uncertain` result means the client cannot prove whether the version was submitted. It can follow |
| 564 | a `failed` outcome or incomplete landing evidence. It can also mean the client had no signers to |
| 565 | verify the landing with. In that case the command says on stderr that a transfer statement could not |
| 566 | be verified, and why. Check that the host publishes its signers (step 3 of |
| 567 | [Client setup](#client-setup)). If it does not, ask the administrator for the signers file and the |
| 568 | integrator's signing name, set `VALLEY_KNOWN_SIGNERS` and `VALLEY_INTEGRATOR_SIGNER` to them, and |
| 569 | rerun `valley status <handle>`. |
| 570 | |
| 571 | If it remains uncertain, ask the administrator to inspect `main`, the outcome record, and the |
| 572 | integrator logs together. Do not assume that a consumed request means a successful landing. Resolve |
| 573 | the uncertainty before rebasing or approving again. The |
| 574 | [landing definitions](./concepts.md#a-change-ready-approve-submitted) describe the evidence needed |
| 575 | to resolve this state. |
| 576 | |
| 577 | ## Running a valley host |
| 578 | |
| 579 | A valley host serves repositories over SSH and runs the integrator on NixOS. This recipe creates an |
| 580 | instance repository named `instance` and a project named `demo`. It uses static keys and grants |
| 581 | first. All names, keys, checks, mirrors, and backup destinations are deployment choices; see |
| 582 | [NixOS host options](./reference.md#nixos-host-options) and |
| 583 | [CUE configuration schemas](./reference.md#cue-configuration-schemas) for the full option tables. |
| 584 | |
| 585 | ### Declare the host |
| 586 | |
| 587 | In your NixOS configuration directory, create `valley.cue`: |
| 588 | |
| 589 | ```cue |
| 590 | package valley |
| 591 | projects: { |
| 592 | instance: protection: {refs: ["refs/heads/main"], writers: []} |
| 593 | demo: protection: {refs: ["refs/heads/main"], writers: []} |
| 594 | } |
| 595 | ``` |
| 596 | |
| 597 | Both projects seal `main` against SSH pushes. The integrator writes locally on the host. |
| 598 | [`examples/hosts/protected.cue`](../examples/hosts/protected.cue) exercises four protection modes |
| 599 | for tests; it is not a production recipe. |
| 600 | |
| 601 | To publish a project on the web, place it in a group. Declare the group under a permanent |
| 602 | identifier, and set `group` on the project to that identifier: |
| 603 | |
| 604 | ```cue |
| 605 | groups: demos: name: "demos" |
| 606 | projects: demo: group: "demos" |
| 607 | ``` |
| 608 | |
| 609 | The web publisher exports only projects that belong to a group. The group's `name` is the first URL |
| 610 | segment and the project's web name is the second, giving `/demos/demo/…` here. A project's web name |
| 611 | defaults to its identifier unless the project sets `name`. When a group changes its `name`, keep the |
| 612 | old name in `aliases`. When a project changes its web name, keep the old name in `formerNames` so |
| 613 | existing links redirect (see [Groups and web URLs](./architecture.md#groups-and-web-urls)). |
| 614 | |
| 615 | Add the-valley as an input named `valley` to your NixOS flake, using your administrator's source |
| 616 | URL. Import `valley.nixosModules.valley-host` in the host's modules. In a module that receives that |
| 617 | input, start with: |
| 618 | |
| 619 | ```nix |
| 620 | { valley, ... }: { |
| 621 | imports = [ valley.nixosModules.valley-host ]; |
| 622 | services.openssh.enable = true; |
| 623 | services.valley = { |
| 624 | enable = true; |
| 625 | config = ./valley.cue; |
| 626 | authorizedKeys = [{ |
| 627 | principal = "operator"; |
| 628 | key = "ssh-ed25519 REPLACE_WITH_OPERATOR_PUBLIC_KEY"; |
| 629 | }]; |
| 630 | grants.approve = [ "operator" ]; |
| 631 | }; |
| 632 | } |
| 633 | ``` |
| 634 | |
| 635 | Pass the input through `specialArgs = { inherit valley; };` in `nixpkgs.lib.nixosSystem` if using |
| 636 | this module's argument. Replace the key with the public SSH key that the operator uses to push. The |
| 637 | `approve` grant is the grant that lets a principal approve. It is also accepted as `request`, and |
| 638 | `grants.request` declares the same grant as `grants.approve`. Keep administrative SSH access |
| 639 | separate from this git account. |
| 640 | |
| 641 | Apply your configuration using your normal NixOS deployment command. For a local flake with a host |
| 642 | named `valley-host`, run this on the host from that configuration directory: |
| 643 | |
| 644 | ```sh |
| 645 | sudo nixos-rebuild switch --flake .#valley-host |
| 646 | sudo systemctl start valley-init |
| 647 | sudo systemctl status valley-init --no-pager |
| 648 | ``` |
| 649 | |
| 650 | `valley-init` creates `/srv/git/instance.git` and `/srv/git/demo.git`, installs hooks, and creates |
| 651 | no initial commit. It publishes the project list once `instanceProject` is configured. Keep the |
| 652 | integrator disabled until both repositories have a `main`. |
| 653 | |
| 654 | ### Seed the initial source |
| 655 | |
| 656 | Create the initial source on the host in `/var/tmp/valley-seed`. Use an ordinary administrator |
| 657 | account with git's author name and email configured: |
| 658 | |
| 659 | ```sh |
| 660 | mkdir -p /var/tmp/valley-seed/instance/policy/instance |
| 661 | mkdir -p /var/tmp/valley-seed/demo/policy |
| 662 | cd /var/tmp/valley-seed/instance |
| 663 | git init --initial-branch=main |
| 664 | printf '# Instance\n' > README.md |
| 665 | cat > policy/instance/floor.cue <<'CUE' |
| 666 | package verification |
| 667 | floor: { |
| 668 | checks: readme: {runner: "command", command: "test -s README.md", validity: "1h"} |
| 669 | classes: source: {paths: {"**": true}, requires: {readme: true}} |
| 670 | unclassified: readme: true |
| 671 | } |
| 672 | CUE |
| 673 | git add README.md policy |
| 674 | git commit -m 'Seed instance policy' |
| 675 | cd /var/tmp/valley-seed/demo |
| 676 | git init --initial-branch=main |
| 677 | printf '# Demo\n' > README.md |
| 678 | printf 'git@valley.example:instance\n' > policy/valley |
| 679 | git add README.md policy |
| 680 | git commit -m 'Seed demo' |
| 681 | ``` |
| 682 | |
| 683 | Replace `valley.example` before committing. `policy/valley` names the instance repository whose |
| 684 | `policy/instance/` supplies this project's floor. The floor here requires only a nonempty README. It |
| 685 | is a smoke check to prove the approval path works. Choose checks that verify your actual projects |
| 686 | before admitting production work. A project's optional `policy/project/*.cue` can add requirements; |
| 687 | it cannot weaken the floor. See [policy](./architecture.md#policy). |
| 688 | |
| 689 | Seed these commits through a local host write. The following commands are for the empty repositories |
| 690 | just created: |
| 691 | |
| 692 | ```sh |
| 693 | sudo chown -R git:git /var/tmp/valley-seed |
| 694 | sudo -u git git -C /srv/git/instance.git fetch /var/tmp/valley-seed/instance main:refs/heads/main |
| 695 | sudo -u git git -C /srv/git/demo.git fetch /var/tmp/valley-seed/demo main:refs/heads/main |
| 696 | ``` |
| 697 | |
| 698 | Local writes bypass `pre-receive`, so this works while SSH writes to `main` are sealed. Keep these |
| 699 | seed directories free of private keys. Another bootstrap choice is to allow a temporary writer and |
| 700 | remove it after seeding; this recipe keeps the sealed configuration throughout. |
| 701 | |
| 702 | ### Provision signing and enable integration |
| 703 | |
| 704 | On the approver's machine, create its attestation key if it does not have one. From the-valley's |
| 705 | checkout, export its public verifier entry: |
| 706 | |
| 707 | ```sh |
| 708 | ssh-keygen -t ed25519 -N '' -f "$HOME/.ssh/valley-attest" |
| 709 | nix run .#attest -- key --key "$HOME/.ssh/valley-attest" --name operator > operator.signer |
| 710 | ``` |
| 711 | |
| 712 | Keep the private key on that machine. Copy only `operator.signer` to the administrator on the host. |
| 713 | On the host, create the integrator's separate key at a runtime path: |
| 714 | |
| 715 | ```sh |
| 716 | sudo install -d -m 0750 -o root -g git /var/lib/valley-secrets |
| 717 | sudo ssh-keygen -t ed25519 -N '' -f /var/lib/valley-secrets/integrator |
| 718 | sudo chgrp git /var/lib/valley-secrets/integrator |
| 719 | sudo chmod 0640 /var/lib/valley-secrets/integrator |
| 720 | ``` |
| 721 | |
| 722 | On the host, clone the-valley's source from the URL your administrator provides. From that checkout, |
| 723 | enter `nix shell .#attest`. Export the integrator entry and combine the two public entries: |
| 724 | |
| 725 | ```sh |
| 726 | sudo "$(command -v attest)" key --key /var/lib/valley-secrets/integrator --name integrator > integrator.signer |
| 727 | cat operator.signer integrator.signer > known-signers |
| 728 | sudo install -m 0644 known-signers /var/lib/valley-secrets/known-signers |
| 729 | ``` |
| 730 | |
| 731 | Add this to `services.valley` and apply the NixOS configuration again: |
| 732 | |
| 733 | ```nix |
| 734 | integrator = { |
| 735 | enable = true; |
| 736 | instanceProject = "instance"; |
| 737 | signingKeyFile = "/var/lib/valley-secrets/integrator"; |
| 738 | signingName = "integrator"; |
| 739 | knownSignersFile = "/var/lib/valley-secrets/known-signers"; |
| 740 | }; |
| 741 | ``` |
| 742 | |
| 743 | The integrator runs as `valley-integrator` in the `git` group. Its key and signers file must be |
| 744 | readable by that account. Private keys belong at runtime paths, never in the Nix store. |
| 745 | |
| 746 | The module requires a nonempty `authorizedKeys`, a signing key, a source for trusted signers, and |
| 747 | exactly one of `instanceProject` or `instancePolicy`. With `instanceProject`, it also requires the |
| 748 | instance's `main` to be protected. `instancePolicy` instead names a directory of floor CUE files on |
| 749 | a host that does not serve the instance repository. Set `signingName` explicitly to the name |
| 750 | published in the signers file. |
| 751 | |
| 752 | The host publishes the `known-signers` file and the integrator's signing name for clients, at |
| 753 | `refs/the-valley/signers` in the instance repository. `valley-signers` writes it at boot, on |
| 754 | activation, and whenever a file it publishes or the instance's `main` changes, so clients need no |
| 755 | signer settings. Follow [Authoring a change](#authoring-a-change) in a clone of `demo`, then approve |
| 756 | it as `operator`. Verify that `valley status <handle>` reports the landing. On the host, inspect: |
| 757 | |
| 758 | ```sh |
| 759 | sudo systemctl status valley-integrator@demo --no-pager |
| 760 | sudo journalctl -u valley-integrator@demo -n 50 --no-pager |
| 761 | sudo journalctl -u valley-signers -n 20 --no-pager |
| 762 | ``` |
| 763 | |
| 764 | ### Use a governed identity registry |
| 765 | |
| 766 | A deployment can maintain principals and keys in the instance source instead of listing all of them |
| 767 | in NixOS. Start with the [registry example](../examples/identity/registry/registry.cue) and |
| 768 | [schema](../schema/identity.cue). Write your own `identity/*.cue` in the instance repository, with |
| 769 | your public keys, signing names, boundaries, and grants. Do not deploy the example's keys. |
| 770 | |
| 771 | Include a registry governor, the operator's push and approval grants, and a signing entry whose |
| 772 | `signs` value matches the integrator's `signingName`. Land the registry through the static setup |
| 773 | above. Then set `services.valley.identity.enable = true` and remove `integrator.knownSignersFile` |
| 774 | from the NixOS configuration. Apply it and inspect the compilation: |
| 775 | |
| 776 | ```sh |
| 777 | sudo systemctl start valley-identity |
| 778 | sudo journalctl -u valley-identity -n 50 --no-pager |
| 779 | ``` |
| 780 | |
| 781 | It reads the integrated registry and writes `/var/lib/valley-identity/known-signers`, authorized |
| 782 | keys, and grants. Distribute that public signers file to clients. Keep a nonempty static |
| 783 | `authorizedKeys` list for bootstrap access. Static grants remain effective alongside compiled |
| 784 | grants; remove a static approval grant if the registry should be its sole source. See |
| 785 | [identity](./architecture.md#identity) for expiry and validation rules. |
| 786 | |
| 787 | ### Publish source mirrors |
| 788 | |
| 789 | A mirror lets readers fetch the source without accessing the primary host. Add a mirror URL to the |
| 790 | project's declaration and apply the host configuration: |
| 791 | |
| 792 | ```cue |
| 793 | projects: demo: mirrors: ["git@mirror.example:team/demo.git"] |
| 794 | ``` |
| 795 | |
| 796 | Provision the `git` Unix user's SSH private key and pinned `known_hosts` under `/srv/git/.ssh`. The |
| 797 | directory should be owned by `git` with mode `0700`; the private key should have mode `0600`. Verify |
| 798 | the mirror's host key through its administrator. The publisher runs as `git` and uses that account's |
| 799 | SSH configuration. |
| 800 | |
| 801 | For an existing mirror, inspect its refs before declaring it. Remove unwanted old refs explicitly; |
| 802 | the publisher does not clean up old topic branches or project storage. Start with an empty mirror |
| 803 | when possible. See [mirror cutover](./architecture.md#after-a-push-events-and-mirrors). |
| 804 | |
| 805 | Applying the configuration pushes the project's `main` and tags to each declared mirror, and every |
| 806 | later move pushes them again. Inspect the publisher: |
| 807 | |
| 808 | ```sh |
| 809 | sudo journalctl -u valley-publish@demo -n 50 --no-pager |
| 810 | git ls-remote git@mirror.example:team/demo.git |
| 811 | ``` |
| 812 | |
| 813 | Its `main` should match the primary. A failed push is retried after a growing delay. Its log line |
| 814 | ends with the reason the mirror or the connection gave, such as a branch rule that refuses the push |
| 815 | or a key the mirror does not accept. An observer reads the same lines with |
| 816 | `valley telemetry read --source mirrors --logs`. The reason is the remote's own words, with any word |
| 817 | that looks like an address or carries a parameter removed. A secret printed as a plain word still |
| 818 | passes through: the reason is for diagnosis, and whoever can read the host's journal or its |
| 819 | telemetry can read it. The publisher sends `main` and tags, not the plan graph or other project |
| 820 | storage. A mirror is not a backup of the valley. |
| 821 | |
| 822 | ### Run a service when main moves |
| 823 | |
| 824 | A host can run a service of its own when a project's `main` moves, such as one that deploys the |
| 825 | landed commit (`deployment choice`). Declare the service as usual, and bind it to the project: |
| 826 | |
| 827 | ```nix |
| 828 | systemd.services.converge = { |
| 829 | serviceConfig = { Type = "oneshot"; TimeoutStartSec = "30min"; }; |
| 830 | script = '' |
| 831 | echo "deploying $VALLEY_COMMIT from $VALLEY_REPOSITORY" |
| 832 | ''; |
| 833 | }; |
| 834 | services.valley.onMain.deploy = { project = "demo"; unit = "converge.service"; }; |
| 835 | ``` |
| 836 | |
| 837 | When `main` names a new commit, the host starts the service with `VALLEY_REPOSITORY` and |
| 838 | `VALLEY_COMMIT` in its environment. Moves made while it runs become one run at the newest commit, |
| 839 | once it has stopped. The service also runs again for the current commit whenever the host boots or |
| 840 | the bridge restarts, so make it safe to repeat. Make it a oneshot without `RemainAfterExit`, and |
| 841 | give it a timeout, because the next run waits for it. Leave out `Restart=`, which evaluation |
| 842 | refuses. |
| 843 | |
| 844 | Nothing retries a failed run automatically; it stays failed until `main` moves again. Read why, and |
| 845 | retry it by hand: |
| 846 | |
| 847 | ```sh |
| 848 | sudo journalctl -u valley-on-main-deploy -u converge -n 50 --no-pager |
| 849 | sudo systemctl start converge |
| 850 | ``` |
| 851 | |
| 852 | A start by hand runs the commit the host last requested. An observer reads the units with |
| 853 | `valley telemetry read --source on-main --logs`. |
| 854 | |
| 855 | The service's start limit applies, by default five starts in ten seconds. When it refuses a start, |
| 856 | the binding's path unit stops too, and later commits wait. Raise the limit (`startLimitBurst`) for a |
| 857 | project that lands faster, and resume with: |
| 858 | |
| 859 | ```sh |
| 860 | sudo systemctl reset-failed converge |
| 861 | sudo systemctl restart valley-on-main-deploy.path |
| 862 | ``` |
| 863 | |
| 864 | After replacing the repository, as a restore does, restart the bridge so that it follows the new |
| 865 | one: `sudo systemctl restart valley-on-main-deploy`. |
| 866 | |
| 867 | ### Back up and test a restore |
| 868 | |
| 869 | Backups preserve the whole data directory. Add an offsite policy to `valley.cue`: |
| 870 | |
| 871 | ```cue |
| 872 | backup: { |
| 873 | target: "restic-sftp" |
| 874 | cadence: "nightly" |
| 875 | retention: {daily: 7, weekly: 4, monthly: 6} |
| 876 | } |
| 877 | ``` |
| 878 | |
| 879 | Provision four files outside the Nix store: the restic repository URL, its encryption password, the |
| 880 | SFTP private key, and pinned SSH host keys. Keep a recoverable copy of the password away from this |
| 881 | host. Point the module at those runtime files: |
| 882 | |
| 883 | ```nix |
| 884 | backup = { |
| 885 | repositoryFile = "/var/lib/valley-secrets/restic-repository"; |
| 886 | passwordFile = "/var/lib/valley-secrets/restic-password"; |
| 887 | sshKeyFile = "/var/lib/valley-secrets/restic-ssh"; |
| 888 | knownHostsFile = "/var/lib/valley-secrets/restic-known-hosts"; |
| 889 | }; |
| 890 | ``` |
| 891 | |
| 892 | After applying the configuration, take a backup and inspect its result: |
| 893 | |
| 894 | ```sh |
| 895 | sudo systemctl start restic-backups-valley |
| 896 | sudo journalctl -u restic-backups-valley -n 50 --no-pager |
| 897 | ``` |
| 898 | |
| 899 | The service runs as root and snapshots `services.valley.dataDir`, `/srv/git` by default. Test a |
| 900 | restore into a separate empty directory. With `restic` available, run these in a root shell: |
| 901 | |
| 902 | ```sh |
| 903 | export RESTIC_REPOSITORY_FILE=/var/lib/valley-secrets/restic-repository |
| 904 | export RESTIC_PASSWORD_FILE=/var/lib/valley-secrets/restic-password |
| 905 | restic -o 'sftp.args=-i /var/lib/valley-secrets/restic-ssh -o UserKnownHostsFile=/var/lib/valley-secrets/restic-known-hosts -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes' snapshots |
| 906 | restic -o 'sftp.args=-i /var/lib/valley-secrets/restic-ssh -o UserKnownHostsFile=/var/lib/valley-secrets/restic-known-hosts -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes' restore latest --target /var/tmp/valley-restore |
| 907 | git -c safe.directory=/var/tmp/valley-restore/srv/git/demo.git -C /var/tmp/valley-restore/srv/git/demo.git fsck --full |
| 908 | git -c safe.directory=/var/tmp/valley-restore/srv/git/instance.git -C /var/tmp/valley-restore/srv/git/instance.git fsck --full |
| 909 | ``` |
| 910 | |
| 911 | Expect a snapshot, a completed restore, and no corrupt or missing objects. Git may report dangling |
| 912 | objects; those alone do not indicate corruption. Inspect the restored `main` and `refs/the-valley/*` |
| 913 | as well. This verifies the restored repository, not a transaction across every ref written while the |
| 914 | backup ran. |
| 915 | |
| 916 | ### Hold pushes for maintenance |
| 917 | |
| 918 | To refuse incoming pushes across every project, create the hold on the host: |
| 919 | |
| 920 | ```sh |
| 921 | sudo touch /srv/git/.valley-hold |
| 922 | ``` |
| 923 | |
| 924 | Remove it after maintenance with `sudo rm /srv/git/.valley-hold`. Use your configured `dataDir` if |
| 925 | it differs. The hold stops SSH pushes; stop the relevant integrator services separately if |
| 926 | maintenance also requires local integration writes to stop. |
| 927 | |
| 928 | ### Serve telemetry from the host |
| 929 | |
| 930 | A host serves telemetry once the administrator enables the collector and names who may read and who |
| 931 | may report (`deployment choice`): |
| 932 | |
| 933 | ```nix |
| 934 | services.valley.telemetry = { |
| 935 | enable = true; |
| 936 | observers = [ "operator" ]; # read every source on the host |
| 937 | reporters = [ "alice" ]; # send records about their own approvals and checks |
| 938 | }; |
| 939 | ``` |
| 940 | |
| 941 | A principal is named by its key's tag, as for a push. `observe` is host-wide: the shared units' logs |
| 942 | span every project, so give it only to principals that may see every project's activity. `report` |
| 943 | grants no reading. A workstation that should read its own reports back needs `observe` too. |
| 944 | |
| 945 | A unit of the host's own, such as the service that converges or deploys it, can be a source too: |
| 946 | |
| 947 | ```nix |
| 948 | services.valley.telemetry.localSources = [ |
| 949 | { name = "converge"; description = "the service that converges this host"; units = [ "converge.service" ]; } |
| 950 | ]; |
| 951 | ``` |
| 952 | |
| 953 | `valley telemetry sources` then reports it with the state of its units, and |
| 954 | `read --source converge --logs` shows what they printed, as for the valley's own services. A name |
| 955 | that another source already uses is refused when the host is evaluated. |
| 956 | |
| 957 | A component on another machine, such as a web receiver, can report with a principal of its own: |
| 958 | |
| 959 | ```nix |
| 960 | services.valley.telemetry.reporters = [ "receiver" ]; |
| 961 | services.valley.telemetry.remoteSources = [ |
| 962 | { name = "remote-receiver"; description = "the web receiver at example.org"; principal = "receiver"; } |
| 963 | ]; |
| 964 | ``` |
| 965 | |
| 966 | The source reads as `unavailable` until that principal reports and as `stale` after an hour of |
| 967 | silence. No component of the-valley reports this way by itself yet; see |
| 968 | [Not deployed or not wired yet](architecture.md#not-deployed-or-not-wired-yet). |
| 969 | |
| 970 | The collector reads the journal, so how far back unit lifecycle and output reach is the host's |
| 971 | journal retention, which each `source` line reports as `journal_since`. |
| 972 | |
| 973 | ### Find refs named like other refs |
| 974 | |
| 975 | The push hook refuses to create or update a ref named like another ref: `refs/`, `refs/heads/`, |
| 976 | `refs/tags/` or `refs/remotes/` followed by a full ref name. When the ref it is named for is |
| 977 | missing, git reads, fetches and pushes to such a ref in its place. A host may hold some already, |
| 978 | made before the hook refused them. List them once, in every repository the host serves: |
| 979 | |
| 980 | ```sh |
| 981 | for repo in /srv/git/*.git; do |
| 982 | sudo -u git git -C "$repo" for-each-ref --format="$repo %(refname)" \ |
| 983 | refs/refs/ refs/heads/refs/ refs/tags/refs/ refs/remotes/refs/ |
| 984 | done |
| 985 | ``` |
| 986 | |
| 987 | Each line names a repository and a ref. Once any work on a ref has been pushed under another name, |
| 988 | delete the ref on the host: |
| 989 | |
| 990 | ```sh |
| 991 | sudo -u git git -C /srv/git/demo.git update-ref -d refs/heads/refs/heads/main |
| 992 | ``` |
| 993 | |
| 994 | Use your configured `dataDir` if it differs. |
| 995 | |
| 996 | ### Run the web edge |
| 997 | |
| 998 | The web edge is a read-only web server for the valley's projects. The publisher on the valley host |
| 999 | pushes signed exports to the edge over HTTP, and the edge never connects back to the valley host. A |
| 1000 | project reaches the edge when a reader's grant and the project's `policy/read` both allow that |
| 1001 | reader — `anyone` or a named principal — to read it there. The edge serves each project only to the |
| 1002 | readers its authorization names, and readers can sign in at the edge with read links. On the edge, |
| 1003 | `valley-web-receive` receives uploads into a state directory and `valley-web` serves them. They run |
| 1004 | as two processes under two Unix users over that shared state directory (see |
| 1005 | [The receiver](./architecture.md#the-receiver)). |
| 1006 | |
| 1007 | Generate a shared bearer token and install the same file on both hosts outside the Nix store, |
| 1008 | readable by root alone: |
| 1009 | |
| 1010 | ```sh |
| 1011 | head -c 32 /dev/urandom | base64 | sudo install -m 0400 /dev/stdin /run/keys/valley-web-receiver-token |
| 1012 | ``` |
| 1013 | |
| 1014 | On the valley host, enable the publisher with the receiver URL and token file: |
| 1015 | |
| 1016 | ```nix |
| 1017 | imports = [ the-valley.nixosModules.default the-valley.nixosModules.web-publisher ]; |
| 1018 | services.valley.webPublisher = { |
| 1019 | enable = true; |
| 1020 | destination = "example.org"; |
| 1021 | receiver = "https://example.org"; |
| 1022 | receiverTokenFile = "/run/keys/valley-web-receiver-token"; |
| 1023 | allowedAddresses = [ "192.0.2.10" ]; |
| 1024 | }; |
| 1025 | ``` |
| 1026 | |
| 1027 | Set `allowedAddresses` to the receiver's IP addresses. The unit allows connections only to addresses |
| 1028 | on that list, permits any port on a listed address, and checks only the destination IP address. When |
| 1029 | the receiver changes to a new address, passes fail until `allowedAddresses` includes it. The |
| 1030 | publisher connects to the receiver directly and ignores `HTTP_PROXY` and `HTTPS_PROXY`. |
| 1031 | |
| 1032 | On NixOS, name lookups go through the C library to `nscd` (`services.nscd.enable`, enabled by |
| 1033 | default), which queries DNS outside the unit. If `nscd` is disabled, add the resolver address from |
| 1034 | `/etc/resolv.conf` to `allowedAddresses` as well. |
| 1035 | |
| 1036 | Before each pass, `valley-web-publish-egress-check` verifies that the IP filter is active by sending |
| 1037 | a UDP datagram to `198.51.100.1` and starting the pass only when the filter blocks it. Leave |
| 1038 | `198.51.100.1` out of `allowedAddresses`, and ensure the host has a route to it, such as a default |
| 1039 | route. If the check stops the pass, `journalctl -u valley-web-publish` logs the reason from |
| 1040 | `valley-web-publish-egress-check`. |
| 1041 | |
| 1042 | Run the publisher once to generate the export signing key and read its verifier line: |
| 1043 | |
| 1044 | ```sh |
| 1045 | sudo systemctl start valley-web-publish |
| 1046 | sudo cat /var/lib/valley-web-publish/verifier |
| 1047 | ``` |
| 1048 | |
| 1049 | Until the receiver pins that verifier line, it refuses every upload with `bad-signature` and the |
| 1050 | publisher pass fails. |
| 1051 | |
| 1052 | On an edge host running NixOS, enable `services.valley.webReceiver`. Configure `listen` on the |
| 1053 | address the publisher reaches and `webListen` behind the reverse proxy that serves the edge's public |
| 1054 | domain: |
| 1055 | |
| 1056 | ```nix |
| 1057 | imports = [ the-valley.nixosModules.web-receiver ]; |
| 1058 | services.valley.webReceiver = { |
| 1059 | enable = true; |
| 1060 | instance = "valley-host"; |
| 1061 | destination = "example.org"; |
| 1062 | verifiers = [ "valley-host/web-export+1a2b3c4d+AQ..." ]; |
| 1063 | tokenFile = "/run/keys/valley-web-receiver-token"; |
| 1064 | listen = "192.0.2.10:8081"; |
| 1065 | webListen = "127.0.0.1:8080"; |
| 1066 | origin = "https://example.org"; |
| 1067 | }; |
| 1068 | ``` |
| 1069 | |
| 1070 | Set `origin` to the public HTTPS origin that browsers send for the edge: `https://` and a lowercase |
| 1071 | host, plus a port when the port is not `443`. When `origin` is set, readers can sign in with read |
| 1072 | links (see [Issue and revoke read links](#issue-and-revoke-read-links)), and `valley-web` stores |
| 1073 | their sessions in `/var/lib/valley-web/browser`. The module creates that directory with owner |
| 1074 | `valley-web` and mode `0700`, and `valley-web` cannot write anywhere else. When `origin` is unset, |
| 1075 | `valley-web` serves every request as `anyone`. Serve the origin over HTTPS, because the session |
| 1076 | cookie has the `Secure` attribute and browsers store it only over HTTPS. |
| 1077 | |
| 1078 | On an edge host that does not run NixOS, build and load the container image from a checkout of |
| 1079 | the-valley: |
| 1080 | |
| 1081 | ```sh |
| 1082 | nix build .#valley-web-image |
| 1083 | docker load < result |
| 1084 | ``` |
| 1085 | |
| 1086 | `docker load` prints the image name and tag. Install the verifier line and a copy of the token where |
| 1087 | the receiver's user (uid 990) can read them, then run two containers sharing one volume — writable |
| 1088 | in `valley-web-receive` and read-only in `valley-web`: |
| 1089 | |
| 1090 | ```sh |
| 1091 | sudo install -d -m 0750 -o 990 -g 990 /etc/valley-web |
| 1092 | sudo install -m 0400 -o 990 -g 990 /run/keys/valley-web-receiver-token /etc/valley-web/token |
| 1093 | echo 'valley-host/web-export+1a2b3c4d+AQ...' | sudo install -m 0444 -o 990 /dev/stdin /etc/valley-web/verifiers |
| 1094 | |
| 1095 | docker run -d --name valley-web-receive --user valley-web-receive \ |
| 1096 | --memory 2g --memory-swap 2g \ |
| 1097 | -v valley-web:/var/lib/valley-web -v /etc/valley-web:/etc/valley-web:ro \ |
| 1098 | -p 192.0.2.10:8081:8081 valley-web:<tag> \ |
| 1099 | valley-web-receive --state /var/lib/valley-web/store --listen :8081 \ |
| 1100 | --instance valley-host --destination example.org \ |
| 1101 | --verifiers /etc/valley-web/verifiers --token-file /etc/valley-web/token |
| 1102 | |
| 1103 | docker run -d --name valley-web --user valley-web \ |
| 1104 | --memory 1g --memory-swap 1g --ulimit core=0 \ |
| 1105 | -v valley-web:/var/lib/valley-web:ro -v valley-web-browser:/var/lib/valley-web/browser \ |
| 1106 | -p 127.0.0.1:8080:8080 valley-web:<tag> \ |
| 1107 | valley-web --state /var/lib/valley-web/store --listen :8080 --origin https://example.org |
| 1108 | ``` |
| 1109 | |
| 1110 | A new `valley-web` volume inherits the owner and permissions of `/var/lib/valley-web` from the |
| 1111 | image: the receiver's user with mode `0750`. `valley-web` reads that volume through the shared |
| 1112 | group. The second volume, `valley-web-browser`, holds the browser state and is the only directory |
| 1113 | `valley-web` writes. A new volume mounted at `/var/lib/valley-web/browser` inherits its owner and |
| 1114 | permissions from the image: `valley-web`'s user (uid 991, gid 990) with mode `0700`. The receiver's |
| 1115 | container does not mount `valley-web-browser`. `valley-web` holds link secrets and session tokens in |
| 1116 | memory; it marks its own process non-dumpable, and `--ulimit core=0` disables core dumps for the |
| 1117 | container as well. If an existing `valley-web` volume lacks a `browser/` directory for the mount |
| 1118 | point, create it once on the host before starting `valley-web`: |
| 1119 | |
| 1120 | ```sh |
| 1121 | sudo install -d -m 0700 -o 991 -g 990 "$(docker volume inspect -f '{{.Mountpoint}}' valley-web)/browser" |
| 1122 | ``` |
| 1123 | |
| 1124 | A bind mount used in place of either volume needs the same owner and mode. Omit |
| 1125 | `-v valley-web-browser:…` and `--origin` to serve `anyone` alone. Both containers take the store |
| 1126 | descriptor `/var/lib/valley-web/store`, which the receiver creates on its first start. When |
| 1127 | upgrading from a release where `--state` was a directory, stop the old receiver, start the new one, |
| 1128 | and upgrade the host after the edge (see |
| 1129 | [Upgrading the edge and the host](./reference.md#upgrading-the-edge-and-the-host)). Then delete the |
| 1130 | first layout's state from the volume by hand: `active`, `high-water`, `exports/`, `staging/`, |
| 1131 | `trash/` and `lock`, beside the descriptor. Leaving them is harmless, because the first layout held |
| 1132 | public projects only. |
| 1133 | |
| 1134 | Give each container its own memory limit. When a container reaches `--memory`, the kernel reclaims |
| 1135 | memory or kills a process inside that container alone. Setting `--memory-swap` equal to `--memory` |
| 1136 | disables swap for the container, matching the NixOS module's units. A limit keeps a spike in one |
| 1137 | container from taking the other's memory or the host's only when the host has room for both limits |
| 1138 | and for its own work. So keep the sum of both limits below the host's physical memory, with explicit |
| 1139 | headroom left for the host's own work. The `2g` and `1g` limits above match the module's defaults |
| 1140 | for `receiverMemoryMax` and `webMemoryMax`; sizing them for the edge's uploads and readers is a |
| 1141 | deployment choice. |
| 1142 | |
| 1143 | The receiver caps the state directory at `--max-storage` (8 GiB by default). Because `--max-storage` |
| 1144 | is best effort, place the state directory on a fixed-size filesystem or under a disk quota slightly |
| 1145 | larger than `--max-storage` (see [Bounds](./architecture.md#bounds)). For containers, apply that |
| 1146 | bound to the filesystem backing the volume. On NixOS, mount a bounded filesystem at the receiver's |
| 1147 | state directory (`/var/lib/valley-web` by default). |
| 1148 | |
| 1149 | Because every upload request carries the token, reach the receiver over HTTPS, through a reverse |
| 1150 | proxy that terminates TLS, or over a private network. On the next pass, the publisher prints |
| 1151 | `the receiver stored authorization <n>`, then `the receiver activated sequence <n>`, and |
| 1152 | `valley-web` serves the export. |
| 1153 | |
| 1154 | To take a project off the web at once, withdraw every reader's grant for it, or remove every reader |
| 1155 | from its `policy/read`, and start a pass: `sudo systemctl start valley-web-publish`. A project stays |
| 1156 | on the edge while any reader may still read it, so removing one reader keeps the project for the |
| 1157 | others. The pass sends its authorization before doing any content work, and the edge stops serving |
| 1158 | the project at the next request, even if the content work stalls or fails. Running |
| 1159 | `valley-web-publish --policy-only` with the unit's other flags sends only the authorization. |
| 1160 | |
| 1161 | ### Issue and revoke read links |
| 1162 | |
| 1163 | A read link lets one person read, at the edge, what one registry principal may read there. The |
| 1164 | principal needs an edge-read grant in the registry and a project whose `policy/read` names it. A |
| 1165 | reader who signs nothing may hold no keys, as long as every grant it holds is an edge read. Run |
| 1166 | these commands as root on the valley host: |
| 1167 | |
| 1168 | ```bash |
| 1169 | valley-web-link issue --principal alice --note laptop |
| 1170 | ``` |
| 1171 | |
| 1172 | The command refuses a principal who may read no project at the destination. Otherwise, it prints the |
| 1173 | link once, such as `https://example.org/-/redeem#lk-0123456789abcdef.<secret>`. Send it to its |
| 1174 | holder over a private channel. The host keeps no copy of the secret. |
| 1175 | |
| 1176 | After the next pass delivers the link to the edge, the holder opens it in a browser and clicks |
| 1177 | **Continue as reader**. That redeems the link once and starts a session in the browser. To switch to |
| 1178 | a new link in a browser that is already signed in, open the new link and click **Sign out and |
| 1179 | continue with this link**. Clicking **Sign out** in the navigation ends the session, and signing in |
| 1180 | again requires a new link. If the page cannot tell whether the server used the link, click the |
| 1181 | button again to retry. If the earlier attempt started a session, the retry continues to `/`; if the |
| 1182 | server reports that the link cannot be used, issue a new link. |
| 1183 | |
| 1184 | After signing in, the browser goes to `/`. A reader who may read more than one project lands on the |
| 1185 | projects page, `/-/projects`, which lists each project they may read under its group. Each entry |
| 1186 | links to the project's source and to its knots. A reader who may read exactly one project lands on |
| 1187 | that project's source instead. Every page of a project has a header that names it as |
| 1188 | `<group>/<project>`, with two tabs: **source** and **knots**. The **projects** link at the top of |
| 1189 | every project page and every listing page returns to the list. The list's **all knots** link shows |
| 1190 | the knots of every project the reader may read (see |
| 1191 | [Web server (`valley-web`)](./reference.md#web-server-valley-web) for the routes). |
| 1192 | |
| 1193 | ```bash |
| 1194 | valley-web-link list |
| 1195 | valley-web-link revoke lk-0123456789abcdef |
| 1196 | valley-web-link revoke --principal alice |
| 1197 | valley-web-link revoke --all |
| 1198 | ``` |
| 1199 | |
| 1200 | After every issue or revoke, the command starts a policy pass and reports every link whose delivery |
| 1201 | is still `pending`. If a link is pending after that pass, it starts the pass once more. `enforced` |
| 1202 | means the receiver acknowledged an authorization that reflects the link's current state. If a link |
| 1203 | is still `pending`, the command exits 1. A revoked link still works at the edge until a pass |
| 1204 | delivers the revocation. Check `journalctl -u valley-web-publish-policy`, then run the same command |
| 1205 | again: a repeated `revoke` retries the delivery. |
| 1206 | |
| 1207 | A command that changes links waits for a policy pass that is reading the links and signing, for up |
| 1208 | to a minute, and says so while it waits. If the wait runs out, the command exits 1 having changed |
| 1209 | nothing. Run it again. |
| 1210 | |
| 1211 | Restoring the valley host from a backup restores the read links as they were at the backup. A link |
| 1212 | revoked after the backup works again once the next pass delivers it. To cut off every link after a |
| 1213 | restore, revoke them all, then issue new links to the people who should keep access: |
| 1214 | |
| 1215 | ```bash |
| 1216 | valley-web-link revoke --all |
| 1217 | valley-web-link issue --principal alice --note laptop |
| 1218 | ``` |
| 1219 | |
| 1220 | `valley-web` creates `browser/state` only when the stored authorization has no link bindings. Any |
| 1221 | link issued before `browser/state` exists cannot be redeemed. Follow these steps when enabling |
| 1222 | reader sign-in for the first time, or after the edge loses `browser/state` or its whole state |
| 1223 | directory: |
| 1224 | |
| 1225 | 1. Run `valley-web-link revoke --all` to revoke every link and deliver an authorization with no |
| 1226 | bindings. |
| 1227 | 2. Confirm that `browser/state` exists in the edge's state directory. `valley-web` creates it when |
| 1228 | it starts or on the first request after that authorization arrives. |
| 1229 | 3. Issue new links. |
| 1230 | |
| 1231 | If `valley-web` logs that the browser state is unavailable, it serves requests without a session |
| 1232 | cookie as `anyone` and answers `503` to requests that carry the session cookie. `valley-web` never |
| 1233 | overwrites an unreadable `browser/state`. To recover, run `valley-web-link revoke --all`, stop |
| 1234 | `valley-web`, remove `browser/state`, start `valley-web` again, and issue new links. |
| 1235 | |
| 1236 | Revoked links stay in the credential file until you prune them: |
| 1237 | |
| 1238 | ```bash |
| 1239 | valley-web-link prune |
| 1240 | ``` |
| 1241 | |
| 1242 | `prune` removes every revoked link whose revocation is `enforced`, and keeps those still `pending`. |
| 1243 | It starts no policy pass, since the edge already refuses every link it removes. The file holds at |
| 1244 | most 1 MiB. `issue` refuses once the file would come within 64 KiB of that, and says to prune. |
| 1245 | `revoke` is never refused for the file's size. |
| 1246 | |
| 1247 | To pause a principal's access without revoking links, set or shorten its `expires` in the registry. |
| 1248 | Its links stop working after the next policy pass past that day, and extending the date restores |
| 1249 | them. |
| 1250 | |
| 1251 | ## Contributing to the-valley |
| 1252 | |
| 1253 | Contributors work in a checkout of this repository. Read [AGENTS.md](../AGENTS.md) before editing. |
| 1254 | You can enter the default package's build environment: |
| 1255 | |
| 1256 | ```sh |
| 1257 | nix develop |
| 1258 | ``` |
| 1259 | |
| 1260 | This flake defines no dedicated development shell. `nix develop` does not supply the full toolchain. |
| 1261 | For the CLI and Go work, use an explicit tool shell from the repository root: |
| 1262 | |
| 1263 | ```sh |
| 1264 | nix shell .#valley .#attest --inputs-from . nixpkgs#go nixpkgs#cue |
| 1265 | ``` |
| 1266 | |
| 1267 | Each Go component has its own module. Run fast tests from the component you changed, for example: |
| 1268 | |
| 1269 | ```sh |
| 1270 | (cd status && go test ./...) |
| 1271 | ``` |
| 1272 | |
| 1273 | There is no root Go module. To test every Go module from the repository root: |
| 1274 | |
| 1275 | ```sh |
| 1276 | for module in attest change composed delta identity integrator knot note rebase restack selfupdate sigverify status valleyhook; do |
| 1277 | (cd "$module" && go test ./...) || exit 1 |
| 1278 | done |
| 1279 | ``` |
| 1280 | |
| 1281 | In Nix, building a Go package does not run its unit tests. Those tests run only in the module's |
| 1282 | `*-unit` check, such as `valleyhook-unit` for `valleyhook/` or `valley-go-unit` for `status/`: |
| 1283 | |
| 1284 | ```sh |
| 1285 | nix build --no-link .#checks.x86_64-linux.valleyhook-unit -L |
| 1286 | ``` |
| 1287 | |
| 1288 | Run a single Nix check by name. For documentation, format first, then check formatting, links, and |
| 1289 | the style rules, then the policy that selects checks: |
| 1290 | |
| 1291 | ```sh |
| 1292 | nix run .#fmt |
| 1293 | nix build --no-link .#checks.x86_64-linux.prose-format -L |
| 1294 | nix build --no-link .#checks.x86_64-linux.own-policy -L |
| 1295 | ``` |
| 1296 | |
| 1297 | Stage new Markdown files before formatting so the formatter sees them. Review the diff afterward. |
| 1298 | Use [nix/checks](../nix/checks/) to find the integration checks for the component you changed. Run |
| 1299 | them one at a time; VM checks need the virtualization facilities their definitions specify. The full |
| 1300 | flake suite is invoked with `nix flake check` when your task permits it and the machine can run all |
| 1301 | its checks. |
| 1302 | |
| 1303 | Each check is given only the files it reads. [nix/checks.nix](../nix/checks.nix) and |
| 1304 | [nix/packages.nix](../nix/packages.nix) narrow each source to those files with `lib.fileset`. An |
| 1305 | edit to any other file leaves the check's derivation unchanged, so the check's evidence transfers to |
| 1306 | the edited tree. When a check starts to read a new file, give the check that file. The sandbox fails |
| 1307 | a check that reads a file it was not given. |
| 1308 | |
| 1309 | Editing a Go test changes only that module's `*-unit` check, not the other checks that use the |
| 1310 | package. A Go package's source leaves out test files, and its `*-unit` check adds them back. |
| 1311 | |
| 1312 | The NixOS host module uses three of the flake's programs: the integrator, the identity compiler, and |
| 1313 | `valleyhook`. Four checks test what the module renders without running those programs: |
| 1314 | `module-eval`, `mirror-e2e`, `bus-e2e`, and `init-e2e`. Those checks render the module with stand-in |
| 1315 | scripts in place of the three programs ([nix/checks/hosts.nix](../nix/checks/hosts.nix)), so editing |
| 1316 | one of the programs leaves those four checks unchanged. Checks that run one of the programs use the |
| 1317 | real package. |
| 1318 | |
| 1319 | To see which checks an edit gives a new derivation, run the measurement script on a commit: |
| 1320 | |
| 1321 | ```sh |
| 1322 | nix/tools/drv-churn.sh --expect nix/tools/drv-churn.expected |
| 1323 | ``` |
| 1324 | |
| 1325 | It applies a fixed list of representative edits to the commit's tree, one at a time, and evaluates |
| 1326 | every check's derivation after each. The first edit, `commit only`, commits the same tree twice and |
| 1327 | evaluates each commit. Only the checks that read the commit may change: `valley-cli`, |
| 1328 | `valley-self-update` and `valley-darwin-eval`. With `--expect`, it fails if any edit changes other |
| 1329 | checks than the recorded table says. When a change means to alter the table, write the new one with |
| 1330 | `--write`. To measure only some edits, name each with `--edit`: |
| 1331 | |
| 1332 | ```sh |
| 1333 | nix/tools/drv-churn.sh --edit 'commit only' --edit 'help text' --expect nix/tools/drv-churn.expected |
| 1334 | ``` |
| 1335 | |
| 1336 | Every check is still evaluated, and `--expect` and `--write` compare or replace only the rows of the |
| 1337 | edits named. With `--history origin/main~20..origin/main` instead, it replays the paths each of |
| 1338 | those commits touched. Run `nix/tools/drv-churn.sh --help` for every option. |
| 1339 | |
| 1340 | The [architecture](./architecture.md) explains component invariants and the checks that cover them. |
| 1341 | The [reference](./reference.md) documents CLI flags, ref bounds, wire formats, JSON outputs, and |
| 1342 | [schema](../schema/) definitions alongside the [concept glossary](./concepts.md#glossary). |