| 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 | # The source of a Go program that uses modules of this repository: its own |
| 35 | # directory and those modules, which its go.mod replaces with their local |
| 36 | # directories, each in its place in the tree. Nothing shared this way is |
| 37 | # fetched. withLocalExcept also leaves out the paths in its last argument, |
| 38 | # which are files of the directory that only a flake check reads, never |
| 39 | # the package's build or tests. |
| 40 | withLocalExcept = |
| 41 | dir: modules: excluded: |
| 42 | lib.fileset.toSource { |
| 43 | root = ../.; |
| 44 | fileset = lib.fileset.difference (lib.fileset.unions ([ dir ] ++ modules)) ( |
| 45 | lib.fileset.unions ([ unread ] ++ excluded) |
| 46 | ); |
| 47 | }; |
| 48 | withLocal = dir: modules: withLocalExcept dir modules [ ]; |
| 49 | |
| 50 | # The source of a Go module that uses no other module of this repository: |
| 51 | # its own directory. |
| 52 | ownSource = |
| 53 | dir: |
| 54 | lib.fileset.toSource { |
| 55 | root = dir; |
| 56 | fileset = lib.fileset.difference dir unread; |
| 57 | }; |
| 58 | |
| 59 | # vendorHash = null builds in vendor mode, which has no reading of a local |
| 60 | # replace. The replaced module is a directory beside the program and |
| 61 | # nothing is fetched either way, so these builds read go.mod as written. |
| 62 | readsGoMod = '' |
| 63 | export GOFLAGS="''${GOFLAGS//-mod=vendor/-mod=mod}" |
| 64 | ''; |
| 65 | |
| 66 | # Markdown prose is filled paragraphs hard-wrapped at 100 columns |
| 67 | # (ida-1ec03b1). One flag string backs both the formatter app and the |
| 68 | # prose-format check, so the two cannot drift. Embedded-language |
| 69 | # formatting is off so fenced code blocks pass through byte-for-byte. |
| 70 | proseFmtArgs = "--prose-wrap always --print-width 100 --embedded-language-formatting off"; |
| 71 | |
| 72 | # The integrator's CLI (bin/valley) wrapped for `nix run`. The script |
| 73 | # itself must keep running bare from any checkout — the package is the |
| 74 | # second of its two shipping modes, never a dependency of the first. |
| 75 | valley-script-unwrapped = pkgs.writeShellApplication { |
| 76 | name = "valley"; |
| 77 | runtimeInputs = [ |
| 78 | pkgs.git |
| 79 | pkgs.natscli # tail and replay only; every other verb needs just git |
| 80 | pkgs.cue # checks and approving — it composes the policy layers |
| 81 | pkgs.less # review only — its v key is what takes a note |
| 82 | attest # approving only — it runs the checks and signs them |
| 83 | valley-go # status, ready, unready, withdraw and rebase, naming a change by its ID, and pending's drafts |
| 84 | ]; |
| 85 | text = builtins.readFile ../bin/valley; |
| 86 | }; |
| 87 | |
| 88 | # The shipping form. The verification schema travels with the script, as |
| 89 | # it does with the integrator: only the-valley's own tree carries |
| 90 | # schema/, so a project's checkout has none to read. --set-default leaves |
| 91 | # an explicit VALLEY_VERIFICATION_SCHEMA in charge. |
| 92 | valley-script = |
| 93 | pkgs.runCommand "valley" |
| 94 | { |
| 95 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 96 | meta.mainProgram = "valley"; |
| 97 | } |
| 98 | '' |
| 99 | mkdir -p $out/bin |
| 100 | makeWrapper ${lib.getExe valley-script-unwrapped} $out/bin/valley \ |
| 101 | --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} |
| 102 | ''; |
| 103 | |
| 104 | # The installed package: the wrapped script stamped with its version, the |
| 105 | # shell completions at the standard paths home-manager/NixOS auto-link, |
| 106 | # and the tiny policy self-update's smoke test derives checks from |
| 107 | # (examples/policy/smoke/). The stamp is set on this outer wrapper alone, |
| 108 | # so the packages the checks and the integrator use do not change with |
| 109 | # every commit. The name carries the version as well: nix profile names |
| 110 | # the element valley from it, and self-update reads a hand-installed |
| 111 | # valley's commit from it. |
| 112 | valley = |
| 113 | pkgs.runCommand "valley-${version}" |
| 114 | { |
| 115 | inherit version; |
| 116 | nativeBuildInputs = [ |
| 117 | pkgs.makeWrapper |
| 118 | pkgs.installShellFiles |
| 119 | ]; |
| 120 | meta.mainProgram = "valley"; |
| 121 | } |
| 122 | '' |
| 123 | mkdir -p $out/bin $out/share/valley |
| 124 | makeWrapper ${lib.getExe valley-script} $out/bin/valley \ |
| 125 | --set VALLEY_VERSION ${version} |
| 126 | installShellCompletion --bash --name valley ${../completions/valley.bash} |
| 127 | installShellCompletion --zsh --name _valley ${../completions/_valley} |
| 128 | cp -r --no-preserve=mode ${../examples/policy/smoke} $out/share/valley/smoke-policy |
| 129 | ''; |
| 130 | |
| 131 | # The verbs of the CLI written in Go (status/). status reads one change's |
| 132 | # request and outcome record from origin, and prints them as sentences or |
| 133 | # as the valley-status/v1 JSON object front ends read. ready, unready and |
| 134 | # withdraw write a change's record, with the one reading of a record the |
| 135 | # push hook shares (../change). rebase rebases a change's whole stack and |
| 136 | # adds each change's rebased head to its record, through the rebase engine |
| 137 | # (../rebase), which also reads how far each version has landed for the |
| 138 | # listings. knot reads and writes the plan graph, with the one reading of |
| 139 | # a graph the push hook shares (../knot), and plan shows that graph as a |
| 140 | # view. compare reads a version's file delta and its approved version's |
| 141 | # with the one reading of valley-delta-v1 (../delta), for review. |
| 142 | # self-update installs the tip of a branch of the-valley into the user's |
| 143 | # nix profile (../selfupdate). checks prints which checks a change |
| 144 | # requires, as the deriver (../derive) derives them from the policy the |
| 145 | # composed-policy reader (../composed) reads. Go, |
| 146 | # standard library only — hence vendorHash = null and no module fetch. It |
| 147 | # runs whatever git and cue are on PATH, which inside the CLI's package |
| 148 | # are the CLI's own. Its unit tests hold its shell quoting to the bash it |
| 149 | # replaced, so they need bash, lay pending out over real repositories, |
| 150 | # so they need git, and derive a change's checks under the verification |
| 151 | # schema, so they need cue and the schema. The plan's golden files |
| 152 | # (status/testdata/plan/) are valley-plan's, and no Go test reads them. |
| 153 | valley-go = pkgs.buildGoModule { |
| 154 | pname = "valley-go"; |
| 155 | version = "0"; |
| 156 | src = |
| 157 | withLocalExcept ../status |
| 158 | [ |
| 159 | ../change |
| 160 | ../composed |
| 161 | ../delta |
| 162 | ../derive |
| 163 | ../knot |
| 164 | ../note |
| 165 | ../rebase |
| 166 | ../selfupdate |
| 167 | ../schema/verification.cue |
| 168 | ] |
| 169 | [ ../status/testdata/plan ]; |
| 170 | modRoot = "status"; |
| 171 | vendorHash = null; |
| 172 | preBuild = readsGoMod; |
| 173 | nativeCheckInputs = [ |
| 174 | pkgs.bash |
| 175 | pkgs.git |
| 176 | pkgs.cue |
| 177 | ]; |
| 178 | # A test that cannot find a tool it needs fails rather than skipping. |
| 179 | preCheck = '' |
| 180 | export VALLEY_TEST_TOOLS=required |
| 181 | ''; |
| 182 | meta.mainProgram = "valley-go"; |
| 183 | }; |
| 184 | |
| 185 | # The check worker: one pass of `valley-go work` (status/worker.go), which |
| 186 | # builds the nix checks ready changes require and publishes the evidence |
| 187 | # before anyone approves them. It runs this flake's git, cue and attest, |
| 188 | # and the verification schema travels with it, as it does with the CLI. |
| 189 | # nix is the machine's own, for the reason attest gives. |
| 190 | valley-worker = |
| 191 | pkgs.runCommand "valley-worker" |
| 192 | { |
| 193 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 194 | meta.mainProgram = "valley-worker"; |
| 195 | } |
| 196 | '' |
| 197 | mkdir -p $out/bin |
| 198 | makeWrapper ${lib.getExe valley-go} $out/bin/valley-worker \ |
| 199 | --add-flags work \ |
| 200 | --prefix PATH : ${ |
| 201 | lib.makeBinPath [ |
| 202 | pkgs.git |
| 203 | pkgs.cue |
| 204 | attest |
| 205 | ] |
| 206 | } \ |
| 207 | --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} |
| 208 | ''; |
| 209 | |
| 210 | # `nix run .#fmt` — rewrap every tracked *.md in the repo to 100 columns. |
| 211 | prose-fmt = pkgs.writeShellApplication { |
| 212 | name = "valley-fmt"; |
| 213 | runtimeInputs = [ |
| 214 | pkgs.git |
| 215 | pkgs.prettier |
| 216 | ]; |
| 217 | text = '' |
| 218 | cd "$(git rev-parse --show-toplevel)" |
| 219 | git ls-files -z -- '*.md' | xargs -0 --no-run-if-empty \ |
| 220 | prettier ${proseFmtArgs} --write |
| 221 | ''; |
| 222 | }; |
| 223 | |
| 224 | # The Phase 2 attestation helper (dcr-0de694f). Go, standard library |
| 225 | # only, note format included — hence vendorHash = null, and hence no |
| 226 | # module fetch at build time. Its unit tests run in the checkPhase and |
| 227 | # need git and ssh-keygen. It reads signed notes with the note module |
| 228 | # (../note), the one reading of the envelope shared by the programs that |
| 229 | # write, verify and admit attestations. The conformance vectors |
| 230 | # (attest/conformance/) are attest-conformance's, and no Go test reads |
| 231 | # them. |
| 232 | attest-unwrapped = pkgs.buildGoModule { |
| 233 | pname = "valley-attest"; |
| 234 | version = "0"; |
| 235 | src = withLocalExcept ../attest [ ../note ] [ ../attest/conformance ]; |
| 236 | modRoot = "attest"; |
| 237 | vendorHash = null; |
| 238 | preBuild = readsGoMod; |
| 239 | nativeCheckInputs = [ |
| 240 | pkgs.git |
| 241 | pkgs.openssh |
| 242 | ]; |
| 243 | meta.mainProgram = "attest"; |
| 244 | }; |
| 245 | |
| 246 | # The shipping form. git and cue are pinned to this flake's nixpkgs, |
| 247 | # so every host composes and vets a statement with the same tools. |
| 248 | # Signing needs no tool at all: a note is signed on crypto/ed25519 |
| 249 | # inside the binary. `nix` is deliberately NOT pinned: the check being |
| 250 | # attested to must be built by the nix the machine actually runs, and |
| 251 | # a nix carried in here would be a second one. |
| 252 | attest = |
| 253 | pkgs.runCommand "valley-attest" |
| 254 | { |
| 255 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 256 | meta.mainProgram = "attest"; |
| 257 | } |
| 258 | '' |
| 259 | mkdir -p $out/bin |
| 260 | makeWrapper ${lib.getExe attest-unwrapped} $out/bin/attest \ |
| 261 | --prefix PATH : ${ |
| 262 | lib.makeBinPath [ |
| 263 | pkgs.git |
| 264 | pkgs.cue |
| 265 | ] |
| 266 | } \ |
| 267 | --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} |
| 268 | ''; |
| 269 | |
| 270 | # The identity registry compiler (dcr-b87f6e8). Go, standard library |
| 271 | # only, note format included, same trade as attest and the integrator — |
| 272 | # hence vendorHash = null and no module fetch. Its unit tests pin the |
| 273 | # note format's key hash against the reference vector attest is held to, |
| 274 | # and verify a real YubiKey attestation against the Yubico roots it |
| 275 | # carries. |
| 276 | identity-unwrapped = pkgs.buildGoModule { |
| 277 | pname = "valley-identity"; |
| 278 | version = "0"; |
| 279 | src = withLocal ../identity [ ../note ]; |
| 280 | modRoot = "identity"; |
| 281 | vendorHash = null; |
| 282 | preBuild = readsGoMod; |
| 283 | meta.mainProgram = "identity"; |
| 284 | }; |
| 285 | |
| 286 | # The shipping form. git reads the registry out of the instance |
| 287 | # repository's tip and cue vets and exports it, both pinned to this |
| 288 | # flake's nixpkgs so every host compiles a registry the same way. The |
| 289 | # schema travels with the binary: a compiler judging a registry against a |
| 290 | # schema the consumer supplied would be no floor at all. |
| 291 | identity = |
| 292 | pkgs.runCommand "valley-identity" |
| 293 | { |
| 294 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 295 | meta.mainProgram = "identity"; |
| 296 | } |
| 297 | '' |
| 298 | mkdir -p $out/bin |
| 299 | makeWrapper ${lib.getExe identity-unwrapped} $out/bin/identity \ |
| 300 | --prefix PATH : ${ |
| 301 | lib.makeBinPath [ |
| 302 | pkgs.git |
| 303 | pkgs.cue |
| 304 | ] |
| 305 | } \ |
| 306 | --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue} |
| 307 | ''; |
| 308 | |
| 309 | # The security-key signature verifier (sigverify/README.md). Go, |
| 310 | # standard library only — hence vendorHash = null and no module fetch. |
| 311 | # |
| 312 | # The git its git-tag command runs is fixed at build time to this |
| 313 | # flake's git, as an absolute store path compiled into the binary. A |
| 314 | # wrapper that puts git on PATH would leave the binary inside it looking |
| 315 | # git up on PATH, and a caller's environment could change which git that |
| 316 | # is. Compiled in, there is no PATH lookup to change. |
| 317 | # |
| 318 | # Its tests run in the checkPhase against real ssh-keygen and git. The |
| 319 | # security-key cases among them need OpenSSH's sk-dummy authenticator, |
| 320 | # which only the sigverify-unit check supplies; here they skip, so a |
| 321 | # consumer building this package never builds OpenSSH. |
| 322 | sigverify = pkgs.buildGoModule { |
| 323 | pname = "valley-sigverify"; |
| 324 | version = "0"; |
| 325 | src = ownSource ../sigverify; |
| 326 | vendorHash = null; |
| 327 | ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ]; |
| 328 | nativeCheckInputs = [ |
| 329 | pkgs.git |
| 330 | pkgs.openssh |
| 331 | ]; |
| 332 | meta.mainProgram = "sigverify"; |
| 333 | }; |
| 334 | |
| 335 | # The pre-receive hook's policy (valleyhook/): what a push may write to a |
| 336 | # project a valley host serves. It validates a push to the plan graph |
| 337 | # with the one reading of a graph the CLI shares (../knot). The same binary is the git user's login |
| 338 | # shell, which derives the pushing principal and pauses pushes until the |
| 339 | # host has converged. Go, standard library only — hence |
| 340 | # vendorHash = null and no module fetch. Its unit tests run in the |
| 341 | # checkPhase. |
| 342 | # |
| 343 | # The git it reads the repository with is fixed at build time, the way |
| 344 | # sigverify's is: an absolute store path compiled into the binary, so no |
| 345 | # PATH a hook runs under can change which git that is. |
| 346 | valleyhook = pkgs.buildGoModule { |
| 347 | pname = "valley-valleyhook"; |
| 348 | version = "0"; |
| 349 | src = withLocal ../valleyhook [ |
| 350 | ../note |
| 351 | ../change |
| 352 | ../knot |
| 353 | ]; |
| 354 | modRoot = "valleyhook"; |
| 355 | vendorHash = null; |
| 356 | preBuild = readsGoMod; |
| 357 | ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ]; |
| 358 | # The walk's and the change records' tests build hostile objects with |
| 359 | # real git. |
| 360 | nativeCheckInputs = [ pkgs.git ]; |
| 361 | meta.mainProgram = "valleyhook"; |
| 362 | }; |
| 363 | |
| 364 | # The note envelope's own tests, which hold it to refusing every line a |
| 365 | # relayer could append that one of its readers would refuse. |
| 366 | note = pkgs.buildGoModule { |
| 367 | pname = "valley-note"; |
| 368 | version = "0"; |
| 369 | src = ownSource ../note; |
| 370 | vendorHash = null; |
| 371 | }; |
| 372 | |
| 373 | # The plan graph (knot/): its canonical form, its layout, cycles and |
| 374 | # transitions, held by its own tests. The package is knotcheck, which |
| 375 | # knot-agree runs to hold the Go validator to the CUE schema and the |
| 376 | # knowledge lint. |
| 377 | knot = pkgs.buildGoModule { |
| 378 | pname = "valley-knot"; |
| 379 | version = "0"; |
| 380 | src = ownSource ../knot; |
| 381 | vendorHash = null; |
| 382 | meta.mainProgram = "knotcheck"; |
| 383 | }; |
| 384 | |
| 385 | # The rebase engine (rebase/): a family of stacked changes captured from |
| 386 | # one snapshot of origin, rebased in a throwaway worktree, and published |
| 387 | # as one atomic branch push and one record append per change. Building |
| 388 | # valley-go does not run a module's tests that it only imports, so this |
| 389 | # package runs the engine's: go test, against real repositories, real |
| 390 | # pushes and real git, and go vet. Go, standard library only — hence |
| 391 | # vendorHash = null and no module fetch. |
| 392 | rebase = pkgs.buildGoModule { |
| 393 | pname = "valley-rebase"; |
| 394 | version = "0"; |
| 395 | src = withLocal ../rebase [ ../change ]; |
| 396 | modRoot = "rebase"; |
| 397 | vendorHash = null; |
| 398 | preBuild = readsGoMod; |
| 399 | nativeCheckInputs = [ pkgs.git ]; |
| 400 | postCheck = '' |
| 401 | go vet ./... |
| 402 | ''; |
| 403 | }; |
| 404 | |
| 405 | # Self-update (selfupdate/): the installed CLI brought up to the tip of a |
| 406 | # branch, built with nix and installed into the user's profile. Building |
| 407 | # valley-go does not run the tests of a module it only imports, so this |
| 408 | # package runs them, and go vet: a real bare repository for ls-remote, |
| 409 | # and a stand-in for nix whose builds are small scripts, so nothing is |
| 410 | # built and no profile is touched. Go, standard library only — hence |
| 411 | # vendorHash = null and no module fetch. |
| 412 | selfupdate = pkgs.buildGoModule { |
| 413 | pname = "valley-selfupdate"; |
| 414 | version = "0"; |
| 415 | src = ownSource ../selfupdate; |
| 416 | vendorHash = null; |
| 417 | nativeCheckInputs = [ pkgs.git ]; |
| 418 | postCheck = '' |
| 419 | go vet ./... |
| 420 | ''; |
| 421 | }; |
| 422 | |
| 423 | # The deriver of required checks (derive/): a change's paths read from |
| 424 | # git diff -z, globs matched byte by byte, and the required checks, pins, |
| 425 | # carry mode and unclassified paths derived from the whole composed |
| 426 | # policy (../composed). Building valley-go does not run the tests of a |
| 427 | # module it only imports, so this package runs them, and go vet. They |
| 428 | # hold it to bin/valley's deriver, run over the repository's own policy, |
| 429 | # the example policies and paths drawn from a fixed seed, so the source |
| 430 | # carries bin/valley, the schema and those policies, and the tests need |
| 431 | # bash, git and cue. bin/valley is run under C.UTF-8 and en_US.UTF-8 as |
| 432 | # well as C, so the tests read the UTF-8 locales' archive. Go, standard |
| 433 | # library only — hence vendorHash = null and no module fetch. |
| 434 | derive = pkgs.buildGoModule { |
| 435 | pname = "valley-derive"; |
| 436 | version = "0"; |
| 437 | src = withLocal ../derive [ |
| 438 | ../composed |
| 439 | ../bin/valley |
| 440 | ../schema/verification.cue |
| 441 | ../examples/policy |
| 442 | ../policy/project |
| 443 | ]; |
| 444 | modRoot = "derive"; |
| 445 | vendorHash = null; |
| 446 | preBuild = readsGoMod; |
| 447 | nativeCheckInputs = [ |
| 448 | pkgs.bash |
| 449 | pkgs.git |
| 450 | pkgs.cue |
| 451 | ]; |
| 452 | # A test that cannot find a tool it needs, or a locale, fails rather |
| 453 | # than skipping. |
| 454 | preCheck = '' |
| 455 | export VALLEY_TEST_TOOLS=required |
| 456 | export LOCALE_ARCHIVE=${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive |
| 457 | ''; |
| 458 | postCheck = '' |
| 459 | go vet ./... |
| 460 | ''; |
| 461 | }; |
| 462 | |
| 463 | # The change record's own tests: its strict reading, its fuzz target's |
| 464 | # seed corpus, and its branch-name rule, which they hold to real git's |
| 465 | # check-ref-format. |
| 466 | change = pkgs.buildGoModule { |
| 467 | pname = "valley-change"; |
| 468 | version = "0"; |
| 469 | src = ownSource ../change; |
| 470 | vendorHash = null; |
| 471 | nativeCheckInputs = [ pkgs.git ]; |
| 472 | }; |
| 473 | |
| 474 | # valley-delta-v1 (delta/): the encoding's strict reading, and the delta |
| 475 | # read from real trees. Its checkPhase runs go vet, the conformance |
| 476 | # vectors' script in its --check mode, which holds the committed expected |
| 477 | # results to what the script computes, and go test, which builds each |
| 478 | # vector's trees with real git and holds the Go code to those results. |
| 479 | delta = pkgs.buildGoModule { |
| 480 | pname = "valley-delta"; |
| 481 | version = "0"; |
| 482 | src = ownSource ../delta; |
| 483 | vendorHash = null; |
| 484 | nativeCheckInputs = [ |
| 485 | pkgs.git |
| 486 | pkgs.python3 |
| 487 | ]; |
| 488 | preCheck = '' |
| 489 | go vet ./... |
| 490 | python3 -I testdata/vectors.py --check testdata |
| 491 | ''; |
| 492 | }; |
| 493 | |
| 494 | # Review records (review/): the-valley/review/v1's strict reading, a |
| 495 | # review's binding to the version it judged, recomputed from git within a |
| 496 | # budget, and the append-only history a review is kept in, with the check |
| 497 | # an append is held to. It reads change records with the one reading of a |
| 498 | # record the push hook shares (../change), and the delta with |
| 499 | # valley-delta-v1's bounded reading (../delta). Its checkPhase runs go |
| 500 | # test, which builds every repository it reads with real git, its fuzz |
| 501 | # target's seed corpus, and then go vet. Go, standard library only — |
| 502 | # hence vendorHash = null and no module fetch. |
| 503 | review = pkgs.buildGoModule { |
| 504 | pname = "valley-review"; |
| 505 | version = "0"; |
| 506 | src = withLocal ../review [ |
| 507 | ../change |
| 508 | ../delta |
| 509 | ]; |
| 510 | modRoot = "review"; |
| 511 | vendorHash = null; |
| 512 | preBuild = readsGoMod; |
| 513 | nativeCheckInputs = [ pkgs.git ]; |
| 514 | postCheck = '' |
| 515 | go vet ./... |
| 516 | ''; |
| 517 | }; |
| 518 | |
| 519 | # The restacker (restack/): `valley-restacker once --report-only` reads |
| 520 | # one snapshot of origin through the rebase engine (../rebase), says |
| 521 | # which families it would restack and which it would hold, and builds the |
| 522 | # writes a pass would push, pushing none. It reads the cap on its |
| 523 | # automatic versions through the composed-policy reader it shares with |
| 524 | # the integrator (../composed), and a signer projects file through the |
| 525 | # note module (../note). Its unit tests cover request association, |
| 526 | # outcome currency, capacity and report bounds, and, against real git, |
| 527 | # the journal of writes and recovery's decisions, its environment, its |
| 528 | # scratch repository's identity, its state directory's lock and binding, |
| 529 | # and the deadline on what it runs. go vet runs after them. Go, standard |
| 530 | # library only — hence vendorHash = null and no module fetch. |
| 531 | restack-unwrapped = pkgs.buildGoModule { |
| 532 | pname = "valley-restacker"; |
| 533 | version = "0"; |
| 534 | # The program alone: e2e/transport is a module of restack-e2e's own, |
| 535 | # which neither this build nor its tests read. |
| 536 | src = |
| 537 | withLocalExcept ../restack |
| 538 | [ |
| 539 | ../change |
| 540 | ../composed |
| 541 | ../note |
| 542 | ../rebase |
| 543 | ] |
| 544 | [ ../restack/e2e ]; |
| 545 | modRoot = "restack"; |
| 546 | subPackages = [ "." ]; |
| 547 | vendorHash = null; |
| 548 | preBuild = readsGoMod; |
| 549 | nativeCheckInputs = [ pkgs.git ]; |
| 550 | postCheck = '' |
| 551 | go vet ./... |
| 552 | ''; |
| 553 | # The module is named for its directory; the program, for what it is. |
| 554 | postInstall = '' |
| 555 | mv $out/bin/restack $out/bin/valley-restacker |
| 556 | ''; |
| 557 | meta.mainProgram = "valley-restacker"; |
| 558 | }; |
| 559 | |
| 560 | # The shipping form: git to read origin, cue to compose the policy, and |
| 561 | # attest to check a transfer statement, all pinned to this flake's |
| 562 | # nixpkgs, with the packaged verification schema as the default. |
| 563 | valley-restacker = |
| 564 | pkgs.runCommand "valley-restacker" |
| 565 | { |
| 566 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 567 | meta.mainProgram = "valley-restacker"; |
| 568 | } |
| 569 | '' |
| 570 | mkdir -p $out/bin |
| 571 | makeWrapper ${lib.getExe restack-unwrapped} $out/bin/valley-restacker \ |
| 572 | --prefix PATH : ${ |
| 573 | lib.makeBinPath [ |
| 574 | pkgs.git |
| 575 | pkgs.cue |
| 576 | attest |
| 577 | ] |
| 578 | } \ |
| 579 | --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} |
| 580 | ''; |
| 581 | |
| 582 | # The Phase 3 integrator (dcr-439b771). Go, standard library only, |
| 583 | # same trade as attest — hence vendorHash = null and no module fetch. It |
| 584 | # reads change records with the one reading of a record the push hook |
| 585 | # shares (../change), and verifier keys with the one reading of a key the |
| 586 | # note format defines (../note). |
| 587 | integrator-unwrapped = pkgs.buildGoModule { |
| 588 | pname = "valley-integrator"; |
| 589 | version = "0"; |
| 590 | # The verification schema is in the source for the policy bridge's |
| 591 | # tests, which compose a policy under it. The scenarios (integrator/e2e/) |
| 592 | # are integrator-e2e's, and no Go test reads them. |
| 593 | src = |
| 594 | withLocalExcept ../integrator |
| 595 | [ |
| 596 | ../change |
| 597 | ../composed |
| 598 | ../note |
| 599 | ../schema/verification.cue |
| 600 | ] |
| 601 | [ ../integrator/e2e ]; |
| 602 | modRoot = "integrator"; |
| 603 | vendorHash = null; |
| 604 | preBuild = readsGoMod; |
| 605 | # The policy bridge's tests check a deriver's report against real git, |
| 606 | # and compose a policy with real cue. |
| 607 | nativeCheckInputs = [ |
| 608 | pkgs.git |
| 609 | pkgs.cue |
| 610 | ]; |
| 611 | meta.mainProgram = "integrator"; |
| 612 | }; |
| 613 | |
| 614 | # The shipping form. The integrator drives four programs rather than |
| 615 | # reimplementing what they do: attest judges every statement and |
| 616 | # every note, the valley deriver and cue compose the policy, and git |
| 617 | # holds the requests and the refs. All four are pinned to this |
| 618 | # flake's nixpkgs so an instance's integrators agree; `nix` is |
| 619 | # deliberately absent for the same reason it is absent from attest — |
| 620 | # a closure must be recomputed by the nix the machine actually runs. |
| 621 | integrator = |
| 622 | pkgs.runCommand "valley-integrator" |
| 623 | { |
| 624 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 625 | meta.mainProgram = "integrator"; |
| 626 | } |
| 627 | '' |
| 628 | mkdir -p $out/bin |
| 629 | makeWrapper ${lib.getExe integrator-unwrapped} $out/bin/integrator \ |
| 630 | --prefix PATH : ${ |
| 631 | lib.makeBinPath [ |
| 632 | pkgs.git |
| 633 | pkgs.cue |
| 634 | pkgs.natscli |
| 635 | attest |
| 636 | valley-script |
| 637 | ] |
| 638 | } \ |
| 639 | --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} \ |
| 640 | --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} \ |
| 641 | --set-default VALLEY_EVENT_SCHEMA ${../schema/events.cue} |
| 642 | ''; |
| 643 | } |