| 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 | { pkgs, lib }: |
| 7 | rec { |
| 8 | # The source of a Go program that uses modules of this repository: its own |
| 9 | # directory and those modules, which its go.mod replaces with their local |
| 10 | # directories. Nothing shared this way is fetched. |
| 11 | withLocal = |
| 12 | dir: modules: |
| 13 | lib.fileset.toSource { |
| 14 | root = ../.; |
| 15 | fileset = lib.fileset.unions ([ dir ] ++ modules); |
| 16 | }; |
| 17 | |
| 18 | # A program that reads signed notes takes the note module (../note). One |
| 19 | # reading of the envelope is shared by the programs that write, verify and |
| 20 | # admit attestations. |
| 21 | withNote = dir: withLocal dir [ ../note ]; |
| 22 | |
| 23 | # vendorHash = null builds in vendor mode, which has no reading of a local |
| 24 | # replace. The replaced module is a directory beside the program and |
| 25 | # nothing is fetched either way, so these builds read go.mod as written. |
| 26 | readsGoMod = '' |
| 27 | export GOFLAGS="''${GOFLAGS//-mod=vendor/-mod=mod}" |
| 28 | ''; |
| 29 | |
| 30 | # Markdown prose is filled paragraphs hard-wrapped at 100 columns |
| 31 | # (ida-1ec03b1). One flag string backs both the formatter app and the |
| 32 | # prose-format check, so the two cannot drift. Embedded-language |
| 33 | # formatting is off so fenced code blocks pass through byte-for-byte. |
| 34 | proseFmtArgs = "--prose-wrap always --print-width 100 --embedded-language-formatting off"; |
| 35 | |
| 36 | # The integrator's CLI (bin/valley) wrapped for `nix run`. The script |
| 37 | # itself must keep running bare from any checkout — the package is the |
| 38 | # second of its two shipping modes, never a dependency of the first. |
| 39 | valley-script-unwrapped = pkgs.writeShellApplication { |
| 40 | name = "valley"; |
| 41 | runtimeInputs = [ |
| 42 | pkgs.git |
| 43 | pkgs.natscli # tail and replay only; every other verb needs just git |
| 44 | pkgs.cue # checks and approving — it composes the policy layers |
| 45 | pkgs.less # review only — its v key is what takes a note |
| 46 | attest # approving only — it runs the checks and signs them |
| 47 | valley-go # status, ready, unready and withdraw, naming a change by its ID, and pending's drafts |
| 48 | ]; |
| 49 | text = builtins.readFile ../bin/valley; |
| 50 | }; |
| 51 | |
| 52 | # The shipping form. The verification schema travels with the script, as |
| 53 | # it does with the integrator: only the-valley's own tree carries |
| 54 | # schema/, so a project's checkout has none to read. --set-default leaves |
| 55 | # an explicit VALLEY_VERIFICATION_SCHEMA in charge. |
| 56 | valley-script = |
| 57 | pkgs.runCommand "valley" |
| 58 | { |
| 59 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 60 | meta.mainProgram = "valley"; |
| 61 | } |
| 62 | '' |
| 63 | mkdir -p $out/bin |
| 64 | makeWrapper ${lib.getExe valley-script-unwrapped} $out/bin/valley \ |
| 65 | --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} |
| 66 | ''; |
| 67 | |
| 68 | # The installed package: the wrapped script plus the shell completions, |
| 69 | # at the standard paths home-manager/NixOS auto-link. |
| 70 | valley = pkgs.symlinkJoin { |
| 71 | name = "valley"; |
| 72 | paths = [ valley-script ]; |
| 73 | nativeBuildInputs = [ pkgs.installShellFiles ]; |
| 74 | postBuild = '' |
| 75 | installShellCompletion --bash --name valley ${../completions/valley.bash} |
| 76 | installShellCompletion --zsh --name _valley ${../completions/_valley} |
| 77 | ''; |
| 78 | }; |
| 79 | |
| 80 | # The verbs of the CLI written in Go (status/). status reads one change's |
| 81 | # request and outcome record from origin, and prints them as sentences or |
| 82 | # as the valley-status/v1 JSON object front ends read. ready, unready and |
| 83 | # withdraw write a change's record, with the one reading of a record the |
| 84 | # push hook shares (../change). Go, standard library only — hence vendorHash = null |
| 85 | # and no module fetch. It runs whatever git is on PATH, which inside the |
| 86 | # CLI's package is the CLI's own. Its unit tests hold its shell quoting to |
| 87 | # the bash it replaced, so they need bash. |
| 88 | valley-go = pkgs.buildGoModule { |
| 89 | pname = "valley-go"; |
| 90 | version = "0"; |
| 91 | src = withLocal ../status [ ../change ]; |
| 92 | modRoot = "status"; |
| 93 | vendorHash = null; |
| 94 | preBuild = readsGoMod; |
| 95 | nativeCheckInputs = [ pkgs.bash ]; |
| 96 | meta.mainProgram = "valley-go"; |
| 97 | }; |
| 98 | |
| 99 | # `nix run .#fmt` — rewrap every tracked *.md in the repo to 100 columns. |
| 100 | prose-fmt = pkgs.writeShellApplication { |
| 101 | name = "valley-fmt"; |
| 102 | runtimeInputs = [ |
| 103 | pkgs.git |
| 104 | pkgs.prettier |
| 105 | ]; |
| 106 | text = '' |
| 107 | cd "$(git rev-parse --show-toplevel)" |
| 108 | git ls-files -z -- '*.md' | xargs -0 --no-run-if-empty \ |
| 109 | prettier ${proseFmtArgs} --write |
| 110 | ''; |
| 111 | }; |
| 112 | |
| 113 | # The Phase 2 attestation helper (dcr-0de694f). Go, standard library |
| 114 | # only, note format included — hence vendorHash = null, and hence no |
| 115 | # module fetch at build time. Its unit tests run in the checkPhase and |
| 116 | # need git and ssh-keygen. |
| 117 | attest-unwrapped = pkgs.buildGoModule { |
| 118 | pname = "valley-attest"; |
| 119 | version = "0"; |
| 120 | src = withNote ../attest; |
| 121 | modRoot = "attest"; |
| 122 | vendorHash = null; |
| 123 | preBuild = readsGoMod; |
| 124 | nativeCheckInputs = [ |
| 125 | pkgs.git |
| 126 | pkgs.openssh |
| 127 | ]; |
| 128 | meta.mainProgram = "attest"; |
| 129 | }; |
| 130 | |
| 131 | # The shipping form. git and cue are pinned to this flake's nixpkgs, |
| 132 | # so every host composes and vets a statement with the same tools. |
| 133 | # Signing needs no tool at all: a note is signed on crypto/ed25519 |
| 134 | # inside the binary. `nix` is deliberately NOT pinned: the check being |
| 135 | # attested to must be built by the nix the machine actually runs, and |
| 136 | # a nix carried in here would be a second one. |
| 137 | attest = |
| 138 | pkgs.runCommand "valley-attest" |
| 139 | { |
| 140 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 141 | meta.mainProgram = "attest"; |
| 142 | } |
| 143 | '' |
| 144 | mkdir -p $out/bin |
| 145 | makeWrapper ${lib.getExe attest-unwrapped} $out/bin/attest \ |
| 146 | --prefix PATH : ${ |
| 147 | lib.makeBinPath [ |
| 148 | pkgs.git |
| 149 | pkgs.cue |
| 150 | ] |
| 151 | } \ |
| 152 | --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} |
| 153 | ''; |
| 154 | |
| 155 | # The identity registry compiler (dcr-b87f6e8). Go, standard library |
| 156 | # only, same trade as attest and the integrator — hence vendorHash = null |
| 157 | # and no module fetch. Its unit tests pin the note format's key hash |
| 158 | # against the reference vector attest is held to. |
| 159 | identity-unwrapped = pkgs.buildGoModule { |
| 160 | pname = "valley-identity"; |
| 161 | version = "0"; |
| 162 | src = ../identity; |
| 163 | vendorHash = null; |
| 164 | meta.mainProgram = "identity"; |
| 165 | }; |
| 166 | |
| 167 | # The shipping form. git reads the registry out of the instance |
| 168 | # repository's tip and cue vets and exports it, both pinned to this |
| 169 | # flake's nixpkgs so every host compiles a registry the same way. The |
| 170 | # schema travels with the binary: a compiler judging a registry against a |
| 171 | # schema the consumer supplied would be no floor at all. |
| 172 | identity = |
| 173 | pkgs.runCommand "valley-identity" |
| 174 | { |
| 175 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 176 | meta.mainProgram = "identity"; |
| 177 | } |
| 178 | '' |
| 179 | mkdir -p $out/bin |
| 180 | makeWrapper ${lib.getExe identity-unwrapped} $out/bin/identity \ |
| 181 | --prefix PATH : ${ |
| 182 | lib.makeBinPath [ |
| 183 | pkgs.git |
| 184 | pkgs.cue |
| 185 | ] |
| 186 | } \ |
| 187 | --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue} |
| 188 | ''; |
| 189 | |
| 190 | # The security-key signature verifier (sigverify/README.md). Go, |
| 191 | # standard library only — hence vendorHash = null and no module fetch. |
| 192 | # |
| 193 | # The git its git-tag command runs is fixed at build time to this |
| 194 | # flake's git, as an absolute store path compiled into the binary. A |
| 195 | # wrapper that puts git on PATH would leave the binary inside it looking |
| 196 | # git up on PATH, and a caller's environment could change which git that |
| 197 | # is. Compiled in, there is no PATH lookup to change. |
| 198 | # |
| 199 | # Its tests run in the checkPhase against real ssh-keygen and git. The |
| 200 | # security-key cases among them need OpenSSH's sk-dummy authenticator, |
| 201 | # which only the sigverify-unit check supplies; here they skip, so a |
| 202 | # consumer building this package never builds OpenSSH. |
| 203 | sigverify = pkgs.buildGoModule { |
| 204 | pname = "valley-sigverify"; |
| 205 | version = "0"; |
| 206 | src = ../sigverify; |
| 207 | vendorHash = null; |
| 208 | ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ]; |
| 209 | nativeCheckInputs = [ |
| 210 | pkgs.git |
| 211 | pkgs.openssh |
| 212 | ]; |
| 213 | meta.mainProgram = "sigverify"; |
| 214 | }; |
| 215 | |
| 216 | # The pre-receive hook's policy (valleyhook/): what a push may write to a |
| 217 | # project a valley host serves. The same binary is the git user's login |
| 218 | # shell, which derives the pushing principal and pauses pushes until the |
| 219 | # host has converged. Go, standard library only — hence |
| 220 | # vendorHash = null and no module fetch. Its unit tests run in the |
| 221 | # checkPhase. |
| 222 | # |
| 223 | # The git it reads the repository with is fixed at build time, the way |
| 224 | # sigverify's is: an absolute store path compiled into the binary, so no |
| 225 | # PATH a hook runs under can change which git that is. |
| 226 | valleyhook = pkgs.buildGoModule { |
| 227 | pname = "valley-valleyhook"; |
| 228 | version = "0"; |
| 229 | src = withLocal ../valleyhook [ |
| 230 | ../note |
| 231 | ../change |
| 232 | ]; |
| 233 | modRoot = "valleyhook"; |
| 234 | vendorHash = null; |
| 235 | preBuild = readsGoMod; |
| 236 | ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ]; |
| 237 | # The walk's and the change records' tests build hostile objects with |
| 238 | # real git. |
| 239 | nativeCheckInputs = [ pkgs.git ]; |
| 240 | meta.mainProgram = "valleyhook"; |
| 241 | }; |
| 242 | |
| 243 | # The note envelope's own tests, which hold it to refusing every line a |
| 244 | # relayer could append that one of its readers would refuse. |
| 245 | note = pkgs.buildGoModule { |
| 246 | pname = "valley-note"; |
| 247 | version = "0"; |
| 248 | src = ../note; |
| 249 | vendorHash = null; |
| 250 | }; |
| 251 | |
| 252 | # The change record's own tests: its strict reading, its fuzz target's |
| 253 | # seed corpus, and its branch-name rule, which they hold to real git's |
| 254 | # check-ref-format. |
| 255 | change = pkgs.buildGoModule { |
| 256 | pname = "valley-change"; |
| 257 | version = "0"; |
| 258 | src = ../change; |
| 259 | vendorHash = null; |
| 260 | nativeCheckInputs = [ pkgs.git ]; |
| 261 | }; |
| 262 | |
| 263 | # The Phase 3 integrator (dcr-439b771). Go, standard library only, |
| 264 | # same trade as attest — hence vendorHash = null and no module fetch. It |
| 265 | # reads change records with the one reading of a record the push hook |
| 266 | # shares (../change). |
| 267 | integrator-unwrapped = pkgs.buildGoModule { |
| 268 | pname = "valley-integrator"; |
| 269 | version = "0"; |
| 270 | src = withLocal ../integrator [ ../change ]; |
| 271 | modRoot = "integrator"; |
| 272 | vendorHash = null; |
| 273 | preBuild = readsGoMod; |
| 274 | # The policy bridge's tests check a deriver's report against real git. |
| 275 | nativeCheckInputs = [ pkgs.git ]; |
| 276 | meta.mainProgram = "integrator"; |
| 277 | }; |
| 278 | |
| 279 | # The shipping form. The integrator drives four programs rather than |
| 280 | # reimplementing what they do: attest judges every statement and |
| 281 | # every note, the valley deriver and cue compose the policy, and git |
| 282 | # holds the requests and the refs. All four are pinned to this |
| 283 | # flake's nixpkgs so an instance's integrators agree; `nix` is |
| 284 | # deliberately absent for the same reason it is absent from attest — |
| 285 | # a closure must be recomputed by the nix the machine actually runs. |
| 286 | integrator = |
| 287 | pkgs.runCommand "valley-integrator" |
| 288 | { |
| 289 | nativeBuildInputs = [ pkgs.makeWrapper ]; |
| 290 | meta.mainProgram = "integrator"; |
| 291 | } |
| 292 | '' |
| 293 | mkdir -p $out/bin |
| 294 | makeWrapper ${lib.getExe integrator-unwrapped} $out/bin/integrator \ |
| 295 | --prefix PATH : ${ |
| 296 | lib.makeBinPath [ |
| 297 | pkgs.git |
| 298 | pkgs.cue |
| 299 | pkgs.natscli |
| 300 | attest |
| 301 | valley-script |
| 302 | ] |
| 303 | } \ |
| 304 | --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} \ |
| 305 | --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} \ |
| 306 | --set-default VALLEY_EVENT_SCHEMA ${../schema/events.cue} |
| 307 | ''; |
| 308 | } |