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