gunk-dev/the-valley

guide.md

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