gunk-dev/the-valley

packages.nix

source1a3e2182ecdemain's published tip history
6.2 KiB
1# Everything this flake builds: the CLI, the formatter, the attestation
2# helper, the integrator, the identity compiler. The flake wires these into
3# packages, apps, and the checks that drive them; nothing here knows about
4# 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 Phase 3 integrator (dcr-439b771). Go, standard library only,
130 # same trade as attest — hence vendorHash = null and no module fetch.
131 integrator-unwrapped = pkgs.buildGoModule {
132 pname = "valley-integrator";
133 version = "0";
134 src = ../integrator;
135 vendorHash = null;
136 meta.mainProgram = "integrator";
137 };
138
139 # The shipping form. The integrator drives four programs rather than
140 # reimplementing what they do: attest judges every statement and
141 # every note, the valley deriver and cue compose the policy, and git
142 # holds the requests and the refs. All four are pinned to this
143 # flake's nixpkgs so an instance's integrators agree; `nix` is
144 # deliberately absent for the same reason it is absent from attest —
145 # a closure must be recomputed by the nix the machine actually runs.
146 integrator =
147 pkgs.runCommand "valley-integrator"
148 {
149 nativeBuildInputs = [ pkgs.makeWrapper ];
150 meta.mainProgram = "integrator";
151 }
152 ''
153 mkdir -p $out/bin
154 makeWrapper ${lib.getExe integrator-unwrapped} $out/bin/integrator \
155 --prefix PATH : ${
156 lib.makeBinPath [
157 pkgs.git
158 pkgs.cue
159 pkgs.natscli
160 attest
161 valley-script
162 ]
163 } \
164 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} \
165 --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} \
166 --set-default VALLEY_EVENT_SCHEMA ${../schema/events.cue}
167 '';
168}