gunk-dev/the-valley

packages.nix

source8bf5a934d291main's published tip history
41.2 KiB
1# Everything this flake builds: the valley command, the
2# formatter, the attestation helper, the integrator, the identity
3# compiler, the pre-receive hook's policy, the security-key signature
4# verifier. The flake wires these into packages, apps, and the checks that
5# drive them; nothing here knows about any of those outputs.
6{
7 pkgs,
8 lib,
9 # The commit the flake is built from: its full SHA, the SHA with -dirty
10 # after it for a tree with uncommitted changes, or null when nix knows no
11 # commit. Only the installed CLI's version stamp reads it.
12 rev ? null,
13}:
14rec {
15 # The CLI's version, which `valley --version` prints and self-update
16 # reads to tell which commit is installed (selfupdate/): cliVersion and
17 # the short commit, as 0.1.0-97db597. A dirty tree's has -dirty after
18 # it, and with no commit known it ends in -unknown, so neither names a
19 # commit.
20 cliVersion = "0.1.0";
21 version =
22 if rev == null then
23 "${cliVersion}-unknown"
24 else if lib.hasSuffix "-dirty" rev then
25 "${cliVersion}-${builtins.substring 0 7 rev}-dirty"
26 else
27 "${cliVersion}-${builtins.substring 0 7 rev}";
28
29 # What no Go build or test here reads: prose and .gitignore files. A Go
30 # package's source leaves them out, so editing a module's README rebuilds
31 # nothing.
32 unread = lib.fileset.fileFilter (f: f.hasExt "md" || f.name == ".gitignore") ../.;
33
34 # Every Go test file in the tree. No package's build reads one.
35 goTests = lib.fileset.fileFilter (f: lib.hasSuffix "_test.go" f.name) ../.;
36
37 # A Go module of this repository, built as a package that runs no tests,
38 # with its unit tests beside it as the package's unit attribute.
39 #
40 # The package's source is what its build reads: the module's directory
41 # (dir) and the modules of this repository it uses (modules), which its
42 # go.mod replaces with their local directories, each in its place in the
43 # tree. Nothing shared this way is fetched. The source holds no test file
44 # and none of the files only the tests read (tests.reads), and the
45 # package's checkPhase is off. So an edit to a test, or to a file only the
46 # tests read, changes neither the package nor any check built on it.
47 #
48 # unit is the same build over the same source with the module's own tests
49 # and tests.reads added, and with its checkPhase on. The checkPhase runs
50 # go test, with the rest of tests: the tools the tests need, and what runs
51 # before and after them, such as go vet. Each module's unit is its unit
52 # check (nix/checks/), so its tests run in that check and in no package
53 # build.
54 #
55 # A file the tests read is in unit's source though it is prose, so a test
56 # may read the repository's documents.
57 #
58 # excluded names files of dir that neither the build nor the tests read:
59 # files only a flake check reads, or the part of a shared module that
60 # another package builds and tests.
61 goModule =
62 {
63 dir,
64 modules ? [ ],
65 excluded ? [ ],
66 tests ? { },
67 ...
68 }@args:
69 let
70 testReads = tests.reads or [ ];
71 source =
72 fileset:
73 lib.fileset.toSource {
74 root = ../.;
75 inherit fileset;
76 };
77 build = lib.fileset.difference (lib.fileset.unions ([ dir ] ++ modules)) (
78 lib.fileset.unions ([ unread goTests ] ++ excluded ++ testReads)
79 );
80 withTests = lib.fileset.union (lib.fileset.difference (lib.fileset.unions [
81 build
82 (lib.fileset.intersection goTests dir)
83 ]) (lib.fileset.unions ([ unread ] ++ excluded))) (lib.fileset.unions testReads);
84 in
85 pkgs.buildGoModule (
86 finalAttrs:
87 removeAttrs args [
88 "dir"
89 "modules"
90 "excluded"
91 "tests"
92 ]
93 // {
94 version = "0";
95 src = source build;
96 modRoot = lib.path.removePrefix ../. dir;
97 # Standard library only, so no module is fetched.
98 vendorHash = null;
99 doCheck = false;
100 passthru.unit = finalAttrs.finalPackage.overrideAttrs (
101 prev:
102 removeAttrs tests [ "reads" ]
103 // {
104 pname = "${prev.pname}-unit";
105 src = source withTests;
106 doCheck = true;
107 }
108 );
109 }
110 );
111
112 # vendorHash = null builds in vendor mode, which has no reading of a local
113 # replace. The replaced module is a directory beside the program and
114 # nothing is fetched either way, so these builds read go.mod as written.
115 readsGoMod = ''
116 export GOFLAGS="''${GOFLAGS//-mod=vendor/-mod=mod}"
117 '';
118
119 # Markdown prose is filled paragraphs hard-wrapped at 100 columns
120 # (ida-1ec03b1). One flag string backs both the formatter app and the
121 # prose-format check, so the two cannot drift. Embedded-language
122 # formatting is off so fenced code blocks pass through byte-for-byte.
123 proseFmtArgs = "--prose-wrap always --print-width 100 --embedded-language-formatting off";
124
125 # The valley command (status/), the raw Go binary with nothing wrapped:
126 # the verbs that read a change's state from origin and write its record,
127 # review and approve, the plan graph's verbs, the bus's, checks and
128 # self-update. status reads one change's request and outcome record from
129 # origin, and prints them as sentences or as the valley-status/v1 JSON
130 # object front ends read. ready, unready and withdraw write a change's
131 # record, with the one reading of a record the push hook shares
132 # (../change). rebase rebases a change's whole stack and adds each
133 # change's rebased head to its record, through the rebase engine
134 # (../rebase), which also reads how far each version has landed for the
135 # listings. knot reads and writes the plan graph, with the one reading of
136 # a graph the push hook shares (../knot), and plan shows that graph as a
137 # view. review reads a version's file delta and its approved version's
138 # with the one reading of valley-delta-v1 (../delta). self-update
139 # installs the tip of a branch of the-valley into the user's nix profile
140 # (../selfupdate). checks prints which checks a change requires, as the
141 # deriver (../derive) derives them from the policy the composed-policy
142 # reader (../composed) reads. Go, standard library only. It runs
143 # whatever git, cue, less, attest and nats are on PATH, so checks that
144 # put a failing stand-in for one ahead of it run this binary rather than
145 # a wrapper. Its unit tests hold its shell quoting to bash, so they need
146 # bash, lay pending out over real repositories, so they need git, and
147 # derive a change's checks under the verification schema, so they need
148 # cue and the schema. The plan's golden files (status/testdata/plan/) are
149 # valley-plan's, and no Go test reads them.
150 valley-unwrapped = goModule {
151 pname = "valley-unwrapped";
152 dir = ../status;
153 modules = [
154 ../change
155 ../composed
156 ../delta
157 ../derive
158 ../knot
159 ../note
160 ../rebase
161 ../selfupdate
162 ../telemetry
163 ];
164 excluded = [ ../status/testdata/plan ];
165 preBuild = readsGoMod;
166 tests = {
167 reads = [ ../schema/verification.cue ];
168 nativeCheckInputs = [
169 pkgs.bash
170 pkgs.git
171 pkgs.cue
172 ];
173 # A test that cannot find a tool it needs fails rather than skipping.
174 preCheck = ''
175 export VALLEY_TEST_TOOLS=required
176 '';
177 };
178 meta.mainProgram = "valley";
179 };
180
181 # The valley command with the tools it runs: git, natscli (tail and
182 # replay), cue (checks and approving, which compose the policy layers),
183 # less (review's notes) and attest (approving, which runs the checks and
184 # signs them). The verification schema travels with it, as it does with
185 # the integrator: only the-valley's own tree carries schema/, so a
186 # project's checkout has none to read. --set-default leaves an explicit
187 # VALLEY_VERIFICATION_SCHEMA in charge. It carries no stamp, so the
188 # packages the checks and the integrator use do not change with every
189 # commit.
190 valley-unstamped =
191 pkgs.runCommand "valley"
192 {
193 nativeBuildInputs = [ pkgs.makeWrapper ];
194 meta.mainProgram = "valley";
195 }
196 ''
197 mkdir -p $out/bin
198 makeWrapper ${lib.getExe valley-unwrapped} $out/bin/valley \
199 --prefix PATH : ${
200 lib.makeBinPath [
201 pkgs.git
202 pkgs.natscli
203 pkgs.cue
204 pkgs.less
205 attest
206 ]
207 } \
208 --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue}
209 '';
210
211 # The installed package: the valley command stamped with its version, the
212 # shell completions at the standard paths home-manager/NixOS auto-link,
213 # and the tiny policy self-update's smoke test derives checks from
214 # (examples/policy/smoke/). The stamp is set on this outer wrapper alone,
215 # so the packages the checks and the integrator use do not change with
216 # every commit. The name carries the version as well: nix profile names
217 # the element valley from it, and self-update reads a hand-installed
218 # valley's commit from it.
219 valley =
220 pkgs.runCommand "valley-${version}"
221 {
222 inherit version;
223 nativeBuildInputs = [
224 pkgs.makeWrapper
225 pkgs.installShellFiles
226 ];
227 meta.mainProgram = "valley";
228 }
229 ''
230 mkdir -p $out/bin $out/share/valley
231 makeWrapper ${lib.getExe valley-unstamped} $out/bin/valley \
232 --set VALLEY_VERSION ${version}
233 installShellCompletion --bash --name valley ${../completions/valley.bash}
234 installShellCompletion --zsh --name _valley ${../completions/_valley}
235 cp -r --no-preserve=mode ${../examples/policy/smoke} $out/share/valley/smoke-policy
236 '';
237
238 # The check worker: one pass of `valley work` (status/worker.go), which
239 # builds the nix checks ready changes require and publishes the evidence
240 # before anyone approves them. It runs this flake's git, cue and attest,
241 # and the verification schema travels with it, as it does with the CLI.
242 # nix is the machine's own, for the reason attest gives.
243 valley-worker =
244 pkgs.runCommand "valley-worker"
245 {
246 nativeBuildInputs = [ pkgs.makeWrapper ];
247 meta.mainProgram = "valley-worker";
248 }
249 ''
250 mkdir -p $out/bin
251 makeWrapper ${lib.getExe valley-unwrapped} $out/bin/valley-worker \
252 --add-flags work \
253 --prefix PATH : ${
254 lib.makeBinPath [
255 pkgs.git
256 pkgs.cue
257 attest
258 ]
259 } \
260 --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue}
261 '';
262
263 # `nix run .#fmt` — rewrap every tracked *.md in the repo to 100 columns.
264 prose-fmt = pkgs.writeShellApplication {
265 name = "valley-fmt";
266 runtimeInputs = [
267 pkgs.git
268 pkgs.prettier
269 ];
270 text = ''
271 cd "$(git rev-parse --show-toplevel)"
272 git ls-files -z -- '*.md' | xargs -0 --no-run-if-empty \
273 prettier ${proseFmtArgs} --write
274 '';
275 };
276
277 # The Phase 2 attestation helper (dcr-0de694f). Go, standard library
278 # only, note format included, and hence no module fetch at build time.
279 # Its unit tests need git and ssh-keygen. It reads signed notes, and
280 # writes and reads the statements in them and the valley-tree-v1 digests
281 # they name, with the note module (../note), the one reading of the
282 # envelope and its statement shared by the programs that write, verify
283 # and admit attestations. The conformance
284 # vectors (attest/conformance/) are attest-conformance's, and no Go test
285 # reads them.
286 attest-unwrapped = goModule {
287 pname = "valley-attest";
288 dir = ../attest;
289 modules = [
290 ../note
291 ../telemetry
292 ];
293 excluded = [ ../attest/conformance ];
294 preBuild = readsGoMod;
295 tests.nativeCheckInputs = [
296 pkgs.git
297 pkgs.openssh
298 ];
299 meta.mainProgram = "attest";
300 };
301
302 # The shipping form. git and cue are pinned to this flake's nixpkgs,
303 # so every host composes and vets a statement with the same tools.
304 # Signing needs no tool at all: a note is signed on crypto/ed25519
305 # inside the binary. `nix` is deliberately NOT pinned: the check being
306 # attested to must be built by the nix the machine actually runs, and
307 # a nix carried in here would be a second one.
308 attest =
309 pkgs.runCommand "valley-attest"
310 {
311 nativeBuildInputs = [ pkgs.makeWrapper ];
312 meta.mainProgram = "attest";
313 }
314 ''
315 mkdir -p $out/bin
316 makeWrapper ${lib.getExe attest-unwrapped} $out/bin/attest \
317 --prefix PATH : ${
318 lib.makeBinPath [
319 pkgs.git
320 pkgs.cue
321 ]
322 } \
323 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue}
324 '';
325
326 # The identity registry compiler (dcr-b87f6e8). Go, standard library
327 # only, note format included, same trade as attest and the integrator, so
328 # no module is fetched. It reads the registry's export with exactjson
329 # (../exactjson). Its unit tests pin the note format's key hash
330 # against the reference vector attest is held to, and verify a real
331 # YubiKey attestation against the Yubico roots it carries. The test
332 # vectors (identity/testdata/) are read by the tests and by identity-e2e,
333 # never by the build.
334 identity-unwrapped = goModule {
335 pname = "valley-identity";
336 dir = ../identity;
337 modules = [
338 ../note
339 ../exactjson
340 ];
341 preBuild = readsGoMod;
342 tests.reads = [ ../identity/testdata ];
343 meta.mainProgram = "identity";
344 };
345
346 # The shipping form. git reads the registry out of the instance
347 # repository's tip and cue vets and exports it, both pinned to this
348 # flake's nixpkgs so every host compiles a registry the same way. The
349 # schema travels with the binary: a compiler judging a registry against a
350 # schema the consumer supplied would be no floor at all.
351 identity =
352 pkgs.runCommand "valley-identity"
353 {
354 nativeBuildInputs = [ pkgs.makeWrapper ];
355 meta.mainProgram = "identity";
356 }
357 ''
358 mkdir -p $out/bin
359 makeWrapper ${lib.getExe identity-unwrapped} $out/bin/identity \
360 --prefix PATH : ${
361 lib.makeBinPath [
362 pkgs.git
363 pkgs.cue
364 ]
365 } \
366 --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue}
367 '';
368
369 # The security-key signature verifier (sigverify/README.md). Go,
370 # standard library only, so no module is fetched.
371 #
372 # The git its git-tag command runs is fixed at build time to this
373 # flake's git, as an absolute store path compiled into the binary. A
374 # wrapper that puts git on PATH would leave the binary inside it looking
375 # git up on PATH, and a caller's environment could change which git that
376 # is. Compiled in, there is no PATH lookup to change.
377 #
378 # Its tests run against real ssh-keygen and git. The security-key cases
379 # among them need OpenSSH's sk-dummy authenticator, which the
380 # sigverify-unit check supplies. Building this package runs no test, so a
381 # consumer building it never builds OpenSSH.
382 sigverify = goModule {
383 pname = "valley-sigverify";
384 dir = ../sigverify;
385 ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ];
386 tests.nativeCheckInputs = [
387 pkgs.git
388 pkgs.openssh
389 ];
390 meta.mainProgram = "sigverify";
391 };
392
393 # Telemetry (../telemetry): the diagnostic records, the bounded streams
394 # that hold them and the telemetry command's grammar, which the
395 # producers, the git user's shell and the collector share, and the
396 # collector itself, valley-telemetry serve, which the host runs per
397 # connection to its socket. Go, standard library only.
398 telemetry = goModule {
399 pname = "valley-telemetry";
400 dir = ../telemetry;
401 meta.mainProgram = "valley-telemetry";
402 };
403
404 # The pre-receive hook's policy (valleyhook/): what a push may write to a
405 # project a valley host serves. It validates a push to the plan graph
406 # with the one reading of a graph the CLI shares (../knot), and reads the
407 # project's push policy with exactjson (../exactjson). The same
408 # binary is the git user's login shell, which derives the pushing
409 # principal and pauses pushes until the host has converged. Go, standard
410 # library only, so no module is fetched.
411 #
412 # The git it reads the repository with is fixed at build time, the way
413 # sigverify's is: an absolute store path compiled into the binary, so no
414 # PATH a hook runs under can change which git that is.
415 valleyhook = goModule {
416 pname = "valley-valleyhook";
417 dir = ../valleyhook;
418 modules = [
419 ../note
420 ../change
421 ../knot
422 ../exactjson
423 ../telemetry
424 ];
425 preBuild = readsGoMod;
426 ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ];
427 # The walk's and the change records' tests build hostile objects with
428 # real git.
429 tests.nativeCheckInputs = [ pkgs.git ];
430 meta.mainProgram = "valleyhook";
431 };
432
433 # The PIV session signer (approval/piv/): a small C program on libykpiv
434 # that holds a YubiKey exclusively for a run of approval signatures,
435 # asks for the PIN once on the terminal, and signs each statement with a
436 # touch. It is C so that the Go modules stay standard library only: the
437 # approval command runs it rather than linking a smart card library. It
438 # calls pcsc-lite, libykpiv's own transport, directly only to connect
439 # exclusively and to see a reset. libykpiv reconnects after a reset or a
440 # removal (_ykpiv_begin_transaction) in shared mode; the signer's
441 # libykpiv reconnects exclusively, so no command reaches the card over a
442 # shared connection even when the card changes between the helper's
443 # check and libykpiv's call. nixpkgs' default hardening applies.
444 piv-signer = pkgs.stdenv.mkDerivation {
445 pname = "valley-piv-signer";
446 version = "0";
447 src = ../approval/piv;
448 buildInputs = [
449 (pkgs.yubico-piv-tool.overrideAttrs (old: {
450 postPatch = (old.postPatch or "") + ''
451 substituteInPlace lib/ykpiv.c \
452 --replace-fail 'SCardReconnect(state->card, SCARD_SHARE_SHARED,' \
453 'SCardReconnect(state->card, SCARD_SHARE_EXCLUSIVE,' \
454 --replace-fail 'SCardConnect(state->context, state->reader, SCARD_SHARE_SHARED,' \
455 'SCardConnect(state->context, state->reader, SCARD_SHARE_EXCLUSIVE,'
456 '';
457 }))
458 pkgs.pcsclite
459 ];
460 buildPhase = ''
461 $CC -std=c11 -O2 -Wall -Wextra -Werror -o valley-piv-signer valley-piv-signer.c \
462 -I${lib.getDev pkgs.pcsclite}/include/PCSC -lykpiv -lpcsclite
463 '';
464 installPhase = ''
465 install -Dm755 valley-piv-signer $out/bin/valley-piv-signer
466 '';
467 meta.mainProgram = "valley-piv-signer";
468 };
469
470 # Approval statements (approval/): the-valley/approval/v1's written form,
471 # signing it with a software key or a YubiKey's PIV slot, and verifying
472 # an approval note under the approval signers files. Go, standard library
473 # only. The PIV signer it runs is fixed at build time, the way
474 # sigverify's git is: an absolute store path compiled into the binary.
475 # Its unit tests run that signer with no smart card service to reach, so
476 # no device is touched.
477 approval = goModule {
478 pname = "valley-approval";
479 dir = ../approval;
480 modules = [
481 ../note
482 ../change
483 ];
484 excluded = [ ../approval/piv ];
485 subPackages = [ "cmd/approval" ];
486 preBuild = readsGoMod;
487 ldflags = [ "-X main.pivSigner=${lib.getExe piv-signer}" ];
488 tests = {
489 reads = [ ../approval/testdata ];
490 subPackages = [
491 "."
492 "cmd/approval"
493 ];
494 VALLEY_PIV_SIGNER = lib.getExe piv-signer;
495 };
496 meta.mainProgram = "approval";
497 };
498
499 # The note envelope (note/). Its tests hold it to refusing every line a
500 # relayer could append that one of its readers would refuse.
501 note = goModule {
502 pname = "valley-note";
503 dir = ../note;
504 };
505
506 # The strict JSON reading (exactjson/) that the identity compiler, the
507 # pre-receive hook and read access read CUE's exports with: every key
508 # spelled exactly as the field it is read into, and no key twice in one
509 # object. Its tests
510 # hold it to each spelling encoding/json alone would fold into a field.
511 exactjson = goModule {
512 pname = "valley-exactjson";
513 dir = ../exactjson;
514 };
515
516 # The web UI (web/). Package export is the contract between the
517 # publisher on a valley host and the web server it pushes to: the public
518 # export and the projection onto it, the signed manifest, the upload and
519 # the receiver's state directory. It reads names and IDs by the plan
520 # graph's rules (../knot), the manifest with the note module (../note),
521 # and who may read a project through ../readaccess, which reads with
522 # ../exactjson, as the publisher reads the host declaration and package
523 # export reads export.json. The program
524 # built from it is the publisher, cmd/valley-web-publish, which
525 # valley-web-publish below wraps. The server and its command are built by
526 # valley-web below, and the receiver by valley-web-receive. The export's
527 # tests accept bundles and build the shared fixture's repositories with
528 # real git. The publisher's tests run it against a valley built with real
529 # git and the valley command's raw binary, read each project's policy/read and the instance's identity
530 # registry with cue under schema/read.cue and schema/identity.cue, and
531 # upload to a receiver over a real store, and to the real receiver, whose
532 # state directory the real valley-web serves. One lands a change as the
533 # integrator does, with a transfer statement attest signs under a key
534 # ssh-keygen makes, which the CLI verifies with attest. Each test's host
535 # declaration is exported by cue under schema/valley.cue, as the module
536 # exports the host's. go vet runs after them. The fixture's expected
537 # export (export/exporttest/testdata/) is read by the tests alone, and so
538 # are README.md and docs/, whose links package markdown's tests resolve. Go,
539 # standard library only, so no module is fetched.
540 web = goModule {
541 pname = "valley-web-module";
542 dir = ../web;
543 modules = [
544 ../knot
545 ../note
546 ../readaccess
547 ../exactjson
548 ];
549 excluded = [
550 ../web/server
551 ../web/readerstate
552 ../web/cmd/valley-web
553 ../web/cmd/valley-web-receive
554 ];
555 preBuild = readsGoMod;
556 tests = {
557 reads = [
558 ../web/export/exporttest/testdata
559 ../README.md
560 ../docs
561 ../schema/read.cue
562 ../schema/identity.cue
563 ../schema/valley.cue
564 ];
565 nativeCheckInputs = [
566 pkgs.git
567 pkgs.bash
568 pkgs.cue
569 pkgs.openssh
570 valley-unwrapped
571 attest
572 ];
573 # A test that cannot find a tool it needs fails rather than skipping.
574 preCheck = ''
575 export VALLEY_TEST_TOOLS=required
576 export VALLEY_WEB=${lib.getExe valley-web}
577 export VALLEY_WEB_RECEIVE=${lib.getExe valley-web-receive}
578 '';
579 postCheck = ''
580 go vet ./...
581 '';
582 };
583 meta.mainProgram = "valley-web-publish";
584 };
585
586 # Read access (readaccess/): the two consents a principal needs to read a
587 # project, read out of git commits with cue under schema/read.cue and
588 # schema/identity.cue, and the evaluator that intersects them. The web
589 # publisher reads through it, and its command is the coverage report,
590 # which valley-read-coverage below wraps. It reads cue's exports with
591 # exactjson (../exactjson). Its tests read real commits with real git and
592 # the real cue under both schemas, and go vet runs after them. Go,
593 # standard library only, so no module is fetched.
594 readaccess = goModule {
595 pname = "valley-readaccess";
596 dir = ../readaccess;
597 modules = [ ../exactjson ];
598 preBuild = readsGoMod;
599 tests = {
600 reads = [
601 ../schema/read.cue
602 ../schema/identity.cue
603 ];
604 nativeCheckInputs = [
605 pkgs.git
606 pkgs.cue
607 ];
608 # A test that cannot find a tool it needs fails rather than skipping.
609 preCheck = ''
610 export VALLEY_TEST_TOOLS=required
611 '';
612 postCheck = ''
613 go vet ./...
614 '';
615 };
616 meta.mainProgram = "valley-read-coverage";
617 };
618
619 # The coverage report: which projects a principal cannot read at a
620 # destination, and which consent each lacks. It runs this flake's git and
621 # cue, and both schemas travel with it.
622 valley-read-coverage =
623 pkgs.runCommand "valley-read-coverage"
624 {
625 nativeBuildInputs = [ pkgs.makeWrapper ];
626 meta.mainProgram = "valley-read-coverage";
627 }
628 ''
629 mkdir -p $out/bin
630 makeWrapper ${lib.getExe readaccess} $out/bin/valley-read-coverage \
631 --prefix PATH : ${
632 lib.makeBinPath [
633 pkgs.git
634 pkgs.cue
635 ]
636 } \
637 --set-default VALLEY_READ_SCHEMA ${../schema/read.cue} \
638 --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue}
639 '';
640
641 # The web UI's server (web/server/) and its command, valley-web
642 # (web/cmd/valley-web/), which serves the active export of a receiver's
643 # state directory to its readers, and keeps their sessions in the
644 # browser state (web/readerstate/). It reads the export and the
645 # state directory with package export, so its source is the web
646 # module, less the fixture's expected export, which only web's tests
647 # read. Package export reads export.json with ../exactjson, so its
648 # source holds that module too. Of ../readaccess, which the publisher
649 # reads through and the server does not, it reads the go.mod alone,
650 # which go reads to resolve the module. The git it reads repositories
651 # with is fixed at build time, the way valleyhook's is. Its tests run the real program over the shared
652 # fixture and real git, and the server over the real publisher's output
653 # (web-published), and go vet runs after them. The crash tests and the
654 # browser test are skipped there: web-reader-state-crash and
655 # web-reader-browser-e2e (nix/checks/) run them from the same tests.
656 # Go, standard library only, so no module is fetched.
657 valley-web = goModule {
658 pname = "valley-web";
659 dir = ../web;
660 modules = [
661 ../knot
662 ../note
663 ../readaccess/go.mod
664 ../exactjson
665 ];
666 excluded = [
667 ../web/export/exporttest/testdata
668 ../web/cmd/valley-web-publish
669 ../web/cmd/valley-web-receive
670 ];
671 subPackages = [ "cmd/valley-web" ];
672 preBuild = readsGoMod;
673 ldflags = [ "-X the-valley/web/export.GitProgram=${lib.getExe pkgs.git}" ];
674 tests = {
675 subPackages = [
676 "server"
677 "readerstate"
678 "cmd/valley-web"
679 ];
680 checkFlags = [ "-skip=^(TestCrash|TestBrowser)" ];
681 nativeCheckInputs = [ pkgs.git ];
682 # A test that cannot find the publisher's output fails rather than
683 # skipping.
684 preCheck = ''
685 export VALLEY_TEST_TOOLS=required
686 export VALLEY_WEB_PUBLISHED=${web-published}
687 '';
688 postCheck = ''
689 go vet ./server/... ./readerstate/... ./cmd/valley-web/...
690 '';
691 };
692 meta.mainProgram = "valley-web";
693 };
694
695 # The real publisher's signed output over a small valley with a public
696 # project, two private projects each one named reader may read, and a
697 # project with no effective reader, written with --out by the packaged publisher and CLI
698 # (nix/checks/web-published.sh). valley-web's tests read it, so the
699 # server is tested against what the publisher writes. It is no check of
700 # its own.
701 web-published =
702 pkgs.runCommand "valley-web-published"
703 {
704 nativeBuildInputs = [
705 pkgs.git
706 pkgs.cue
707 pkgs.jq
708 valley-unstamped
709 valley-web-publish
710 ];
711 schema = ../schema/valley.cue;
712 }
713 (builtins.readFile ./checks/web-published.sh);
714
715 # The web export receiver, valley-web-receive (web/cmd/valley-web-receive/),
716 # which takes the publisher's uploads into a state directory that
717 # valley-web serves. Its source is the web module less the publisher,
718 # the server and its command, which it does not build, and the fixture's
719 # expected export. Package export reads export.json with ../exactjson, so
720 # its source holds that module too; of ../readaccess it reads the go.mod
721 # alone, as valley-web does. The git it accepts bundles with is fixed at
722 # build time. Its tests run the real program over the shared fixture and
723 # real git, with the real valley-web serving its state directory, and go
724 # vet runs after them. Go, standard library only.
725 valley-web-receive = goModule {
726 pname = "valley-web-receive";
727 dir = ../web;
728 modules = [
729 ../knot
730 ../note
731 ../readaccess/go.mod
732 ../exactjson
733 ];
734 excluded = [
735 ../web/export/exporttest/testdata
736 ../web/cmd/valley-web-publish
737 ../web/cmd/valley-web
738 ../web/server
739 ../web/readerstate
740 ];
741 subPackages = [ "cmd/valley-web-receive" ];
742 preBuild = readsGoMod;
743 ldflags = [ "-X the-valley/web/export.GitProgram=${lib.getExe pkgs.git}" ];
744 tests = {
745 nativeCheckInputs = [ pkgs.git ];
746 # A test that cannot find valley-web fails rather than skipping.
747 preCheck = ''
748 export VALLEY_TEST_TOOLS=required
749 export VALLEY_WEB=${lib.getExe valley-web}
750 '';
751 postCheck = ''
752 go vet ./cmd/valley-web-receive/...
753 '';
754 };
755 meta.mainProgram = "valley-web-receive";
756 };
757
758 # The edge's container image, for a web server that does not run NixOS:
759 # valley-web and valley-web-receive, and the git both run, in one image.
760 # The two run as two containers of it over one state directory, as two
761 # users of one group: the receiver as valley-web-receive, which writes
762 # the directory, and valley-web as valley-web, which reads it. The image
763 # names both users in its /etc/passwd, and holds the state directory,
764 # owned by the receiver and readable by the group alone, so a volume
765 # mounted there starts with that owner and mode. In it, browser/ is
766 # valley-web's alone, mode 0700: the browser state, the one place
767 # valley-web writes. It runs as valley-web unless it is told otherwise,
768 # and starts no program of its own: each container names its command.
769 edgeUsers = {
770 receiver = {
771 name = "valley-web-receive";
772 uid = 990;
773 };
774 web = {
775 name = "valley-web";
776 uid = 991;
777 };
778 gid = 990;
779 };
780 valley-web-image = pkgs.dockerTools.buildLayeredImage {
781 name = "valley-web";
782 contents = [
783 valley-web
784 valley-web-receive
785 (pkgs.dockerTools.fakeNss.override {
786 extraPasswdLines = with edgeUsers; [
787 "${receiver.name}:x:${toString receiver.uid}:${toString gid}:valley-web-receive:/var/empty:/bin/false"
788 "${edgeUsers.web.name}:x:${toString edgeUsers.web.uid}:${toString gid}:valley-web:/var/empty:/bin/false"
789 ];
790 extraGroupLines = [ "valley-web:x:${toString edgeUsers.gid}:" ];
791 })
792 ];
793 fakeRootCommands = ''
794 mkdir -p var/lib/valley-web/browser tmp
795 chown ${toString edgeUsers.receiver.uid}:${toString edgeUsers.gid} var/lib/valley-web
796 chmod 0750 var/lib/valley-web
797 chown ${toString edgeUsers.web.uid}:${toString edgeUsers.gid} var/lib/valley-web/browser
798 chmod 0700 var/lib/valley-web/browser
799 chmod 1777 tmp
800 '';
801 config = {
802 User = edgeUsers.web.name;
803 WorkingDirectory = "/";
804 Env = [ "PATH=/bin" ];
805 Volumes."/var/lib/valley-web" = { };
806 };
807 };
808
809 # The web publisher: one pass of valley-web-publish, which reads a valley
810 # host's public projects through the CLI's JSON commands and uploads them
811 # to a web receiver. It runs this flake's git, cue and CLI, and the two
812 # schemas it reads read access under travel with it, as the verification
813 # schema does with the CLI.
814 valley-web-publish =
815 pkgs.runCommand "valley-web-publish"
816 {
817 nativeBuildInputs = [ pkgs.makeWrapper ];
818 meta.mainProgram = "valley-web-publish";
819 }
820 ''
821 mkdir -p $out/bin
822 makeWrapper ${lib.getExe web} $out/bin/valley-web-publish \
823 --prefix PATH : ${
824 lib.makeBinPath [
825 pkgs.git
826 pkgs.cue
827 valley-unstamped
828 ]
829 } \
830 --set-default VALLEY_READ_SCHEMA ${../schema/read.cue} \
831 --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue}
832 '';
833
834 # The plan graph (knot/): its canonical form, its layout, cycles and
835 # transitions, held by its own tests. The package is knotcheck, which
836 # knot-agree runs to hold the Go validator to the CUE schema and the
837 # knowledge lint.
838 knot = goModule {
839 pname = "valley-knot";
840 dir = ../knot;
841 meta.mainProgram = "knotcheck";
842 };
843
844 # The rebase engine (rebase/): a family of stacked changes captured from
845 # one snapshot of origin, rebased in a throwaway worktree, and published
846 # as one atomic branch push and one record append per change. It verifies
847 # the integrator's transfer statements with the note module (../note).
848 # Its tests run against real repositories, real pushes and real git, with
849 # go vet after them. Go, standard library only, so no module is fetched.
850 rebase = goModule {
851 pname = "valley-rebase";
852 dir = ../rebase;
853 modules = [
854 ../change
855 ../note
856 ];
857 preBuild = readsGoMod;
858 tests = {
859 nativeCheckInputs = [ pkgs.git ];
860 postCheck = ''
861 go vet ./...
862 '';
863 };
864 };
865
866 # Self-update (selfupdate/): the installed CLI brought up to the tip of a
867 # branch, built with nix and installed into the user's profile. Its tests,
868 # with go vet after them, use a real bare repository for ls-remote and a
869 # stand-in for nix whose builds are small scripts, so nothing is built and
870 # no profile is touched. Go, standard library only, so no module is
871 # fetched.
872 selfupdate = goModule {
873 pname = "valley-selfupdate";
874 dir = ../selfupdate;
875 tests = {
876 nativeCheckInputs = [ pkgs.git ];
877 postCheck = ''
878 go vet ./...
879 '';
880 };
881 };
882
883 # The deriver of required checks (derive/): a change's paths read from
884 # git diff -z, globs matched byte by byte, and the required checks, pins,
885 # carry mode and unclassified paths derived from the whole composed
886 # policy (../composed). Its tests, with go vet after them, derive over the
887 # repository's own policy and the example policies, with changes drawn
888 # from a fixed seed, so they read the schema and those policies, and need
889 # git and cue. Go, standard library only, so no module is fetched.
890 derive = goModule {
891 pname = "valley-derive";
892 dir = ../derive;
893 modules = [ ../composed ];
894 preBuild = readsGoMod;
895 tests = {
896 reads = [
897 ../schema/verification.cue
898 ../examples/policy
899 ../policy/project
900 ];
901 nativeCheckInputs = [
902 pkgs.git
903 pkgs.cue
904 ];
905 # A test that cannot find a tool it needs fails rather than skipping.
906 preCheck = ''
907 export VALLEY_TEST_TOOLS=required
908 '';
909 postCheck = ''
910 go vet ./...
911 '';
912 };
913 };
914
915 # The composed-policy reader (composed/): each layer read out of git,
916 # present, absent or refused. Its tests
917 # read layers from real repositories, some with objects removed, and go
918 # vet runs after them.
919 composed = goModule {
920 pname = "valley-composed";
921 dir = ../composed;
922 tests = {
923 nativeCheckInputs = [ pkgs.git ];
924 # A test that cannot find git fails rather than skipping.
925 preCheck = ''
926 export VALLEY_TEST_TOOLS=required
927 '';
928 postCheck = ''
929 go vet ./...
930 '';
931 };
932 };
933
934 # The change record (change/). Its tests cover its strict reading, its
935 # fuzz target's seed corpus, and its branch-name rule, which they hold to
936 # real git's check-ref-format.
937 change = goModule {
938 pname = "valley-change";
939 dir = ../change;
940 tests.nativeCheckInputs = [ pkgs.git ];
941 };
942
943 # valley-delta-v1 (delta/): the encoding's strict reading, and the delta
944 # read from real trees. Its unit tests run go vet, the conformance
945 # vectors' script in its --check mode, which holds the committed expected
946 # results to what the script computes, and go test, which builds each
947 # vector's trees with real git and holds the Go code to those results.
948 delta = goModule {
949 pname = "valley-delta";
950 dir = ../delta;
951 tests = {
952 reads = [ ../delta/testdata ];
953 nativeCheckInputs = [
954 pkgs.git
955 pkgs.python3
956 ];
957 preCheck = ''
958 go vet ./...
959 python3 -I testdata/vectors.py --check testdata
960 '';
961 };
962 };
963
964 # Review records (review/): the-valley/review/v1's strict reading, a
965 # review's binding to the version it judged, recomputed from git within a
966 # budget, and the append-only history a review is kept in, with the check
967 # an append is held to. It reads change records with the one reading of a
968 # record the push hook shares (../change), and the delta with
969 # valley-delta-v1's bounded reading (../delta). Its tests build every
970 # repository they read with real git and run its fuzz target's seed
971 # corpus, and go vet runs after them. Go, standard library only, so no
972 # module is fetched.
973 review = goModule {
974 pname = "valley-review";
975 dir = ../review;
976 modules = [
977 ../change
978 ../delta
979 ];
980 preBuild = readsGoMod;
981 tests = {
982 nativeCheckInputs = [ pkgs.git ];
983 postCheck = ''
984 go vet ./...
985 '';
986 };
987 };
988
989 # The restacker (restack/): `valley-restacker run` reconciles on an
990 # interval, and `once` is one pass. A pass reads origin through the
991 # rebase engine (../rebase), plans which families to restack and which
992 # to hold, keeps the writes in its journal, and pushes them;
993 # `once --report-only` pushes none. It reads the cap on its
994 # automatic versions through the composed-policy reader it shares with
995 # the integrator (../composed), and a signer projects file through the
996 # note module (../note). Its unit tests cover request association,
997 # outcome currency, capacity and report bounds, and, against real git,
998 # the journal of writes, recovery's decisions and publishing through the
999 # rendered hook, its environment, its
1000 # scratch repository's identity, its state directory's lock and binding,
1001 # and the deadline on what it runs. go vet runs after them. Go, standard
1002 # library only, so no module is fetched.
1003 restack-unwrapped = goModule {
1004 pname = "valley-restacker";
1005 dir = ../restack;
1006 modules = [
1007 ../change
1008 ../composed
1009 ../note
1010 ../rebase
1011 ];
1012 # The program alone: e2e/transport is a module of restack-e2e's own,
1013 # which neither this build nor its tests read.
1014 excluded = [ ../restack/e2e ];
1015 subPackages = [ "." ];
1016 preBuild = readsGoMod;
1017 tests = {
1018 nativeCheckInputs = [ pkgs.git ];
1019 postCheck = ''
1020 go vet ./...
1021 '';
1022 };
1023 # The module is named for its directory; the program, for what it is.
1024 postInstall = ''
1025 mv $out/bin/restack $out/bin/valley-restacker
1026 '';
1027 meta.mainProgram = "valley-restacker";
1028 };
1029
1030 # The shipping form: git to read origin and cue to compose the policy,
1031 # both pinned to this flake's nixpkgs, with the packaged verification
1032 # schema as the default.
1033 valley-restacker =
1034 pkgs.runCommand "valley-restacker"
1035 {
1036 nativeBuildInputs = [ pkgs.makeWrapper ];
1037 meta.mainProgram = "valley-restacker";
1038 }
1039 ''
1040 mkdir -p $out/bin
1041 makeWrapper ${lib.getExe restack-unwrapped} $out/bin/valley-restacker \
1042 --prefix PATH : ${
1043 lib.makeBinPath [
1044 pkgs.git
1045 pkgs.cue
1046 ]
1047 } \
1048 --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue}
1049 '';
1050
1051 # The Phase 3 integrator (dcr-439b771). Go, standard library only,
1052 # same trade as attest, so no module is fetched. It reads change records
1053 # with the one reading of a record the push hook shares (../change),
1054 # verifier keys with the one reading of a key the note format defines
1055 # (../note), and derives required checks with the deriver (../derive).
1056 integrator-unwrapped = goModule {
1057 pname = "valley-integrator";
1058 dir = ../integrator;
1059 modules = [
1060 ../change
1061 ../composed
1062 ../derive
1063 ../note
1064 ../telemetry
1065 ];
1066 # The scenarios (integrator/e2e/) are integrator-e2e's, and no Go test
1067 # reads them.
1068 excluded = [ ../integrator/e2e ];
1069 preBuild = readsGoMod;
1070 tests = {
1071 # The policy bridge's tests compose a policy under the verification
1072 # schema with real cue, and derive over diffs in real git.
1073 reads = [ ../schema/verification.cue ];
1074 nativeCheckInputs = [
1075 pkgs.git
1076 pkgs.cue
1077 ];
1078 };
1079 meta.mainProgram = "integrator";
1080 };
1081
1082 # The shipping form. The integrator drives four programs rather than
1083 # reimplementing what they do: attest judges every statement and
1084 # every note, cue composes the policy, git holds the requests and the
1085 # refs, and nats publishes its events. All four are pinned to this
1086 # flake's nixpkgs so an instance's integrators agree; `nix` is
1087 # deliberately absent for the same reason it is absent from attest —
1088 # a closure must be recomputed by the nix the machine actually runs.
1089 integrator =
1090 pkgs.runCommand "valley-integrator"
1091 {
1092 nativeBuildInputs = [ pkgs.makeWrapper ];
1093 meta.mainProgram = "integrator";
1094 }
1095 ''
1096 mkdir -p $out/bin
1097 makeWrapper ${lib.getExe integrator-unwrapped} $out/bin/integrator \
1098 --prefix PATH : ${
1099 lib.makeBinPath [
1100 pkgs.git
1101 pkgs.cue
1102 pkgs.natscli
1103 attest
1104 ]
1105 } \
1106 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} \
1107 --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} \
1108 --set-default VALLEY_EVENT_SCHEMA ${../schema/events.cue}
1109 '';
1110}