gunk-dev/the-valley

packages.nix

source885985671589main's published tip history
13.3 KiB
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 }:
7rec {
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, withdraw and rebase, 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). rebase rebases a change's whole stack and
85 # adds each change's rebased head to its record. knot reads and writes
86 # the plan graph, with the one reading of a graph the push hook shares
87 # (../knot), and plan shows that graph as a view. compare reads a
88 # version's file delta and its approved version's with the one reading
89 # of valley-delta-v1 (../delta), for review. Go,
90 # standard library only — hence vendorHash = null and no module fetch. It runs whatever git is on PATH, which inside the
91 # CLI's package is the CLI's own. Its unit tests hold its shell quoting to
92 # the bash it replaced, so they need bash, and lay pending out over real
93 # repositories, so they need git.
94 valley-go = pkgs.buildGoModule {
95 pname = "valley-go";
96 version = "0";
97 src = withLocal ../status [
98 ../change
99 ../delta
100 ../knot
101 ];
102 modRoot = "status";
103 vendorHash = null;
104 preBuild = readsGoMod;
105 nativeCheckInputs = [
106 pkgs.bash
107 pkgs.git
108 ];
109 meta.mainProgram = "valley-go";
110 };
111
112 # `nix run .#fmt` — rewrap every tracked *.md in the repo to 100 columns.
113 prose-fmt = pkgs.writeShellApplication {
114 name = "valley-fmt";
115 runtimeInputs = [
116 pkgs.git
117 pkgs.prettier
118 ];
119 text = ''
120 cd "$(git rev-parse --show-toplevel)"
121 git ls-files -z -- '*.md' | xargs -0 --no-run-if-empty \
122 prettier ${proseFmtArgs} --write
123 '';
124 };
125
126 # The Phase 2 attestation helper (dcr-0de694f). Go, standard library
127 # only, note format included — hence vendorHash = null, and hence no
128 # module fetch at build time. Its unit tests run in the checkPhase and
129 # need git and ssh-keygen.
130 attest-unwrapped = pkgs.buildGoModule {
131 pname = "valley-attest";
132 version = "0";
133 src = withNote ../attest;
134 modRoot = "attest";
135 vendorHash = null;
136 preBuild = readsGoMod;
137 nativeCheckInputs = [
138 pkgs.git
139 pkgs.openssh
140 ];
141 meta.mainProgram = "attest";
142 };
143
144 # The shipping form. git and cue are pinned to this flake's nixpkgs,
145 # so every host composes and vets a statement with the same tools.
146 # Signing needs no tool at all: a note is signed on crypto/ed25519
147 # inside the binary. `nix` is deliberately NOT pinned: the check being
148 # attested to must be built by the nix the machine actually runs, and
149 # a nix carried in here would be a second one.
150 attest =
151 pkgs.runCommand "valley-attest"
152 {
153 nativeBuildInputs = [ pkgs.makeWrapper ];
154 meta.mainProgram = "attest";
155 }
156 ''
157 mkdir -p $out/bin
158 makeWrapper ${lib.getExe attest-unwrapped} $out/bin/attest \
159 --prefix PATH : ${
160 lib.makeBinPath [
161 pkgs.git
162 pkgs.cue
163 ]
164 } \
165 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue}
166 '';
167
168 # The identity registry compiler (dcr-b87f6e8). Go, standard library
169 # only, same trade as attest and the integrator — hence vendorHash = null
170 # and no module fetch. Its unit tests pin the note format's key hash
171 # against the reference vector attest is held to.
172 identity-unwrapped = pkgs.buildGoModule {
173 pname = "valley-identity";
174 version = "0";
175 src = ../identity;
176 vendorHash = null;
177 meta.mainProgram = "identity";
178 };
179
180 # The shipping form. git reads the registry out of the instance
181 # repository's tip and cue vets and exports it, both pinned to this
182 # flake's nixpkgs so every host compiles a registry the same way. The
183 # schema travels with the binary: a compiler judging a registry against a
184 # schema the consumer supplied would be no floor at all.
185 identity =
186 pkgs.runCommand "valley-identity"
187 {
188 nativeBuildInputs = [ pkgs.makeWrapper ];
189 meta.mainProgram = "identity";
190 }
191 ''
192 mkdir -p $out/bin
193 makeWrapper ${lib.getExe identity-unwrapped} $out/bin/identity \
194 --prefix PATH : ${
195 lib.makeBinPath [
196 pkgs.git
197 pkgs.cue
198 ]
199 } \
200 --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue}
201 '';
202
203 # The security-key signature verifier (sigverify/README.md). Go,
204 # standard library only — hence vendorHash = null and no module fetch.
205 #
206 # The git its git-tag command runs is fixed at build time to this
207 # flake's git, as an absolute store path compiled into the binary. A
208 # wrapper that puts git on PATH would leave the binary inside it looking
209 # git up on PATH, and a caller's environment could change which git that
210 # is. Compiled in, there is no PATH lookup to change.
211 #
212 # Its tests run in the checkPhase against real ssh-keygen and git. The
213 # security-key cases among them need OpenSSH's sk-dummy authenticator,
214 # which only the sigverify-unit check supplies; here they skip, so a
215 # consumer building this package never builds OpenSSH.
216 sigverify = pkgs.buildGoModule {
217 pname = "valley-sigverify";
218 version = "0";
219 src = ../sigverify;
220 vendorHash = null;
221 ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ];
222 nativeCheckInputs = [
223 pkgs.git
224 pkgs.openssh
225 ];
226 meta.mainProgram = "sigverify";
227 };
228
229 # The pre-receive hook's policy (valleyhook/): what a push may write to a
230 # project a valley host serves. It validates a push to the plan graph
231 # with the one reading of a graph the CLI shares (../knot). The same binary is the git user's login
232 # shell, which derives the pushing principal and pauses pushes until the
233 # host has converged. Go, standard library only — hence
234 # vendorHash = null and no module fetch. Its unit tests run in the
235 # checkPhase.
236 #
237 # The git it reads the repository with is fixed at build time, the way
238 # sigverify's is: an absolute store path compiled into the binary, so no
239 # PATH a hook runs under can change which git that is.
240 valleyhook = pkgs.buildGoModule {
241 pname = "valley-valleyhook";
242 version = "0";
243 src = withLocal ../valleyhook [
244 ../note
245 ../change
246 ../knot
247 ];
248 modRoot = "valleyhook";
249 vendorHash = null;
250 preBuild = readsGoMod;
251 ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ];
252 # The walk's and the change records' tests build hostile objects with
253 # real git.
254 nativeCheckInputs = [ pkgs.git ];
255 meta.mainProgram = "valleyhook";
256 };
257
258 # The note envelope's own tests, which hold it to refusing every line a
259 # relayer could append that one of its readers would refuse.
260 note = pkgs.buildGoModule {
261 pname = "valley-note";
262 version = "0";
263 src = ../note;
264 vendorHash = null;
265 };
266
267 # The plan graph (knot/): its canonical form, its layout, cycles and
268 # transitions, held by its own tests. The package is knotcheck, which
269 # knot-agree runs to hold the Go validator to the CUE schema and the
270 # knowledge lint.
271 knot = pkgs.buildGoModule {
272 pname = "valley-knot";
273 version = "0";
274 src = ../knot;
275 vendorHash = null;
276 meta.mainProgram = "knotcheck";
277 };
278
279 # The change record's own tests: its strict reading, its fuzz target's
280 # seed corpus, and its branch-name rule, which they hold to real git's
281 # check-ref-format.
282 change = pkgs.buildGoModule {
283 pname = "valley-change";
284 version = "0";
285 src = ../change;
286 vendorHash = null;
287 nativeCheckInputs = [ pkgs.git ];
288 };
289
290 # valley-delta-v1 (delta/): the encoding's strict reading, and the delta
291 # read from real trees. Its checkPhase runs go vet, the conformance
292 # vectors' script in its --check mode, which holds the committed expected
293 # results to what the script computes, and go test, which builds each
294 # vector's trees with real git and holds the Go code to those results.
295 delta = pkgs.buildGoModule {
296 pname = "valley-delta";
297 version = "0";
298 src = ../delta;
299 vendorHash = null;
300 nativeCheckInputs = [
301 pkgs.git
302 pkgs.python3
303 ];
304 preCheck = ''
305 go vet ./...
306 python3 -I testdata/vectors.py --check testdata
307 '';
308 };
309
310 # The Phase 3 integrator (dcr-439b771). Go, standard library only,
311 # same trade as attest — hence vendorHash = null and no module fetch. It
312 # reads change records with the one reading of a record the push hook
313 # shares (../change).
314 integrator-unwrapped = pkgs.buildGoModule {
315 pname = "valley-integrator";
316 version = "0";
317 src = withLocal ../integrator [ ../change ];
318 modRoot = "integrator";
319 vendorHash = null;
320 preBuild = readsGoMod;
321 # The policy bridge's tests check a deriver's report against real git.
322 nativeCheckInputs = [ pkgs.git ];
323 meta.mainProgram = "integrator";
324 };
325
326 # The shipping form. The integrator drives four programs rather than
327 # reimplementing what they do: attest judges every statement and
328 # every note, the valley deriver and cue compose the policy, and git
329 # holds the requests and the refs. All four are pinned to this
330 # flake's nixpkgs so an instance's integrators agree; `nix` is
331 # deliberately absent for the same reason it is absent from attest —
332 # a closure must be recomputed by the nix the machine actually runs.
333 integrator =
334 pkgs.runCommand "valley-integrator"
335 {
336 nativeBuildInputs = [ pkgs.makeWrapper ];
337 meta.mainProgram = "integrator";
338 }
339 ''
340 mkdir -p $out/bin
341 makeWrapper ${lib.getExe integrator-unwrapped} $out/bin/integrator \
342 --prefix PATH : ${
343 lib.makeBinPath [
344 pkgs.git
345 pkgs.cue
346 pkgs.natscli
347 attest
348 valley-script
349 ]
350 } \
351 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} \
352 --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} \
353 --set-default VALLEY_EVENT_SCHEMA ${../schema/events.cue}
354 '';
355}