gunk-dev/the-valley

packages.nix

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