gunk-dev/the-valley

guide.md

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