gunk-dev/the-valley

guide.md

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