gunk-dev/the-valley

packages.nix

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