gunk-dev/the-valley

guide.md

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