gunk-dev/the-valley

guide.md

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