gunk-dev/the-valley

packages.nix

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