gunk-dev/the-valley

packages.nix

source818813f26b40main's published tip history
8.0 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 # Markdown prose is filled paragraphs hard-wrapped at 100 columns
8 # (ida-1ec03b1). One flag string backs both the formatter app and the
9 # prose-format check, so the two cannot drift. Embedded-language
10 # formatting is off so fenced code blocks pass through byte-for-byte.
11 proseFmtArgs = "--prose-wrap always --print-width 100 --embedded-language-formatting off";
12
13 # The integrator's CLI (bin/valley) wrapped for `nix run`. The script
14 # itself must keep running bare from any checkout — the package is the
15 # second of its two shipping modes, never a dependency of the first.
16 valley-script = pkgs.writeShellApplication {
17 name = "valley";
18 runtimeInputs = [
19 pkgs.git
20 pkgs.natscli # tail and replay only; every other verb needs just git
21 pkgs.cue # checks and review's [a]sk — it composes the policy layers
22 pkgs.less # review only — its v key is what takes a note
23 attest # review's [a]sk only — it runs the checks and signs them
24 ];
25 text = builtins.readFile ../bin/valley;
26 };
27
28 # The installed package: the wrapped script plus the shell completions,
29 # at the standard paths home-manager/NixOS auto-link.
30 valley = pkgs.symlinkJoin {
31 name = "valley";
32 paths = [ valley-script ];
33 nativeBuildInputs = [ pkgs.installShellFiles ];
34 postBuild = ''
35 installShellCompletion --bash --name valley ${../completions/valley.bash}
36 installShellCompletion --zsh --name _valley ${../completions/_valley}
37 '';
38 };
39
40 # `nix run .#fmt` — rewrap every tracked *.md in the repo to 100 columns.
41 prose-fmt = pkgs.writeShellApplication {
42 name = "valley-fmt";
43 runtimeInputs = [
44 pkgs.git
45 pkgs.prettier
46 ];
47 text = ''
48 cd "$(git rev-parse --show-toplevel)"
49 git ls-files -z -- '*.md' | xargs -0 --no-run-if-empty \
50 prettier ${proseFmtArgs} --write
51 '';
52 };
53
54 # The Phase 2 attestation helper (dcr-0de694f). Go, standard library
55 # only, note format included — hence vendorHash = null, and hence no
56 # module fetch at build time. Its unit tests run in the checkPhase and
57 # need git and ssh-keygen.
58 attest-unwrapped = pkgs.buildGoModule {
59 pname = "valley-attest";
60 version = "0";
61 src = ../attest;
62 vendorHash = null;
63 nativeCheckInputs = [
64 pkgs.git
65 pkgs.openssh
66 ];
67 meta.mainProgram = "attest";
68 };
69
70 # The shipping form. git and cue are pinned to this flake's nixpkgs,
71 # so every host composes and vets a statement with the same tools.
72 # Signing needs no tool at all: a note is signed on crypto/ed25519
73 # inside the binary. `nix` is deliberately NOT pinned: the check being
74 # attested to must be built by the nix the machine actually runs, and
75 # a nix carried in here would be a second one.
76 attest =
77 pkgs.runCommand "valley-attest"
78 {
79 nativeBuildInputs = [ pkgs.makeWrapper ];
80 meta.mainProgram = "attest";
81 }
82 ''
83 mkdir -p $out/bin
84 makeWrapper ${lib.getExe attest-unwrapped} $out/bin/attest \
85 --prefix PATH : ${
86 lib.makeBinPath [
87 pkgs.git
88 pkgs.cue
89 ]
90 } \
91 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue}
92 '';
93
94 # The identity registry compiler (dcr-b87f6e8). Go, standard library
95 # only, same trade as attest and the integrator — hence vendorHash = null
96 # and no module fetch. Its unit tests pin the note format's key hash
97 # against the reference vector attest is held to.
98 identity-unwrapped = pkgs.buildGoModule {
99 pname = "valley-identity";
100 version = "0";
101 src = ../identity;
102 vendorHash = null;
103 meta.mainProgram = "identity";
104 };
105
106 # The shipping form. git reads the registry out of the instance
107 # repository's tip and cue vets and exports it, both pinned to this
108 # flake's nixpkgs so every host compiles a registry the same way. The
109 # schema travels with the binary: a compiler judging a registry against a
110 # schema the consumer supplied would be no floor at all.
111 identity =
112 pkgs.runCommand "valley-identity"
113 {
114 nativeBuildInputs = [ pkgs.makeWrapper ];
115 meta.mainProgram = "identity";
116 }
117 ''
118 mkdir -p $out/bin
119 makeWrapper ${lib.getExe identity-unwrapped} $out/bin/identity \
120 --prefix PATH : ${
121 lib.makeBinPath [
122 pkgs.git
123 pkgs.cue
124 ]
125 } \
126 --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue}
127 '';
128
129 # The security-key signature verifier (sigverify/README.md). Go,
130 # standard library only — hence vendorHash = null and no module fetch.
131 #
132 # The git its git-tag command runs is fixed at build time to this
133 # flake's git, as an absolute store path compiled into the binary. A
134 # wrapper that puts git on PATH would leave the binary inside it looking
135 # git up on PATH, and a caller's environment could change which git that
136 # is. Compiled in, there is no PATH lookup to change.
137 #
138 # Its tests run in the checkPhase against real ssh-keygen and git. The
139 # security-key cases among them need OpenSSH's sk-dummy authenticator,
140 # which only the sigverify-unit check supplies; here they skip, so a
141 # consumer building this package never builds OpenSSH.
142 sigverify = pkgs.buildGoModule {
143 pname = "valley-sigverify";
144 version = "0";
145 src = ../sigverify;
146 vendorHash = null;
147 ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ];
148 nativeCheckInputs = [
149 pkgs.git
150 pkgs.openssh
151 ];
152 meta.mainProgram = "sigverify";
153 };
154
155 # The pre-receive hook's policy (valleyhook/): what a push may write to a
156 # project a valley host serves. Go, standard library only — hence
157 # vendorHash = null and no module fetch. Its unit tests run in the
158 # checkPhase.
159 #
160 # The git it reads the repository with is fixed at build time, the way
161 # sigverify's is: an absolute store path compiled into the binary, so no
162 # PATH a hook runs under can change which git that is.
163 valleyhook = pkgs.buildGoModule {
164 pname = "valley-valleyhook";
165 version = "0";
166 src = ../valleyhook;
167 vendorHash = null;
168 ldflags = [ "-X main.gitProgram=${lib.getExe pkgs.git}" ];
169 meta.mainProgram = "valleyhook";
170 };
171
172 # The Phase 3 integrator (dcr-439b771). Go, standard library only,
173 # same trade as attest — hence vendorHash = null and no module fetch.
174 integrator-unwrapped = pkgs.buildGoModule {
175 pname = "valley-integrator";
176 version = "0";
177 src = ../integrator;
178 vendorHash = null;
179 meta.mainProgram = "integrator";
180 };
181
182 # The shipping form. The integrator drives four programs rather than
183 # reimplementing what they do: attest judges every statement and
184 # every note, the valley deriver and cue compose the policy, and git
185 # holds the requests and the refs. All four are pinned to this
186 # flake's nixpkgs so an instance's integrators agree; `nix` is
187 # deliberately absent for the same reason it is absent from attest —
188 # a closure must be recomputed by the nix the machine actually runs.
189 integrator =
190 pkgs.runCommand "valley-integrator"
191 {
192 nativeBuildInputs = [ pkgs.makeWrapper ];
193 meta.mainProgram = "integrator";
194 }
195 ''
196 mkdir -p $out/bin
197 makeWrapper ${lib.getExe integrator-unwrapped} $out/bin/integrator \
198 --prefix PATH : ${
199 lib.makeBinPath [
200 pkgs.git
201 pkgs.cue
202 pkgs.natscli
203 attest
204 valley-script
205 ]
206 } \
207 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} \
208 --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} \
209 --set-default VALLEY_EVENT_SCHEMA ${../schema/events.cue}
210 '';
211}