gunk-dev/the-valley

guide.md

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