gunk-dev/the-valley

packages.nix

source6063990989b7main's published tip history
9.3 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 = 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 installed package: the wrapped script plus the shell completions,
50 # at the standard paths home-manager/NixOS auto-link.
51 valley = pkgs.symlinkJoin {
52 name = "valley";
53 paths = [ valley-script ];
54 nativeBuildInputs = [ pkgs.installShellFiles ];
55 postBuild = ''
56 installShellCompletion --bash --name valley ${../completions/valley.bash}
57 installShellCompletion --zsh --name _valley ${../completions/_valley}
58 '';
59 };
60
61 # `nix run .#fmt` — rewrap every tracked *.md in the repo to 100 columns.
62 prose-fmt = pkgs.writeShellApplication {
63 name = "valley-fmt";
64 runtimeInputs = [
65 pkgs.git
66 pkgs.prettier
67 ];
68 text = ''
69 cd "$(git rev-parse --show-toplevel)"
70 git ls-files -z -- '*.md' | xargs -0 --no-run-if-empty \
71 prettier ${proseFmtArgs} --write
72 '';
73 };
74
75 # The Phase 2 attestation helper (dcr-0de694f). Go, standard library
76 # only, note format included — hence vendorHash = null, and hence no
77 # module fetch at build time. Its unit tests run in the checkPhase and
78 # need git and ssh-keygen.
79 attest-unwrapped = pkgs.buildGoModule {
80 pname = "valley-attest";
81 version = "0";
82 src = withNote ../attest;
83 modRoot = "attest";
84 vendorHash = null;
85 preBuild = readsGoMod;
86 nativeCheckInputs = [
87 pkgs.git
88 pkgs.openssh
89 ];
90 meta.mainProgram = "attest";
91 };
92
93 # The shipping form. git and cue are pinned to this flake's nixpkgs,
94 # so every host composes and vets a statement with the same tools.
95 # Signing needs no tool at all: a note is signed on crypto/ed25519
96 # inside the binary. `nix` is deliberately NOT pinned: the check being
97 # attested to must be built by the nix the machine actually runs, and
98 # a nix carried in here would be a second one.
99 attest =
100 pkgs.runCommand "valley-attest"
101 {
102 nativeBuildInputs = [ pkgs.makeWrapper ];
103 meta.mainProgram = "attest";
104 }
105 ''
106 mkdir -p $out/bin
107 makeWrapper ${lib.getExe attest-unwrapped} $out/bin/attest \
108 --prefix PATH : ${
109 lib.makeBinPath [
110 pkgs.git
111 pkgs.cue
112 ]
113 } \
114 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue}
115 '';
116
117 # The identity registry compiler (dcr-b87f6e8). Go, standard library
118 # only, same trade as attest and the integrator — hence vendorHash = null
119 # and no module fetch. Its unit tests pin the note format's key hash
120 # against the reference vector attest is held to.
121 identity-unwrapped = pkgs.buildGoModule {
122 pname = "valley-identity";
123 version = "0";
124 src = ../identity;
125 vendorHash = null;
126 meta.mainProgram = "identity";
127 };
128
129 # The shipping form. git reads the registry out of the instance
130 # repository's tip and cue vets and exports it, both pinned to this
131 # flake's nixpkgs so every host compiles a registry the same way. The
132 # schema travels with the binary: a compiler judging a registry against a
133 # schema the consumer supplied would be no floor at all.
134 identity =
135 pkgs.runCommand "valley-identity"
136 {
137 nativeBuildInputs = [ pkgs.makeWrapper ];
138 meta.mainProgram = "identity";
139 }
140 ''
141 mkdir -p $out/bin
142 makeWrapper ${lib.getExe identity-unwrapped} $out/bin/identity \
143 --prefix PATH : ${
144 lib.makeBinPath [
145 pkgs.git
146 pkgs.cue
147 ]
148 } \
149 --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue}
150 '';
151
152 # The security-key signature verifier (sigverify/README.md). Go,
153 # standard library only — hence vendorHash = null and no module fetch.
154 #
155 # The git its git-tag command runs is fixed at build time to this
156 # flake's git, as an absolute store path compiled into the binary. A
157 # wrapper that puts git on PATH would leave the binary inside it looking
158 # git up on PATH, and a caller's environment could change which git that
159 # is. Compiled in, there is no PATH lookup to change.
160 #
161 # Its tests run in the checkPhase against real ssh-keygen and git. The
162 # security-key cases among them need OpenSSH's sk-dummy authenticator,
163 # which only the sigverify-unit check supplies; here they skip, so a
164 # consumer building this package never builds OpenSSH.
165 sigverify = pkgs.buildGoModule {
166 pname = "valley-sigverify";
167 version = "0";
168 src = ../sigverify;
169 vendorHash = null;
170 ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ];
171 nativeCheckInputs = [
172 pkgs.git
173 pkgs.openssh
174 ];
175 meta.mainProgram = "sigverify";
176 };
177
178 # The pre-receive hook's policy (valleyhook/): what a push may write to a
179 # project a valley host serves. The same binary is the git user's login
180 # shell, which derives the pushing principal and pauses pushes until the
181 # host has converged. Go, standard library only — hence
182 # vendorHash = null and no module fetch. Its unit tests run in the
183 # checkPhase.
184 #
185 # The git it reads the repository with is fixed at build time, the way
186 # sigverify's is: an absolute store path compiled into the binary, so no
187 # PATH a hook runs under can change which git that is.
188 valleyhook = pkgs.buildGoModule {
189 pname = "valley-valleyhook";
190 version = "0";
191 src = withNote ../valleyhook;
192 modRoot = "valleyhook";
193 vendorHash = null;
194 preBuild = readsGoMod;
195 ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ];
196 # The walk's tests build hostile trees with real git.
197 nativeCheckInputs = [ pkgs.git ];
198 meta.mainProgram = "valleyhook";
199 };
200
201 # The note envelope's own tests, which hold it to refusing every line a
202 # relayer could append that one of its readers would refuse.
203 note = pkgs.buildGoModule {
204 pname = "valley-note";
205 version = "0";
206 src = ../note;
207 vendorHash = null;
208 };
209
210 # The Phase 3 integrator (dcr-439b771). Go, standard library only,
211 # same trade as attest — hence vendorHash = null and no module fetch.
212 integrator-unwrapped = pkgs.buildGoModule {
213 pname = "valley-integrator";
214 version = "0";
215 src = ../integrator;
216 vendorHash = null;
217 meta.mainProgram = "integrator";
218 };
219
220 # The shipping form. The integrator drives four programs rather than
221 # reimplementing what they do: attest judges every statement and
222 # every note, the valley deriver and cue compose the policy, and git
223 # holds the requests and the refs. All four are pinned to this
224 # flake's nixpkgs so an instance's integrators agree; `nix` is
225 # deliberately absent for the same reason it is absent from attest —
226 # a closure must be recomputed by the nix the machine actually runs.
227 integrator =
228 pkgs.runCommand "valley-integrator"
229 {
230 nativeBuildInputs = [ pkgs.makeWrapper ];
231 meta.mainProgram = "integrator";
232 }
233 ''
234 mkdir -p $out/bin
235 makeWrapper ${lib.getExe integrator-unwrapped} $out/bin/integrator \
236 --prefix PATH : ${
237 lib.makeBinPath [
238 pkgs.git
239 pkgs.cue
240 pkgs.natscli
241 attest
242 valley-script
243 ]
244 } \
245 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} \
246 --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} \
247 --set-default VALLEY_EVENT_SCHEMA ${../schema/events.cue}
248 '';
249}