gunk-dev/the-valley

guide.md

source9d44ba98f6b9main's published tip history
33.2 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. When a check has to run locally, the host must trust that
80 signing key. Your SSH principal must also be allowed to approve. These are separate parts of
81 [identity](./concepts.md#principals-and-grants); see
82 [Environment variables and configuration](./reference.md#environment-variables-and-configuration)
83 for every client setting.
84
85To install updates into your user Nix profile, name the-valley's source repository:
86
87```sh
88valley self-update --repo git@valley.example:the-valley --branch main
89```
90
91It builds the selected commit, tests the new client, and installs it. For repeated use, save the
92repository with `git config --global valley.selfUpdate.repo git@valley.example:the-valley`, then run
93`valley self-update`. Without a configured repository, self-update is off. Run
94`valley self-update --help` for rollback and pinning.
95
96The installed package includes Bash and Zsh completions. For a shell using the checkout directly,
97source `completions/valley.bash` in Bash. In Zsh, add the checkout's `completions` directory to
98`fpath` before running `autoload -Uz compinit; compinit`.
99
100## Authoring a change
101
102A change starts with a local commit. This example uses a new git branch called `greeting` to carry
103it. Run it in a project with an initial `main` and verification policy already set up.
104
105### Create and ready the first version
106
107```sh
108git fetch origin
109git switch -c greeting origin/main
110printf 'Hello from the valley.\n' > greeting.txt
111git add greeting.txt
112git commit -m 'Add a greeting'
113valley checks
114```
115
116`valley checks` lists what this diff requires. It does not run the checks. Run the commands named by
117your project's policy before asking for review. For a Nix check named `prose-format` in this
118repository, for example:
119
120```sh
121nix build --no-link .#checks.x86_64-linux.prose-format -L
122```
123
124For this new, unpushed commit, stamp a stable Change ID and publish the first version:
125
126```sh
127valley ready --stamp
128valley status greeting
129```
130
131`ready` prints a handle and version, such as `demo kqxm v1 ready`. Use the handle it actually prints
132in later commands. The handle identifies the change even when its commit changes. `status` reports
133readiness, any request, and the latest integration result. To see the required checks alongside
134pending changes, run `valley pending --checks`.
135
136If the commit already carries a `Change-Id` trailer or a jj `change-id` header, push it first and
137run `valley ready` without `--stamp`:
138
139```sh
140git push -u origin HEAD
141valley ready
142```
143
144Without `--stamp`, `ready` uses the pushed tip by default. Keep the full Change ID when recording a
145new revision. The [change concept](./concepts.md#a-change-ready-approve-submitted) explains how
146headers, trailers, and `--change <id>` preserve it.
147
148### Revise or pause
149
150Pause a ready change before editing it:
151
152```sh
153valley unready kqxm
154```
155
156It becomes a draft. If it has an approval, ask a principal allowed to approve to
157[delete the outstanding request](#withdraw-or-revoke-an-approval) before you ready a replacement.
158Otherwise, readying the edited change can let the old version land: its request still names the old
159head.
160
161Edit the files, then amend the commit while keeping its `Change-Id` trailer:
162
163```sh
164git add greeting.txt
165git commit --amend --no-edit
166git push --force-with-lease origin HEAD
167valley ready
168valley status kqxm
169```
170
171The new head becomes the next version of the same change. If you make a new commit without its
172trailer or header, use `valley ready --change <full-change-id>` after pushing it.
173
174### Withdraw or revoke an approval
175
176To abandon the change, run `valley withdraw kqxm`. This marks it withdrawn. The integrator removes
177outstanding requests on its next pass while the change is still withdrawn. Do not ready a withdrawn
178change again until that removal is confirmed. For immediate revocation, a principal allowed to
179approve can delete its request:
180
181```sh
182git push origin :refs/the-valley/integration-requests/main/c-<full-change-id>
183```
184
185Replace the whole `<full-change-id>` placeholder before running this command. If an older request
186uses a branch name, delete that request too. Use
187`git ls-remote origin 'refs/the-valley/integration-requests/main/*'` to list them. Neither pausing
188nor withdrawing undoes a completed landing. See the
189[integrator's final readiness check](./concepts.md#the-host-the-hook-and-the-integrator) for the
190limit when a landing is already in progress.
191
192### Restack onto main
193
194Rebase a ready change when it needs the latest `main`. Before replacing an approved version,
195[revoke its outstanding request](#withdraw-or-revoke-an-approval).
196
197```sh
198valley rebase kqxm
199valley status kqxm
200```
201
202This rebases the whole stack beneath the named change, pushes the new heads, and records new
203versions. It leaves your local checkout in place. Read its output before editing locally again;
204fetch the remote updates and reconcile your local branch with them. If a record update fails, finish
205with the exact `valley ready` command it prints.
206
207Get the rebased version reviewed and approved again. Automatic restacking and automatic approval
208carry are not built. For conflicts or an uncertain landing, use
209[recovery](#recovering-from-failure).
210
211## Reviewing and approving changes
212
213A principal allowed to approve can turn a ready change into an integration request. Start in a clone
214of the project with the [client signing settings](#client-setup).
215
216```sh
217valley pending
218valley review kqxm
219```
220
221Use a handle from `pending`. Review pages the diff and offers actions at the terminal. Choose
222`[s]kip` to leave it alone or `[a]pprove` to run its required checks and approve the head you saw. A
223draft or withdrawn layer stops review from offering approval for that layer or anything above it. A
224stack is shown from the bottom up; approving its top includes the layers below.
225
226For a revised change, review automatically compares it with an earlier approved version when one can
227be identified. A clean restack gets a short summary. Use `[v]iew full diff` to see the whole change.
228The [comparison rules](./architecture.md#review-against-the-approved-version) explain what can be
229compared.
230
231You can also approve from the command line:
232
233```sh
234valley approve kqxm
235valley status kqxm
236```
237
238On a terminal, `approve` asks you to confirm the head and title. For automation, pass the exact
239reviewed commit with `valley approve --head <sha> kqxm`. Approval reuses eligible evidence already
240on `origin` for the commit's content tree (see [`valley approve`](./reference.md#valley-approve)),
241runs and signs any remaining required checks, and publishes the new evidence and request together.
242When every required check is covered, nothing runs and no signing key is needed. It does not wait
243for landing. An enabled integrator processes the request; `status` tells you what happened.
244
245After a successful landing, update your local `main`:
246
247```sh
248git fetch origin
249git switch main
250git merge --ff-only origin/main
251```
252
253To inspect all recorded changes, including submitted and withdrawn ones, use
254`valley changes --json`. For changes across the instance, use `valley pending --all` or
255`valley changes --json --all`; see [CLI JSON outputs](./reference.md#cli-json-outputs) for their
256output schemas. These need access to the instance and project repositories.
257
258### Watch activity and inspect results
259
260`status` and `changes --json` read the records on the host. Use them to inspect landing results. If
261your deployment provides access to its NATS bus, configure a NATS context for that endpoint and run:
262
263```sh
264valley tail
265```
266
267It streams events until you interrupt it. Bus access is a deployment choice; the default host bus
268listens on loopback. An administrator can use `journalctl -u valley-integrator@demo` on the host for
269service logs.
270
271An administrator can republish the host's current refs with `replay`. On a host with
272`services.valley.bus.enable = true` at its default address, enter `nix shell .#valley` from a
273checkout of the-valley, then run:
274
275```sh
276sudo -u git env NATS_URL=nats://127.0.0.1:4222 "$(command -v valley)" replay /srv/git/demo.git
277```
278
279Use the deployment's bus address and credentials if they differ. This writes current-state events to
280the bus; it is not a history viewer. See
281[events and mirrors](./architecture.md#after-a-push-events-and-mirrors).
282
283## Planning work with knots
284
285The plan graph records work and the relationships between its knots. Read it from a clone of the
286primary valley repository:
287
288```sh
289valley plan
290valley plan --all
291```
292
293The first command shows this project's plan. The second reads projects published by the serving
294host. A source mirror does not carry the plan graph. See
295[project storage](./concepts.md#records-project-storage-the-plan-graph-and-knots).
296
297Create an outcome and inspect the ID it prints:
298
299```sh
300valley knot new outcome 'Greeting reaches readers' --owner operator
301valley knot list --status active
302```
303
304Use that ID in place of `oc-1234567` below:
305
306```sh
307valley knot show oc-1234567
308valley knot set oc-1234567 status=in-progress
309valley knot new bug 'Greeting needs an example' --parent oc-1234567
310valley knot link oc-1234567 --change valley:demo/<full-change-id>
311```
312
313Replace `<full-change-id>` with the change's full ID. The link connects the plan to the work that
314fulfills it. A dependency uses `--blocked-by <knot-id>` instead. When the outcome is complete:
315
316```sh
317valley knot set oc-1234567 status=done
318valley plan
319```
320
321Comments record findings on a knot. `valley knot show` prints each comment's ID in brackets. A
322comment's author or a holder of the `approve` grant can replace a comment's text with `--edit`:
323
324```sh
325valley knot comment oc-1234567 -m 'Waiting on the example.'
326valley knot show oc-1234567
327valley knot comment oc-1234567 --edit <comment-id> -m 'The example landed.'
328```
329
330The plan graph keeps every earlier text in its commit history. `valley knot log` lists the commits
331that touched a knot or its comments, and `valley knot show --at <commit>` shows the knot at that
332commit:
333
334```sh
335valley knot log oc-1234567
336valley knot show oc-1234567 --at <commit>
337```
338
339Use `valley knot schema` to see each type's fields and allowed statuses. Knot writes validate the
340resulting graph and push it directly; they do not go through change approval. See
341[`valley knot`](./reference.md#valley-knot) for every subcommand and flag, and
342[the plan graph](./architecture.md#the-plan-graph) for validation and concurrent edits.
343
344## Recovering from failure
345
346Start with `valley status <handle>`. It distinguishes work waiting for an integrator from a request
347that the integrator has judged. Keep the command's full output when asking your administrator for
348help.
349
350### A stale or rejected request
351
352A `stale` result means the change conflicts with `main` or required evidence is missing or does not
353transfer across `main` movement. Read the reason in `status`. If the base moved,
354[revoke the outstanding request](#withdraw-or-revoke-an-approval), restack the ready change, then
355ask for a fresh review and approval:
356
357```sh
358valley rebase kqxm
359valley status kqxm
360```
361
362For missing or expired evidence, the approver must rerun approval with trusted signing settings. If
363approval reports that evidence from this signer already exists for the tree, follow its recovery
364message; retrying the same head does not replace that evidence.
365
366A `reject` result means the evidence is invalid, such as a signature or statement that does not
367match what it claims. Keep the reason and ask the administrator to inspect the evidence and signing
368configuration before trying again. See [checks and evidence](./concepts.md#checks-and-evidence).
369
370If `valley rebase` reports a conflict, it pushes nothing. For a single change, start from its remote
371head on a clean local branch, run `git fetch origin` and `git rebase origin/main`, resolve the
372reported files, and use `git add <resolved-files>` followed by `git rebase --continue`. Use
373`git rebase --abort` to abandon that local attempt. Push with `--force-with-lease`, then run
374`valley ready --change <full-change-id>`. For a stack, resolve each layer in order; do not publish
375only the top while lower change records still name old heads.
376
377### A refused push
378
379A refusal means the host did not accept that ref update. The message identifies the boundary:
380
381- **Protected ref:** push the work to a topic branch and use readiness and approval. A deployment
382 may seal `main` against every SSH principal.
383- **Push hold:** ask the administrator to finish maintenance and remove the hold. Client settings
384 cannot bypass it.
385- **Record ownership or non-fast-forward record update:** fetch again and use `valley ready`,
386 `unready`, or `withdraw` as the owner or a principal allowed to approve. Do not force a
387 hand-edited record over someone else's update.
388- **Malformed or oversized record or knot:** read the named validation error. Use the CLI to make
389 valid records and `valley knot schema` to inspect the knot model. Reduce oversized content before
390 retrying.
391
392The [push rules](./architecture.md#what-a-push-may-write) and
393[ref layout table](./reference.md#project-storage-ref-layout-and-bounds) explain each boundary.
394
395### An uncertain landing
396
397An `uncertain` result means the client cannot prove whether the version was submitted. It can follow
398a `failed` outcome or incomplete landing evidence. It can also mean the client had no signers to
399verify the landing with. In that case the command says on stderr that a transfer statement could not
400be verified, and why. Check that the host publishes its signers (step 3 of
401[Client setup](#client-setup)). If it does not, ask the administrator for the signers file and the
402integrator's signing name, set `VALLEY_KNOWN_SIGNERS` and `VALLEY_INTEGRATOR_SIGNER` to them, and
403rerun `valley status <handle>`.
404
405If it remains uncertain, ask the administrator to inspect `main`, the outcome record, and the
406integrator logs together. Do not assume that a consumed request means a successful landing. Resolve
407the uncertainty before rebasing or approving again. The
408[landing definitions](./concepts.md#a-change-ready-approve-submitted) describe the evidence needed
409to resolve this state.
410
411## Running a valley host
412
413A valley host serves repositories over SSH and runs the integrator on NixOS. This recipe creates an
414instance repository named `instance` and a project named `demo`. It uses static keys and grants
415first. All names, keys, checks, mirrors, and backup destinations are deployment choices; see
416[NixOS host options](./reference.md#nixos-host-options) and
417[CUE configuration schemas](./reference.md#cue-configuration-schemas) for the full option tables.
418
419### Declare the host
420
421In your NixOS configuration directory, create `valley.cue`:
422
423```cue
424package valley
425projects: {
426 instance: protection: {refs: ["refs/heads/main"], writers: []}
427 demo: protection: {refs: ["refs/heads/main"], writers: []}
428}
429```
430
431Both projects seal `main` against SSH pushes. The integrator writes locally on the host.
432[`examples/hosts/protected.cue`](../examples/hosts/protected.cue) exercises four protection modes
433for tests; it is not a production recipe.
434
435Add the-valley as an input named `valley` to your NixOS flake, using your administrator's source
436URL. Import `valley.nixosModules.valley-host` in the host's modules. In a module that receives that
437input, start with:
438
439```nix
440{ valley, ... }: {
441 imports = [ valley.nixosModules.valley-host ];
442 services.openssh.enable = true;
443 services.valley = {
444 enable = true;
445 config = ./valley.cue;
446 authorizedKeys = [{
447 principal = "operator";
448 key = "ssh-ed25519 REPLACE_WITH_OPERATOR_PUBLIC_KEY";
449 }];
450 grants.approve = [ "operator" ];
451 };
452}
453```
454
455Pass the input through `specialArgs = { inherit valley; };` in `nixpkgs.lib.nixosSystem` if using
456this module's argument. Replace the key with the public SSH key that the operator uses to push. The
457`approve` grant is the grant that lets a principal approve. It is also accepted as `request`, and
458`grants.request` declares the same grant as `grants.approve`. Keep administrative SSH access
459separate from this git account.
460
461Apply your configuration using your normal NixOS deployment command. For a local flake with a host
462named `valley-host`, run this on the host from that configuration directory:
463
464```sh
465sudo nixos-rebuild switch --flake .#valley-host
466sudo systemctl start valley-init
467sudo systemctl status valley-init --no-pager
468```
469
470`valley-init` creates `/srv/git/instance.git` and `/srv/git/demo.git`, installs hooks, and creates
471no initial commit. It publishes the project list once `instanceProject` is configured. Keep the
472integrator disabled until both repositories have a `main`.
473
474### Seed the initial source
475
476Create the initial source on the host in `/var/tmp/valley-seed`. Use an ordinary administrator
477account with git's author name and email configured:
478
479```sh
480mkdir -p /var/tmp/valley-seed/instance/policy/instance
481mkdir -p /var/tmp/valley-seed/demo/policy
482cd /var/tmp/valley-seed/instance
483git init --initial-branch=main
484printf '# Instance\n' > README.md
485cat > policy/instance/floor.cue <<'CUE'
486package verification
487floor: {
488 checks: readme: {runner: "command", command: "test -s README.md", validity: "1h"}
489 classes: source: {paths: {"**": true}, requires: {readme: true}}
490 unclassified: readme: true
491}
492CUE
493git add README.md policy
494git commit -m 'Seed instance policy'
495cd /var/tmp/valley-seed/demo
496git init --initial-branch=main
497printf '# Demo\n' > README.md
498printf 'git@valley.example:instance\n' > policy/valley
499git add README.md policy
500git commit -m 'Seed demo'
501```
502
503Replace `valley.example` before committing. `policy/valley` names the instance repository whose
504`policy/instance/` supplies this project's floor. The floor here requires only a nonempty README. It
505is a smoke check to prove the approval path works. Choose checks that verify your actual projects
506before admitting production work. A project's optional `policy/project/*.cue` can add requirements;
507it cannot weaken the floor. See [policy](./architecture.md#policy).
508
509Seed these commits through a local host write. The following commands are for the empty repositories
510just created:
511
512```sh
513sudo chown -R git:git /var/tmp/valley-seed
514sudo -u git git -C /srv/git/instance.git fetch /var/tmp/valley-seed/instance main:refs/heads/main
515sudo -u git git -C /srv/git/demo.git fetch /var/tmp/valley-seed/demo main:refs/heads/main
516```
517
518Local writes bypass `pre-receive`, so this works while SSH writes to `main` are sealed. Keep these
519seed directories free of private keys. Another bootstrap choice is to allow a temporary writer and
520remove it after seeding; this recipe keeps the sealed configuration throughout.
521
522### Provision signing and enable integration
523
524On the approver's machine, create its attestation key if it does not have one. From the-valley's
525checkout, export its public verifier entry:
526
527```sh
528ssh-keygen -t ed25519 -N '' -f "$HOME/.ssh/valley-attest"
529nix run .#attest -- key --key "$HOME/.ssh/valley-attest" --name operator > operator.signer
530```
531
532Keep the private key on that machine. Copy only `operator.signer` to the administrator on the host.
533On the host, create the integrator's separate key at a runtime path:
534
535```sh
536sudo install -d -m 0750 -o root -g git /var/lib/valley-secrets
537sudo ssh-keygen -t ed25519 -N '' -f /var/lib/valley-secrets/integrator
538sudo chgrp git /var/lib/valley-secrets/integrator
539sudo chmod 0640 /var/lib/valley-secrets/integrator
540```
541
542On the host, clone the-valley's source from the URL your administrator provides. From that checkout,
543enter `nix shell .#attest`. Export the integrator entry and combine the two public entries:
544
545```sh
546sudo "$(command -v attest)" key --key /var/lib/valley-secrets/integrator --name integrator > integrator.signer
547cat operator.signer integrator.signer > known-signers
548sudo install -m 0644 known-signers /var/lib/valley-secrets/known-signers
549```
550
551Add this to `services.valley` and apply the NixOS configuration again:
552
553```nix
554integrator = {
555 enable = true;
556 instanceProject = "instance";
557 signingKeyFile = "/var/lib/valley-secrets/integrator";
558 signingName = "integrator";
559 knownSignersFile = "/var/lib/valley-secrets/known-signers";
560};
561```
562
563The integrator runs as `valley-integrator` in the `git` group. Its key and signers file must be
564readable by that account. Private keys belong at runtime paths, never in the Nix store.
565
566The module requires a nonempty `authorizedKeys`, a signing key, a source for trusted signers, and
567exactly one of `instanceProject` or `instancePolicy`. With `instanceProject`, it also requires the
568instance's `main` to be protected. `instancePolicy` instead names a directory of floor CUE files on
569a host that does not serve the instance repository. Set `signingName` explicitly to the name
570published in the signers file.
571
572The host publishes the `known-signers` file and the integrator's signing name for clients, at
573`refs/the-valley/signers` in the instance repository. `valley-signers` writes it at boot, on
574activation, and whenever the file changes, so clients need no signer settings. Follow
575[Authoring a change](#authoring-a-change) in a clone of `demo`, then approve it as `operator`.
576Verify that `valley status <handle>` reports the landing. On the host, inspect:
577
578```sh
579sudo systemctl status valley-integrator@demo --no-pager
580sudo journalctl -u valley-integrator@demo -n 50 --no-pager
581sudo journalctl -u valley-signers -n 20 --no-pager
582```
583
584### Use a governed identity registry
585
586A deployment can maintain principals and keys in the instance source instead of listing all of them
587in NixOS. Start with the [registry example](../examples/identity/registry/registry.cue) and
588[schema](../schema/identity.cue). Write your own `identity/*.cue` in the instance repository, with
589your public keys, signing names, boundaries, and grants. Do not deploy the example's keys.
590
591Include a registry governor, the operator's push and approval grants, and a signing entry whose
592`signs` value matches the integrator's `signingName`. Land the registry through the static setup
593above. Then set `services.valley.identity.enable = true` and remove `integrator.knownSignersFile`
594from the NixOS configuration. Apply it and inspect the compilation:
595
596```sh
597sudo systemctl start valley-identity
598sudo journalctl -u valley-identity -n 50 --no-pager
599```
600
601It reads the integrated registry and writes `/var/lib/valley-identity/known-signers`, authorized
602keys, and grants. Distribute that public signers file to clients. Keep a nonempty static
603`authorizedKeys` list for bootstrap access. Static grants remain effective alongside compiled
604grants; remove a static approval grant if the registry should be its sole source. See
605[identity](./architecture.md#identity) for expiry and validation rules.
606
607### Publish source mirrors
608
609A mirror lets readers fetch the source without accessing the primary host. Add a mirror URL to the
610project's declaration and apply the host configuration:
611
612```cue
613projects: demo: mirrors: ["git@mirror.example:team/demo.git"]
614```
615
616Provision the `git` Unix user's SSH private key and pinned `known_hosts` under `/srv/git/.ssh`. The
617directory should be owned by `git` with mode `0700`; the private key should have mode `0600`. Verify
618the mirror's host key through its administrator. The publisher runs as `git` and uses that account's
619SSH configuration.
620
621For an existing mirror, inspect its refs before cutover. Remove unwanted old refs explicitly; the
622publisher does not clean up old topic branches or project storage. Start with an empty mirror when
623possible. See [mirror cutover](./architecture.md#after-a-push-events-and-mirrors).
624
625After a test landing, inspect the publisher:
626
627```sh
628sudo systemctl start valley-publish@demo
629sudo journalctl -u valley-publish@demo -n 50 --no-pager
630git ls-remote git@mirror.example:team/demo.git
631```
632
633Its `main` should match the primary. The publisher sends `main` and tags, not the plan graph or
634other project storage. A mirror is not a backup of the valley.
635
636### Back up and test a restore
637
638Backups preserve the whole data directory. Add an offsite policy to `valley.cue`:
639
640```cue
641backup: {
642 target: "restic-sftp"
643 cadence: "nightly"
644 retention: {daily: 7, weekly: 4, monthly: 6}
645}
646```
647
648Provision four files outside the Nix store: the restic repository URL, its encryption password, the
649SFTP private key, and pinned SSH host keys. Keep a recoverable copy of the password away from this
650host. Point the module at those runtime files:
651
652```nix
653backup = {
654 repositoryFile = "/var/lib/valley-secrets/restic-repository";
655 passwordFile = "/var/lib/valley-secrets/restic-password";
656 sshKeyFile = "/var/lib/valley-secrets/restic-ssh";
657 knownHostsFile = "/var/lib/valley-secrets/restic-known-hosts";
658};
659```
660
661After applying the configuration, take a backup and inspect its result:
662
663```sh
664sudo systemctl start restic-backups-valley
665sudo journalctl -u restic-backups-valley -n 50 --no-pager
666```
667
668The service runs as root and snapshots `services.valley.dataDir`, `/srv/git` by default. Test a
669restore into a separate empty directory. With `restic` available, run these in a root shell:
670
671```sh
672export RESTIC_REPOSITORY_FILE=/var/lib/valley-secrets/restic-repository
673export RESTIC_PASSWORD_FILE=/var/lib/valley-secrets/restic-password
674restic -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
675restic -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
676git -c safe.directory=/var/tmp/valley-restore/srv/git/demo.git -C /var/tmp/valley-restore/srv/git/demo.git fsck --full
677git -c safe.directory=/var/tmp/valley-restore/srv/git/instance.git -C /var/tmp/valley-restore/srv/git/instance.git fsck --full
678```
679
680Expect a snapshot, a completed restore, and no corrupt or missing objects. Git may report dangling
681objects; those alone do not indicate corruption. Inspect the restored `main` and `refs/the-valley/*`
682as well. This verifies the restored repository, not a transaction across every ref written while the
683backup ran.
684
685### Hold pushes for maintenance
686
687To refuse incoming pushes across every project, create the hold on the host:
688
689```sh
690sudo touch /srv/git/.valley-hold
691```
692
693Remove it after maintenance with `sudo rm /srv/git/.valley-hold`. Use your configured `dataDir` if
694it differs. The hold stops SSH pushes; stop the relevant integrator services separately if
695maintenance also requires local integration writes to stop.
696
697## Contributing to the-valley
698
699Contributors work in a checkout of this repository. Read [AGENTS.md](../AGENTS.md) before editing.
700You can enter the default package's build environment:
701
702```sh
703nix develop
704```
705
706This flake defines no dedicated development shell. `nix develop` does not supply the full toolchain.
707For the CLI and Go work, use an explicit tool shell from the repository root:
708
709```sh
710nix shell .#valley .#attest --inputs-from . nixpkgs#go nixpkgs#cue
711```
712
713Each Go component has its own module. Run fast tests from the component you changed, for example:
714
715```sh
716(cd status && go test ./...)
717```
718
719There is no root Go module. To test every Go module from the repository root:
720
721```sh
722for module in attest change composed delta identity integrator knot note rebase restack selfupdate sigverify status valleyhook; do
723 (cd "$module" && go test ./...) || exit 1
724done
725```
726
727In Nix, building a Go package does not run its unit tests. Those tests run only in the module's
728`*-unit` check, such as `valleyhook-unit` for `valleyhook/` or `valley-go-unit` for `status/`:
729
730```sh
731nix build --no-link .#checks.x86_64-linux.valleyhook-unit -L
732```
733
734Run a single Nix check by name. For documentation, format first, then check formatting, links, and
735the style rules, then the policy that selects checks:
736
737```sh
738nix run .#fmt
739nix build --no-link .#checks.x86_64-linux.prose-format -L
740nix build --no-link .#checks.x86_64-linux.own-policy -L
741```
742
743Stage new Markdown files before formatting so the formatter sees them. Review the diff afterward.
744Use [nix/checks](../nix/checks/) to find the integration checks for the component you changed. Run
745them one at a time; VM checks need the virtualization facilities their definitions specify. The full
746flake suite is invoked with `nix flake check` when your task permits it and the machine can run all
747its checks.
748
749Each check is given only the files it reads. [nix/checks.nix](../nix/checks.nix) and
750[nix/packages.nix](../nix/packages.nix) narrow each source to those files with `lib.fileset`. An
751edit to any other file leaves the check's derivation unchanged, so the check's evidence transfers to
752the edited tree. When a check starts to read a new file, give the check that file. The sandbox fails
753a check that reads a file it was not given.
754
755Editing a Go test changes only that module's `*-unit` check, not the other checks that use the
756package. A Go package's source leaves out test files, and its `*-unit` check adds them back.
757
758The NixOS host module uses three of the flake's programs: the integrator, the identity compiler, and
759`valleyhook`. Four checks test what the module renders without running those programs:
760`module-eval`, `mirror-e2e`, `bus-e2e`, and `init-e2e`. Those checks render the module with stand-in
761scripts in place of the three programs ([nix/checks/hosts.nix](../nix/checks/hosts.nix)), so editing
762one of the programs leaves those four checks unchanged. Checks that run one of the programs use the
763real package.
764
765To see which checks an edit gives a new derivation, run the measurement script on a commit:
766
767```sh
768nix/tools/drv-churn.sh --expect nix/tools/drv-churn.expected
769```
770
771It applies a fixed list of representative edits to the commit's tree, one at a time, and evaluates
772every check's derivation after each. With `--expect`, it fails if any edit changes other checks than
773the recorded table says. When a change means to alter the table, write the new one with `--write`.
774With `--history origin/main~20..origin/main` instead, it replays the paths each of those commits
775touched. Run `nix/tools/drv-churn.sh --help` for every option.
776
777The [architecture](./architecture.md) explains component invariants and the checks that cover them.
778The [reference](./reference.md) documents CLI flags, ref bounds, wire formats, JSON outputs, and
779[schema](../schema/) definitions alongside the [concept glossary](./concepts.md#glossary).