| 1 | # Everything this flake builds: the CLI, the formatter, the attestation |
| 2 | # helper, the integrator. The flake wires these into packages, apps, and the |
| 3 | # checks that drive them; nothing here knows about any of those outputs. |
| 4 | { pkgs, lib }: |
| 5 | rec { |
| 6 | # Markdown prose is filled paragraphs hard-wrapped at 100 columns |
| 7 | # (ida-1ec03b1). One flag string backs both the formatter app and the |
| 8 | # prose-format check, so the two cannot drift. Embedded-language |
| 9 | # formatting is off so fenced code blocks pass through byte-for-byte. |
| 10 | proseFmtArgs = "--prose-wrap always --print-width 100 --embedded-language-formatting off"; |
| 11 | |
| 12 | # The integrator's CLI (bin/valley) wrapped for `nix run`. The script |
| 13 | # itself must keep running bare from any checkout — the package is the |
| 14 | # second of its two shipping modes, never a dependency of the first. |
| 15 | valley-script = pkgs.writeShellApplication { |
| 16 | name = "valley"; |
| 17 | runtimeInputs = [ |
| 18 | pkgs.git |
| 19 | pkgs.natscli # tail and replay only; every other verb needs just git |
| 20 | pkgs.cue # checks only — it composes the policy layers |
| 21 | pkgs.less # review only — its v key is what takes a note |
| 22 | ]; |
| 23 | text = builtins.readFile ../bin/valley; |
| 24 | }; |
| 25 | |
| 26 | # The installed package: the wrapped script plus the shell completions, |
| 27 | # at the standard paths home-manager/NixOS auto-link. |
| 28 | valley = pkgs.symlinkJoin { |
| 29 | name = "valley"; |
| 30 | paths = [ valley-script ]; |
| 31 | nativeBuildInputs = [ pkgs.installShellFiles ]; |
| 32 | postBuild = '' |
| 33 | installShellCompletion --bash --name valley ${../completions/valley.bash} |
| 34 | installShellCompletion --zsh --name _valley ${../completions/_valley} |
| 35 | ''; |
| 36 | }; |
| 37 | |
| 38 | # `nix run .#fmt` — rewrap every tracked *.md in the repo to 100 columns. |
| 39 | prose-fmt = pkgs.writeShellApplication { |
| 40 | name = "valley-fmt"; |
| 41 | runtimeInputs = [ |
| 42 | pkgs.git |
| 43 | pkgs.prettier |
| 44 | ]; |
| 45 | text = '' |
| 46 | cd "$(git rev-parse --show-toplevel)" |
| 47 | git ls-files -z -- '*.md' | xargs -0 --no-run-if-empty \ |
| 48 | prettier ${proseFmtArgs} --write |
| 49 | ''; |
| 50 | }; |
| 51 | |
| 52 | # The Phase 2 attestation helper (dcr-0de694f). Go, standard library |
| 53 | # only, note format included — hence vendorHash = null, and hence no |
| 54 | # module fetch at build time. Its unit tests run in the checkPhase and |
| 55 | # need git and ssh-keygen. |
| 56 | attest-unwrapped = pkgs.buildGoModule { |
| 57 | pname = "valley-attest"; |
| 58 | version = "0"; |
| 59 | src = ../attest; |
| 60 | vendorHash = null; |
| 61 | nativeCheckInputs = [ |
| 62 | pkgs.git |
| 63 | pkgs.openssh |
| 64 | ]; |
| 65 | meta.mainProgram = "attest"; |
| 66 | }; |
| 67 | |
| 68 | # The shipping form. git and cue are pinned to this flake's nixpkgs, |
| 69 | # so every host composes and vets a statement with the same tools. |
| 70 | # Signing needs no tool at all: a note is signed on crypto/ed25519 |
| 71 | # inside the binary. `nix` is deliberately NOT pinned: the check being |
| 72 | # attested to must be built by the nix the machine actually runs, and |
| 73 | # a nix carried in here would be a second one. |
| 74 | attest = |
| 75 | pkgs.runCommand "valley-attest" |
| 76 | { |
| 77 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 78 | meta.mainProgram = "attest"; |
| 79 | } |
| 80 | '' |
| 81 | mkdir -p $out/bin |
| 82 | makeWrapper ${lib.getExe attest-unwrapped} $out/bin/attest \ |
| 83 | --prefix PATH : ${ |
| 84 | lib.makeBinPath [ |
| 85 | pkgs.git |
| 86 | pkgs.cue |
| 87 | ] |
| 88 | } \ |
| 89 | --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} |
| 90 | ''; |
| 91 | |
| 92 | # The Phase 3 integrator (dcr-439b771). Go, standard library only, |
| 93 | # same trade as attest — hence vendorHash = null and no module fetch. |
| 94 | integrator-unwrapped = pkgs.buildGoModule { |
| 95 | pname = "valley-integrator"; |
| 96 | version = "0"; |
| 97 | src = ../integrator; |
| 98 | vendorHash = null; |
| 99 | meta.mainProgram = "integrator"; |
| 100 | }; |
| 101 | |
| 102 | # The shipping form. The integrator drives four programs rather than |
| 103 | # reimplementing what they do: attest judges every statement and |
| 104 | # every note, the valley deriver and cue compose the policy, and git |
| 105 | # holds the requests and the refs. All four are pinned to this |
| 106 | # flake's nixpkgs so an instance's integrators agree; `nix` is |
| 107 | # deliberately absent for the same reason it is absent from attest — |
| 108 | # a closure must be recomputed by the nix the machine actually runs. |
| 109 | integrator = |
| 110 | pkgs.runCommand "valley-integrator" |
| 111 | { |
| 112 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 113 | meta.mainProgram = "integrator"; |
| 114 | } |
| 115 | '' |
| 116 | mkdir -p $out/bin |
| 117 | makeWrapper ${lib.getExe integrator-unwrapped} $out/bin/integrator \ |
| 118 | --prefix PATH : ${ |
| 119 | lib.makeBinPath [ |
| 120 | pkgs.git |
| 121 | pkgs.cue |
| 122 | pkgs.natscli |
| 123 | attest |
| 124 | valley-script |
| 125 | ] |
| 126 | } \ |
| 127 | --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} \ |
| 128 | --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} \ |
| 129 | --set-default VALLEY_EVENT_SCHEMA ${../schema/events.cue} |
| 130 | ''; |
| 131 | } |