| 1 | # Everything this flake builds: the CLI and its Go verbs, 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 | }: |
| 14 | rec { |
| 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 | # excluded names files of dir that neither the build nor the tests read: |
| 56 | # files only a flake check reads, or the part of a shared module that |
| 57 | # another package builds and tests. |
| 58 | goModule = |
| 59 | { |
| 60 | dir, |
| 61 | modules ? [ ], |
| 62 | excluded ? [ ], |
| 63 | tests ? { }, |
| 64 | ... |
| 65 | }@args: |
| 66 | let |
| 67 | testReads = tests.reads or [ ]; |
| 68 | source = |
| 69 | fileset: |
| 70 | lib.fileset.toSource { |
| 71 | root = ../.; |
| 72 | inherit fileset; |
| 73 | }; |
| 74 | build = lib.fileset.difference (lib.fileset.unions ([ dir ] ++ modules)) ( |
| 75 | lib.fileset.unions ([ unread goTests ] ++ excluded ++ testReads) |
| 76 | ); |
| 77 | withTests = lib.fileset.difference (lib.fileset.unions ( |
| 78 | [ |
| 79 | build |
| 80 | (lib.fileset.intersection goTests dir) |
| 81 | ] |
| 82 | ++ testReads |
| 83 | )) (lib.fileset.unions ([ unread ] ++ excluded)); |
| 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 integrator's CLI (bin/valley) wrapped for `nix run`. The script |
| 126 | # itself must keep running bare from any checkout — the package is the |
| 127 | # second of its two shipping modes, never a dependency of the first. |
| 128 | valley-script-unwrapped = pkgs.writeShellApplication { |
| 129 | name = "valley"; |
| 130 | runtimeInputs = [ |
| 131 | pkgs.git |
| 132 | pkgs.natscli # tail and replay only; every other verb needs just git |
| 133 | pkgs.cue # checks and approving — it composes the policy layers |
| 134 | pkgs.less # review only — its v key is what takes a note |
| 135 | attest # approving only — it runs the checks and signs them |
| 136 | valley-go # status, ready, unready, withdraw and rebase, naming a change by its ID, and pending's drafts |
| 137 | ]; |
| 138 | text = builtins.readFile ../bin/valley; |
| 139 | }; |
| 140 | |
| 141 | # The shipping form. The verification schema travels with the script, as |
| 142 | # it does with the integrator: only the-valley's own tree carries |
| 143 | # schema/, so a project's checkout has none to read. --set-default leaves |
| 144 | # an explicit VALLEY_VERIFICATION_SCHEMA in charge. |
| 145 | valley-script = |
| 146 | pkgs.runCommand "valley" |
| 147 | { |
| 148 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 149 | meta.mainProgram = "valley"; |
| 150 | } |
| 151 | '' |
| 152 | mkdir -p $out/bin |
| 153 | makeWrapper ${lib.getExe valley-script-unwrapped} $out/bin/valley \ |
| 154 | --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} |
| 155 | ''; |
| 156 | |
| 157 | # The installed package: the wrapped script stamped with its version, the |
| 158 | # shell completions at the standard paths home-manager/NixOS auto-link, |
| 159 | # and the tiny policy self-update's smoke test derives checks from |
| 160 | # (examples/policy/smoke/). The stamp is set on this outer wrapper alone, |
| 161 | # so the packages the checks and the integrator use do not change with |
| 162 | # every commit. The name carries the version as well: nix profile names |
| 163 | # the element valley from it, and self-update reads a hand-installed |
| 164 | # valley's commit from it. |
| 165 | valley = |
| 166 | pkgs.runCommand "valley-${version}" |
| 167 | { |
| 168 | inherit version; |
| 169 | nativeBuildInputs = [ |
| 170 | pkgs.makeWrapper |
| 171 | pkgs.installShellFiles |
| 172 | ]; |
| 173 | meta.mainProgram = "valley"; |
| 174 | } |
| 175 | '' |
| 176 | mkdir -p $out/bin $out/share/valley |
| 177 | makeWrapper ${lib.getExe valley-script} $out/bin/valley \ |
| 178 | --set VALLEY_VERSION ${version} |
| 179 | installShellCompletion --bash --name valley ${../completions/valley.bash} |
| 180 | installShellCompletion --zsh --name _valley ${../completions/_valley} |
| 181 | cp -r --no-preserve=mode ${../examples/policy/smoke} $out/share/valley/smoke-policy |
| 182 | ''; |
| 183 | |
| 184 | # The verbs of the CLI written in Go (status/). status reads one change's |
| 185 | # request and outcome record from origin, and prints them as sentences or |
| 186 | # as the valley-status/v1 JSON object front ends read. ready, unready and |
| 187 | # withdraw write a change's record, with the one reading of a record the |
| 188 | # push hook shares (../change). rebase rebases a change's whole stack and |
| 189 | # adds each change's rebased head to its record, through the rebase engine |
| 190 | # (../rebase), which also reads how far each version has landed for the |
| 191 | # listings. knot reads and writes the plan graph, with the one reading of |
| 192 | # a graph the push hook shares (../knot), and plan shows that graph as a |
| 193 | # view. compare reads a version's file delta and its approved version's |
| 194 | # with the one reading of valley-delta-v1 (../delta), for review. |
| 195 | # self-update installs the tip of a branch of the-valley into the user's |
| 196 | # nix profile (../selfupdate). checks prints which checks a change |
| 197 | # requires, as the deriver (../derive) derives them from the policy the |
| 198 | # composed-policy reader (../composed) reads. Go, standard library only. |
| 199 | # It runs whatever git and cue are on PATH, which inside the CLI's package |
| 200 | # are the CLI's own. Its unit tests hold its shell quoting to the bash it |
| 201 | # replaced, so they need bash, lay pending out over real repositories, |
| 202 | # so they need git, and derive a change's checks under the verification |
| 203 | # schema, so they need cue and the schema. The plan's golden files |
| 204 | # (status/testdata/plan/) are valley-plan's, and no Go test reads them. |
| 205 | valley-go = goModule { |
| 206 | pname = "valley-go"; |
| 207 | dir = ../status; |
| 208 | modules = [ |
| 209 | ../change |
| 210 | ../composed |
| 211 | ../delta |
| 212 | ../derive |
| 213 | ../knot |
| 214 | ../note |
| 215 | ../rebase |
| 216 | ../selfupdate |
| 217 | ]; |
| 218 | excluded = [ ../status/testdata/plan ]; |
| 219 | preBuild = readsGoMod; |
| 220 | tests = { |
| 221 | reads = [ ../schema/verification.cue ]; |
| 222 | nativeCheckInputs = [ |
| 223 | pkgs.bash |
| 224 | pkgs.git |
| 225 | pkgs.cue |
| 226 | ]; |
| 227 | # A test that cannot find a tool it needs fails rather than skipping. |
| 228 | preCheck = '' |
| 229 | export VALLEY_TEST_TOOLS=required |
| 230 | ''; |
| 231 | }; |
| 232 | meta.mainProgram = "valley-go"; |
| 233 | }; |
| 234 | |
| 235 | # The check worker: one pass of `valley-go work` (status/worker.go), which |
| 236 | # builds the nix checks ready changes require and publishes the evidence |
| 237 | # before anyone approves them. It runs this flake's git, cue and attest, |
| 238 | # and the verification schema travels with it, as it does with the CLI. |
| 239 | # nix is the machine's own, for the reason attest gives. |
| 240 | valley-worker = |
| 241 | pkgs.runCommand "valley-worker" |
| 242 | { |
| 243 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 244 | meta.mainProgram = "valley-worker"; |
| 245 | } |
| 246 | '' |
| 247 | mkdir -p $out/bin |
| 248 | makeWrapper ${lib.getExe valley-go} $out/bin/valley-worker \ |
| 249 | --add-flags work \ |
| 250 | --prefix PATH : ${ |
| 251 | lib.makeBinPath [ |
| 252 | pkgs.git |
| 253 | pkgs.cue |
| 254 | attest |
| 255 | ] |
| 256 | } \ |
| 257 | --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} |
| 258 | ''; |
| 259 | |
| 260 | # `nix run .#fmt` — rewrap every tracked *.md in the repo to 100 columns. |
| 261 | prose-fmt = pkgs.writeShellApplication { |
| 262 | name = "valley-fmt"; |
| 263 | runtimeInputs = [ |
| 264 | pkgs.git |
| 265 | pkgs.prettier |
| 266 | ]; |
| 267 | text = '' |
| 268 | cd "$(git rev-parse --show-toplevel)" |
| 269 | git ls-files -z -- '*.md' | xargs -0 --no-run-if-empty \ |
| 270 | prettier ${proseFmtArgs} --write |
| 271 | ''; |
| 272 | }; |
| 273 | |
| 274 | # The Phase 2 attestation helper (dcr-0de694f). Go, standard library |
| 275 | # only, note format included, and hence no module fetch at build time. |
| 276 | # Its unit tests need git and ssh-keygen. It reads signed notes with the |
| 277 | # note module (../note), the one reading of the envelope shared by the |
| 278 | # programs that write, verify and admit attestations. The conformance |
| 279 | # vectors (attest/conformance/) are attest-conformance's, and no Go test |
| 280 | # reads them. |
| 281 | attest-unwrapped = goModule { |
| 282 | pname = "valley-attest"; |
| 283 | dir = ../attest; |
| 284 | modules = [ ../note ]; |
| 285 | excluded = [ ../attest/conformance ]; |
| 286 | preBuild = readsGoMod; |
| 287 | tests.nativeCheckInputs = [ |
| 288 | pkgs.git |
| 289 | pkgs.openssh |
| 290 | ]; |
| 291 | meta.mainProgram = "attest"; |
| 292 | }; |
| 293 | |
| 294 | # The shipping form. git and cue are pinned to this flake's nixpkgs, |
| 295 | # so every host composes and vets a statement with the same tools. |
| 296 | # Signing needs no tool at all: a note is signed on crypto/ed25519 |
| 297 | # inside the binary. `nix` is deliberately NOT pinned: the check being |
| 298 | # attested to must be built by the nix the machine actually runs, and |
| 299 | # a nix carried in here would be a second one. |
| 300 | attest = |
| 301 | pkgs.runCommand "valley-attest" |
| 302 | { |
| 303 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 304 | meta.mainProgram = "attest"; |
| 305 | } |
| 306 | '' |
| 307 | mkdir -p $out/bin |
| 308 | makeWrapper ${lib.getExe attest-unwrapped} $out/bin/attest \ |
| 309 | --prefix PATH : ${ |
| 310 | lib.makeBinPath [ |
| 311 | pkgs.git |
| 312 | pkgs.cue |
| 313 | ] |
| 314 | } \ |
| 315 | --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} |
| 316 | ''; |
| 317 | |
| 318 | # The identity registry compiler (dcr-b87f6e8). Go, standard library |
| 319 | # only, note format included, same trade as attest and the integrator, so |
| 320 | # no module is fetched. It reads the registry's export with exactjson |
| 321 | # (../exactjson). Its unit tests pin the note format's key hash |
| 322 | # against the reference vector attest is held to, and verify a real |
| 323 | # YubiKey attestation against the Yubico roots it carries. The test |
| 324 | # vectors (identity/testdata/) are read by the tests and by identity-e2e, |
| 325 | # never by the build. |
| 326 | identity-unwrapped = goModule { |
| 327 | pname = "valley-identity"; |
| 328 | dir = ../identity; |
| 329 | modules = [ |
| 330 | ../note |
| 331 | ../exactjson |
| 332 | ]; |
| 333 | preBuild = readsGoMod; |
| 334 | tests.reads = [ ../identity/testdata ]; |
| 335 | meta.mainProgram = "identity"; |
| 336 | }; |
| 337 | |
| 338 | # The shipping form. git reads the registry out of the instance |
| 339 | # repository's tip and cue vets and exports it, both pinned to this |
| 340 | # flake's nixpkgs so every host compiles a registry the same way. The |
| 341 | # schema travels with the binary: a compiler judging a registry against a |
| 342 | # schema the consumer supplied would be no floor at all. |
| 343 | identity = |
| 344 | pkgs.runCommand "valley-identity" |
| 345 | { |
| 346 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 347 | meta.mainProgram = "identity"; |
| 348 | } |
| 349 | '' |
| 350 | mkdir -p $out/bin |
| 351 | makeWrapper ${lib.getExe identity-unwrapped} $out/bin/identity \ |
| 352 | --prefix PATH : ${ |
| 353 | lib.makeBinPath [ |
| 354 | pkgs.git |
| 355 | pkgs.cue |
| 356 | ] |
| 357 | } \ |
| 358 | --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue} |
| 359 | ''; |
| 360 | |
| 361 | # The security-key signature verifier (sigverify/README.md). Go, |
| 362 | # standard library only, so no module is fetched. |
| 363 | # |
| 364 | # The git its git-tag command runs is fixed at build time to this |
| 365 | # flake's git, as an absolute store path compiled into the binary. A |
| 366 | # wrapper that puts git on PATH would leave the binary inside it looking |
| 367 | # git up on PATH, and a caller's environment could change which git that |
| 368 | # is. Compiled in, there is no PATH lookup to change. |
| 369 | # |
| 370 | # Its tests run against real ssh-keygen and git. The security-key cases |
| 371 | # among them need OpenSSH's sk-dummy authenticator, which the |
| 372 | # sigverify-unit check supplies. Building this package runs no test, so a |
| 373 | # consumer building it never builds OpenSSH. |
| 374 | sigverify = goModule { |
| 375 | pname = "valley-sigverify"; |
| 376 | dir = ../sigverify; |
| 377 | ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ]; |
| 378 | tests.nativeCheckInputs = [ |
| 379 | pkgs.git |
| 380 | pkgs.openssh |
| 381 | ]; |
| 382 | meta.mainProgram = "sigverify"; |
| 383 | }; |
| 384 | |
| 385 | # The pre-receive hook's policy (valleyhook/): what a push may write to a |
| 386 | # project a valley host serves. It validates a push to the plan graph |
| 387 | # with the one reading of a graph the CLI shares (../knot), and reads the |
| 388 | # project's push policy with exactjson (../exactjson). The same |
| 389 | # binary is the git user's login shell, which derives the pushing |
| 390 | # principal and pauses pushes until the host has converged. Go, standard |
| 391 | # library only, so no module is fetched. |
| 392 | # |
| 393 | # The git it reads the repository with is fixed at build time, the way |
| 394 | # sigverify's is: an absolute store path compiled into the binary, so no |
| 395 | # PATH a hook runs under can change which git that is. |
| 396 | valleyhook = goModule { |
| 397 | pname = "valley-valleyhook"; |
| 398 | dir = ../valleyhook; |
| 399 | modules = [ |
| 400 | ../note |
| 401 | ../change |
| 402 | ../knot |
| 403 | ../exactjson |
| 404 | ]; |
| 405 | preBuild = readsGoMod; |
| 406 | ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ]; |
| 407 | # The walk's and the change records' tests build hostile objects with |
| 408 | # real git. |
| 409 | tests.nativeCheckInputs = [ pkgs.git ]; |
| 410 | meta.mainProgram = "valleyhook"; |
| 411 | }; |
| 412 | |
| 413 | # The note envelope (note/). Its tests hold it to refusing every line a |
| 414 | # relayer could append that one of its readers would refuse. |
| 415 | note = goModule { |
| 416 | pname = "valley-note"; |
| 417 | dir = ../note; |
| 418 | }; |
| 419 | |
| 420 | # The strict JSON reading (exactjson/) that the identity compiler, the |
| 421 | # pre-receive hook and read access read CUE's exports with: every key |
| 422 | # spelled exactly as the field it is read into, and no key twice in one |
| 423 | # object. Its tests |
| 424 | # hold it to each spelling encoding/json alone would fold into a field. |
| 425 | exactjson = goModule { |
| 426 | pname = "valley-exactjson"; |
| 427 | dir = ../exactjson; |
| 428 | }; |
| 429 | |
| 430 | # The web UI (web/). Package export is the contract between the |
| 431 | # publisher on a valley host and the web server it pushes to: the public |
| 432 | # export and the projection onto it, the signed manifest, the upload and |
| 433 | # the receiver's state directory. It reads names and IDs by the plan |
| 434 | # graph's rules (../knot), the manifest with the note module (../note), |
| 435 | # and who may read a project through ../readaccess, which reads with |
| 436 | # ../exactjson. The program built |
| 437 | # from it is the publisher, cmd/valley-web-publish, which |
| 438 | # valley-web-publish below wraps. The server and its command are built by |
| 439 | # valley-web below, and the receiver by valley-web-receive. The export's |
| 440 | # tests accept bundles and build the shared fixture's repositories with |
| 441 | # real git. The publisher's tests run it against a valley built with real |
| 442 | # git and the CLI itself (bin/valley, run by bash, with valley-go on |
| 443 | # PATH), read each project's policy/read and the instance's identity |
| 444 | # registry with cue under schema/read.cue and schema/identity.cue, and |
| 445 | # upload to a receiver over a real store, and to the real receiver, whose |
| 446 | # state directory the real valley-web serves. One lands a change as the |
| 447 | # integrator does, with a transfer statement attest signs under a key |
| 448 | # ssh-keygen makes, which the CLI verifies with attest. go vet runs after |
| 449 | # them. The fixture's expected export |
| 450 | # (export/exporttest/testdata/) is read by the tests alone. Go, standard |
| 451 | # library only, so no module is fetched. |
| 452 | web = goModule { |
| 453 | pname = "valley-web-module"; |
| 454 | dir = ../web; |
| 455 | modules = [ |
| 456 | ../knot |
| 457 | ../note |
| 458 | ../readaccess |
| 459 | ../exactjson |
| 460 | ]; |
| 461 | excluded = [ |
| 462 | ../web/server |
| 463 | ../web/cmd/valley-web |
| 464 | ../web/cmd/valley-web-receive |
| 465 | ]; |
| 466 | preBuild = readsGoMod; |
| 467 | tests = { |
| 468 | reads = [ |
| 469 | ../web/export/exporttest/testdata |
| 470 | ../bin/valley |
| 471 | ../schema/read.cue |
| 472 | ../schema/identity.cue |
| 473 | ]; |
| 474 | nativeCheckInputs = [ |
| 475 | pkgs.git |
| 476 | pkgs.bash |
| 477 | pkgs.cue |
| 478 | pkgs.openssh |
| 479 | valley-go |
| 480 | attest |
| 481 | ]; |
| 482 | # A test that cannot find a tool it needs fails rather than skipping. |
| 483 | preCheck = '' |
| 484 | export VALLEY_TEST_TOOLS=required |
| 485 | export VALLEY_WEB=${lib.getExe valley-web} |
| 486 | export VALLEY_WEB_RECEIVE=${lib.getExe valley-web-receive} |
| 487 | ''; |
| 488 | postCheck = '' |
| 489 | go vet ./... |
| 490 | ''; |
| 491 | }; |
| 492 | meta.mainProgram = "valley-web-publish"; |
| 493 | }; |
| 494 | |
| 495 | # Read access (readaccess/): the two consents a principal needs to read a |
| 496 | # project, read out of git commits with cue under schema/read.cue and |
| 497 | # schema/identity.cue, and the evaluator that intersects them. The web |
| 498 | # publisher reads through it, and its command is the coverage report, |
| 499 | # which valley-read-coverage below wraps. It reads cue's exports with |
| 500 | # exactjson (../exactjson). Its tests read real commits with real git and |
| 501 | # the real cue under both schemas, and go vet runs after them. Go, |
| 502 | # standard library only, so no module is fetched. |
| 503 | readaccess = goModule { |
| 504 | pname = "valley-readaccess"; |
| 505 | dir = ../readaccess; |
| 506 | modules = [ ../exactjson ]; |
| 507 | preBuild = readsGoMod; |
| 508 | tests = { |
| 509 | reads = [ |
| 510 | ../schema/read.cue |
| 511 | ../schema/identity.cue |
| 512 | ]; |
| 513 | nativeCheckInputs = [ |
| 514 | pkgs.git |
| 515 | pkgs.cue |
| 516 | ]; |
| 517 | # A test that cannot find a tool it needs fails rather than skipping. |
| 518 | preCheck = '' |
| 519 | export VALLEY_TEST_TOOLS=required |
| 520 | ''; |
| 521 | postCheck = '' |
| 522 | go vet ./... |
| 523 | ''; |
| 524 | }; |
| 525 | meta.mainProgram = "valley-read-coverage"; |
| 526 | }; |
| 527 | |
| 528 | # The coverage report: which projects a principal cannot read at a |
| 529 | # destination, and which consent each lacks. It runs this flake's git and |
| 530 | # cue, and both schemas travel with it. |
| 531 | valley-read-coverage = |
| 532 | pkgs.runCommand "valley-read-coverage" |
| 533 | { |
| 534 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 535 | meta.mainProgram = "valley-read-coverage"; |
| 536 | } |
| 537 | '' |
| 538 | mkdir -p $out/bin |
| 539 | makeWrapper ${lib.getExe readaccess} $out/bin/valley-read-coverage \ |
| 540 | --prefix PATH : ${ |
| 541 | lib.makeBinPath [ |
| 542 | pkgs.git |
| 543 | pkgs.cue |
| 544 | ] |
| 545 | } \ |
| 546 | --set-default VALLEY_READ_SCHEMA ${../schema/read.cue} \ |
| 547 | --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue} |
| 548 | ''; |
| 549 | |
| 550 | # The web UI's server (web/server/) and its command, valley-web |
| 551 | # (web/cmd/valley-web/), which serves the active export of a receiver's |
| 552 | # state directory to anonymous readers. It reads the export and the |
| 553 | # state directory with package export, so its source is the web |
| 554 | # module, less the fixture's expected export, which only web's tests |
| 555 | # read. Of ../readaccess, which the publisher reads through and the |
| 556 | # server does not, and of ../exactjson, which readaccess reads with, it |
| 557 | # reads the go.mod alone, which go reads to resolve the module. The git it reads repositories with is fixed at build time, |
| 558 | # the way valleyhook's is. Its tests run the real program over the shared |
| 559 | # fixture and real git, and go vet runs after them. Go, standard library |
| 560 | # only, so no module is fetched. |
| 561 | valley-web = goModule { |
| 562 | pname = "valley-web"; |
| 563 | dir = ../web; |
| 564 | modules = [ |
| 565 | ../knot |
| 566 | ../note |
| 567 | ../readaccess/go.mod |
| 568 | ../exactjson/go.mod |
| 569 | ]; |
| 570 | excluded = [ |
| 571 | ../web/export/exporttest/testdata |
| 572 | ../web/cmd/valley-web-publish |
| 573 | ../web/cmd/valley-web-receive |
| 574 | ]; |
| 575 | subPackages = [ "cmd/valley-web" ]; |
| 576 | preBuild = readsGoMod; |
| 577 | ldflags = [ "-X the-valley/web/export.GitProgram=${lib.getExe pkgs.git}" ]; |
| 578 | tests = { |
| 579 | subPackages = [ |
| 580 | "server" |
| 581 | "cmd/valley-web" |
| 582 | ]; |
| 583 | nativeCheckInputs = [ pkgs.git ]; |
| 584 | postCheck = '' |
| 585 | go vet ./server/... ./cmd/valley-web/... |
| 586 | ''; |
| 587 | }; |
| 588 | meta.mainProgram = "valley-web"; |
| 589 | }; |
| 590 | |
| 591 | # The web export receiver, valley-web-receive (web/cmd/valley-web-receive/), |
| 592 | # which takes the publisher's uploads into a state directory that |
| 593 | # valley-web serves. Its source is the web module less the publisher, |
| 594 | # the server and its command, which it does not build, and the fixture's |
| 595 | # expected export; of ../readaccess and ../exactjson it reads the go.mod |
| 596 | # alone, as valley-web does. The git it accepts bundles with is fixed at |
| 597 | # build time. Its tests run the real program over the shared fixture and |
| 598 | # real git, with the real valley-web serving its state directory, and go |
| 599 | # vet runs after them. Go, standard library only. |
| 600 | valley-web-receive = goModule { |
| 601 | pname = "valley-web-receive"; |
| 602 | dir = ../web; |
| 603 | modules = [ |
| 604 | ../knot |
| 605 | ../note |
| 606 | ../readaccess/go.mod |
| 607 | ../exactjson/go.mod |
| 608 | ]; |
| 609 | excluded = [ |
| 610 | ../web/export/exporttest/testdata |
| 611 | ../web/cmd/valley-web-publish |
| 612 | ../web/cmd/valley-web |
| 613 | ../web/server |
| 614 | ]; |
| 615 | subPackages = [ "cmd/valley-web-receive" ]; |
| 616 | preBuild = readsGoMod; |
| 617 | ldflags = [ "-X the-valley/web/export.GitProgram=${lib.getExe pkgs.git}" ]; |
| 618 | tests = { |
| 619 | nativeCheckInputs = [ pkgs.git ]; |
| 620 | # A test that cannot find valley-web fails rather than skipping. |
| 621 | preCheck = '' |
| 622 | export VALLEY_TEST_TOOLS=required |
| 623 | export VALLEY_WEB=${lib.getExe valley-web} |
| 624 | ''; |
| 625 | postCheck = '' |
| 626 | go vet ./cmd/valley-web-receive/... |
| 627 | ''; |
| 628 | }; |
| 629 | meta.mainProgram = "valley-web-receive"; |
| 630 | }; |
| 631 | |
| 632 | # The web publisher: one pass of valley-web-publish, which reads a valley |
| 633 | # host's public projects through the CLI's JSON commands and uploads them |
| 634 | # to a web receiver. It runs this flake's git, cue and CLI, and the two |
| 635 | # schemas it reads read access under travel with it, as the verification |
| 636 | # schema does with the CLI. |
| 637 | valley-web-publish = |
| 638 | pkgs.runCommand "valley-web-publish" |
| 639 | { |
| 640 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 641 | meta.mainProgram = "valley-web-publish"; |
| 642 | } |
| 643 | '' |
| 644 | mkdir -p $out/bin |
| 645 | makeWrapper ${lib.getExe web} $out/bin/valley-web-publish \ |
| 646 | --prefix PATH : ${ |
| 647 | lib.makeBinPath [ |
| 648 | pkgs.git |
| 649 | pkgs.cue |
| 650 | valley-script |
| 651 | ] |
| 652 | } \ |
| 653 | --set-default VALLEY_READ_SCHEMA ${../schema/read.cue} \ |
| 654 | --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue} |
| 655 | ''; |
| 656 | |
| 657 | # The plan graph (knot/): its canonical form, its layout, cycles and |
| 658 | # transitions, held by its own tests. The package is knotcheck, which |
| 659 | # knot-agree runs to hold the Go validator to the CUE schema and the |
| 660 | # knowledge lint. |
| 661 | knot = goModule { |
| 662 | pname = "valley-knot"; |
| 663 | dir = ../knot; |
| 664 | meta.mainProgram = "knotcheck"; |
| 665 | }; |
| 666 | |
| 667 | # The rebase engine (rebase/): a family of stacked changes captured from |
| 668 | # one snapshot of origin, rebased in a throwaway worktree, and published |
| 669 | # as one atomic branch push and one record append per change. Its tests |
| 670 | # run against real repositories, real pushes and real git, with go vet |
| 671 | # after them. Go, standard library only, so no module is fetched. |
| 672 | rebase = goModule { |
| 673 | pname = "valley-rebase"; |
| 674 | dir = ../rebase; |
| 675 | modules = [ ../change ]; |
| 676 | preBuild = readsGoMod; |
| 677 | tests = { |
| 678 | nativeCheckInputs = [ pkgs.git ]; |
| 679 | postCheck = '' |
| 680 | go vet ./... |
| 681 | ''; |
| 682 | }; |
| 683 | }; |
| 684 | |
| 685 | # Self-update (selfupdate/): the installed CLI brought up to the tip of a |
| 686 | # branch, built with nix and installed into the user's profile. Its tests, |
| 687 | # with go vet after them, use a real bare repository for ls-remote and a |
| 688 | # stand-in for nix whose builds are small scripts, so nothing is built and |
| 689 | # no profile is touched. Go, standard library only, so no module is |
| 690 | # fetched. |
| 691 | selfupdate = goModule { |
| 692 | pname = "valley-selfupdate"; |
| 693 | dir = ../selfupdate; |
| 694 | tests = { |
| 695 | nativeCheckInputs = [ pkgs.git ]; |
| 696 | postCheck = '' |
| 697 | go vet ./... |
| 698 | ''; |
| 699 | }; |
| 700 | }; |
| 701 | |
| 702 | # The deriver of required checks (derive/): a change's paths read from |
| 703 | # git diff -z, globs matched byte by byte, and the required checks, pins, |
| 704 | # carry mode and unclassified paths derived from the whole composed |
| 705 | # policy (../composed). Its tests, with go vet after them, hold it to |
| 706 | # bin/valley's deriver, run over the repository's own policy, the example |
| 707 | # policies and paths drawn from a fixed seed. So the tests read |
| 708 | # bin/valley, the schema and those policies, and need bash, git and cue. |
| 709 | # bin/valley is run under C.UTF-8 and en_US.UTF-8 as well as C, so the |
| 710 | # tests read the UTF-8 locales' archive. Go, standard library only, so no |
| 711 | # module is fetched. |
| 712 | derive = goModule { |
| 713 | pname = "valley-derive"; |
| 714 | dir = ../derive; |
| 715 | modules = [ ../composed ]; |
| 716 | preBuild = readsGoMod; |
| 717 | tests = { |
| 718 | reads = [ |
| 719 | ../bin/valley |
| 720 | ../schema/verification.cue |
| 721 | ../examples/policy |
| 722 | ../policy/project |
| 723 | ]; |
| 724 | nativeCheckInputs = [ |
| 725 | pkgs.bash |
| 726 | pkgs.git |
| 727 | pkgs.cue |
| 728 | ]; |
| 729 | # A test that cannot find a tool it needs, or a locale, fails rather |
| 730 | # than skipping. |
| 731 | preCheck = '' |
| 732 | export VALLEY_TEST_TOOLS=required |
| 733 | export LOCALE_ARCHIVE=${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive |
| 734 | ''; |
| 735 | postCheck = '' |
| 736 | go vet ./... |
| 737 | ''; |
| 738 | }; |
| 739 | }; |
| 740 | |
| 741 | # The change record (change/). Its tests cover its strict reading, its |
| 742 | # fuzz target's seed corpus, and its branch-name rule, which they hold to |
| 743 | # real git's check-ref-format. |
| 744 | change = goModule { |
| 745 | pname = "valley-change"; |
| 746 | dir = ../change; |
| 747 | tests.nativeCheckInputs = [ pkgs.git ]; |
| 748 | }; |
| 749 | |
| 750 | # valley-delta-v1 (delta/): the encoding's strict reading, and the delta |
| 751 | # read from real trees. Its unit tests run go vet, the conformance |
| 752 | # vectors' script in its --check mode, which holds the committed expected |
| 753 | # results to what the script computes, and go test, which builds each |
| 754 | # vector's trees with real git and holds the Go code to those results. |
| 755 | delta = goModule { |
| 756 | pname = "valley-delta"; |
| 757 | dir = ../delta; |
| 758 | tests = { |
| 759 | reads = [ ../delta/testdata ]; |
| 760 | nativeCheckInputs = [ |
| 761 | pkgs.git |
| 762 | pkgs.python3 |
| 763 | ]; |
| 764 | preCheck = '' |
| 765 | go vet ./... |
| 766 | python3 -I testdata/vectors.py --check testdata |
| 767 | ''; |
| 768 | }; |
| 769 | }; |
| 770 | |
| 771 | # Review records (review/): the-valley/review/v1's strict reading, a |
| 772 | # review's binding to the version it judged, recomputed from git within a |
| 773 | # budget, and the append-only history a review is kept in, with the check |
| 774 | # an append is held to. It reads change records with the one reading of a |
| 775 | # record the push hook shares (../change), and the delta with |
| 776 | # valley-delta-v1's bounded reading (../delta). Its tests build every |
| 777 | # repository they read with real git and run its fuzz target's seed |
| 778 | # corpus, and go vet runs after them. Go, standard library only, so no |
| 779 | # module is fetched. |
| 780 | review = goModule { |
| 781 | pname = "valley-review"; |
| 782 | dir = ../review; |
| 783 | modules = [ |
| 784 | ../change |
| 785 | ../delta |
| 786 | ]; |
| 787 | preBuild = readsGoMod; |
| 788 | tests = { |
| 789 | nativeCheckInputs = [ pkgs.git ]; |
| 790 | postCheck = '' |
| 791 | go vet ./... |
| 792 | ''; |
| 793 | }; |
| 794 | }; |
| 795 | |
| 796 | # The restacker (restack/): `valley-restacker run` reconciles on an |
| 797 | # interval, and `once` is one pass. A pass reads origin through the |
| 798 | # rebase engine (../rebase), plans which families to restack and which |
| 799 | # to hold, keeps the writes in its journal, and pushes them; |
| 800 | # `once --report-only` pushes none. It reads the cap on its |
| 801 | # automatic versions through the composed-policy reader it shares with |
| 802 | # the integrator (../composed), and a signer projects file through the |
| 803 | # note module (../note). Its unit tests cover request association, |
| 804 | # outcome currency, capacity and report bounds, and, against real git, |
| 805 | # the journal of writes, recovery's decisions and publishing through the |
| 806 | # rendered hook, its environment, its |
| 807 | # scratch repository's identity, its state directory's lock and binding, |
| 808 | # and the deadline on what it runs. go vet runs after them. Go, standard |
| 809 | # library only, so no module is fetched. |
| 810 | restack-unwrapped = goModule { |
| 811 | pname = "valley-restacker"; |
| 812 | dir = ../restack; |
| 813 | modules = [ |
| 814 | ../change |
| 815 | ../composed |
| 816 | ../note |
| 817 | ../rebase |
| 818 | ]; |
| 819 | # The program alone: e2e/transport is a module of restack-e2e's own, |
| 820 | # which neither this build nor its tests read. |
| 821 | excluded = [ ../restack/e2e ]; |
| 822 | subPackages = [ "." ]; |
| 823 | preBuild = readsGoMod; |
| 824 | tests = { |
| 825 | nativeCheckInputs = [ pkgs.git ]; |
| 826 | postCheck = '' |
| 827 | go vet ./... |
| 828 | ''; |
| 829 | }; |
| 830 | # The module is named for its directory; the program, for what it is. |
| 831 | postInstall = '' |
| 832 | mv $out/bin/restack $out/bin/valley-restacker |
| 833 | ''; |
| 834 | meta.mainProgram = "valley-restacker"; |
| 835 | }; |
| 836 | |
| 837 | # The shipping form: git to read origin, cue to compose the policy, and |
| 838 | # attest to check a transfer statement, all pinned to this flake's |
| 839 | # nixpkgs, with the packaged verification schema as the default. |
| 840 | valley-restacker = |
| 841 | pkgs.runCommand "valley-restacker" |
| 842 | { |
| 843 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 844 | meta.mainProgram = "valley-restacker"; |
| 845 | } |
| 846 | '' |
| 847 | mkdir -p $out/bin |
| 848 | makeWrapper ${lib.getExe restack-unwrapped} $out/bin/valley-restacker \ |
| 849 | --prefix PATH : ${ |
| 850 | lib.makeBinPath [ |
| 851 | pkgs.git |
| 852 | pkgs.cue |
| 853 | attest |
| 854 | ] |
| 855 | } \ |
| 856 | --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} |
| 857 | ''; |
| 858 | |
| 859 | # The Phase 3 integrator (dcr-439b771). Go, standard library only, |
| 860 | # same trade as attest, so no module is fetched. It reads change records |
| 861 | # with the one reading of a record the push hook shares (../change), and |
| 862 | # verifier keys with the one reading of a key the note format defines |
| 863 | # (../note). |
| 864 | integrator-unwrapped = goModule { |
| 865 | pname = "valley-integrator"; |
| 866 | dir = ../integrator; |
| 867 | modules = [ |
| 868 | ../change |
| 869 | ../composed |
| 870 | ../note |
| 871 | ]; |
| 872 | # The scenarios (integrator/e2e/) are integrator-e2e's, and no Go test |
| 873 | # reads them. |
| 874 | excluded = [ ../integrator/e2e ]; |
| 875 | preBuild = readsGoMod; |
| 876 | tests = { |
| 877 | # The policy bridge's tests compose a policy under the verification |
| 878 | # schema with real cue, and check a deriver's report against real git. |
| 879 | reads = [ ../schema/verification.cue ]; |
| 880 | nativeCheckInputs = [ |
| 881 | pkgs.git |
| 882 | pkgs.cue |
| 883 | ]; |
| 884 | }; |
| 885 | meta.mainProgram = "integrator"; |
| 886 | }; |
| 887 | |
| 888 | # The shipping form. The integrator drives four programs rather than |
| 889 | # reimplementing what they do: attest judges every statement and |
| 890 | # every note, the valley deriver and cue compose the policy, and git |
| 891 | # holds the requests and the refs. All four are pinned to this |
| 892 | # flake's nixpkgs so an instance's integrators agree; `nix` is |
| 893 | # deliberately absent for the same reason it is absent from attest — |
| 894 | # a closure must be recomputed by the nix the machine actually runs. |
| 895 | integrator = |
| 896 | pkgs.runCommand "valley-integrator" |
| 897 | { |
| 898 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 899 | meta.mainProgram = "integrator"; |
| 900 | } |
| 901 | '' |
| 902 | mkdir -p $out/bin |
| 903 | makeWrapper ${lib.getExe integrator-unwrapped} $out/bin/integrator \ |
| 904 | --prefix PATH : ${ |
| 905 | lib.makeBinPath [ |
| 906 | pkgs.git |
| 907 | pkgs.cue |
| 908 | pkgs.natscli |
| 909 | attest |
| 910 | valley-script |
| 911 | ] |
| 912 | } \ |
| 913 | --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} \ |
| 914 | --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} \ |
| 915 | --set-default VALLEY_EVENT_SCHEMA ${../schema/events.cue} |
| 916 | ''; |
| 917 | } |