gunk-dev/the-valley

packages.nix

sourcefe4ab5bf3cabmain's published tip history
7.3 KiB
1# Everything this flake builds: the CLI, the formatter, the attestation
2# helper, the integrator, the identity compiler, the security-key signature
3# 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 # Its tests run in the checkPhase against real ssh-keygen and git. The
132 # security-key cases among them need OpenSSH's sk-dummy authenticator,
133 # which only the sigverify-unit check supplies; here they skip, so a
134 # consumer building this package never builds OpenSSH.
135 sigverify-unwrapped = pkgs.buildGoModule {
136 pname = "valley-sigverify";
137 version = "0";
138 src = ../sigverify;
139 vendorHash = null;
140 nativeCheckInputs = [
141 pkgs.git
142 pkgs.openssh
143 ];
144 meta.mainProgram = "sigverify";
145 };
146
147 # The shipping form. The git-tag command reads tag objects with git, so
148 # git travels with it.
149 sigverify =
150 pkgs.runCommand "valley-sigverify"
151 {
152 nativeBuildInputs = [ pkgs.makeWrapper ];
153 meta.mainProgram = "sigverify";
154 }
155 ''
156 mkdir -p $out/bin
157 makeWrapper ${lib.getExe sigverify-unwrapped} $out/bin/sigverify \
158 --prefix PATH : ${lib.makeBinPath [ pkgs.git ]}
159 '';
160
161 # The Phase 3 integrator (dcr-439b771). Go, standard library only,
162 # same trade as attest — hence vendorHash = null and no module fetch.
163 integrator-unwrapped = pkgs.buildGoModule {
164 pname = "valley-integrator";
165 version = "0";
166 src = ../integrator;
167 vendorHash = null;
168 meta.mainProgram = "integrator";
169 };
170
171 # The shipping form. The integrator drives four programs rather than
172 # reimplementing what they do: attest judges every statement and
173 # every note, the valley deriver and cue compose the policy, and git
174 # holds the requests and the refs. All four are pinned to this
175 # flake's nixpkgs so an instance's integrators agree; `nix` is
176 # deliberately absent for the same reason it is absent from attest —
177 # a closure must be recomputed by the nix the machine actually runs.
178 integrator =
179 pkgs.runCommand "valley-integrator"
180 {
181 nativeBuildInputs = [ pkgs.makeWrapper ];
182 meta.mainProgram = "integrator";
183 }
184 ''
185 mkdir -p $out/bin
186 makeWrapper ${lib.getExe integrator-unwrapped} $out/bin/integrator \
187 --prefix PATH : ${
188 lib.makeBinPath [
189 pkgs.git
190 pkgs.cue
191 pkgs.natscli
192 attest
193 valley-script
194 ]
195 } \
196 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} \
197 --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} \
198 --set-default VALLEY_EVENT_SCHEMA ${../schema/events.cue}
199 '';
200}