gunk-dev/the-valley

packages.nix

source25a17935048dmain's published tip history
6.1 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 only — it composes the policy layers
22 pkgs.less # review only — its v key is what takes a note
23 ];
24 text = builtins.readFile ../bin/valley;
25 };
26
27 # The installed package: the wrapped script plus the shell completions,
28 # at the standard paths home-manager/NixOS auto-link.
29 valley = pkgs.symlinkJoin {
30 name = "valley";
31 paths = [ valley-script ];
32 nativeBuildInputs = [ pkgs.installShellFiles ];
33 postBuild = ''
34 installShellCompletion --bash --name valley ${../completions/valley.bash}
35 installShellCompletion --zsh --name _valley ${../completions/_valley}
36 '';
37 };
38
39 # `nix run .#fmt` — rewrap every tracked *.md in the repo to 100 columns.
40 prose-fmt = pkgs.writeShellApplication {
41 name = "valley-fmt";
42 runtimeInputs = [
43 pkgs.git
44 pkgs.prettier
45 ];
46 text = ''
47 cd "$(git rev-parse --show-toplevel)"
48 git ls-files -z -- '*.md' | xargs -0 --no-run-if-empty \
49 prettier ${proseFmtArgs} --write
50 '';
51 };
52
53 # The Phase 2 attestation helper (dcr-0de694f). Go, standard library
54 # only, note format included — hence vendorHash = null, and hence no
55 # module fetch at build time. Its unit tests run in the checkPhase and
56 # need git and ssh-keygen.
57 attest-unwrapped = pkgs.buildGoModule {
58 pname = "valley-attest";
59 version = "0";
60 src = ../attest;
61 vendorHash = null;
62 nativeCheckInputs = [
63 pkgs.git
64 pkgs.openssh
65 ];
66 meta.mainProgram = "attest";
67 };
68
69 # The shipping form. git and cue are pinned to this flake's nixpkgs,
70 # so every host composes and vets a statement with the same tools.
71 # Signing needs no tool at all: a note is signed on crypto/ed25519
72 # inside the binary. `nix` is deliberately NOT pinned: the check being
73 # attested to must be built by the nix the machine actually runs, and
74 # a nix carried in here would be a second one.
75 attest =
76 pkgs.runCommand "valley-attest"
77 {
78 nativeBuildInputs = [ pkgs.makeWrapper ];
79 meta.mainProgram = "attest";
80 }
81 ''
82 mkdir -p $out/bin
83 makeWrapper ${lib.getExe attest-unwrapped} $out/bin/attest \
84 --prefix PATH : ${
85 lib.makeBinPath [
86 pkgs.git
87 pkgs.cue
88 ]
89 } \
90 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue}
91 '';
92
93 # The identity registry compiler (dcr-b87f6e8). Go, standard library
94 # only, same trade as attest and the integrator — hence vendorHash = null
95 # and no module fetch. Its unit tests pin the note format's key hash
96 # against the reference vector attest is held to.
97 identity-unwrapped = pkgs.buildGoModule {
98 pname = "valley-identity";
99 version = "0";
100 src = ../identity;
101 vendorHash = null;
102 meta.mainProgram = "identity";
103 };
104
105 # The shipping form. git reads the registry out of the instance
106 # repository's tip and cue vets and exports it, both pinned to this
107 # flake's nixpkgs so every host compiles a registry the same way. The
108 # schema travels with the binary: a compiler judging a registry against a
109 # schema the consumer supplied would be no floor at all.
110 identity =
111 pkgs.runCommand "valley-identity"
112 {
113 nativeBuildInputs = [ pkgs.makeWrapper ];
114 meta.mainProgram = "identity";
115 }
116 ''
117 mkdir -p $out/bin
118 makeWrapper ${lib.getExe identity-unwrapped} $out/bin/identity \
119 --prefix PATH : ${
120 lib.makeBinPath [
121 pkgs.git
122 pkgs.cue
123 ]
124 } \
125 --set-default VALLEY_IDENTITY_SCHEMA ${../schema/identity.cue}
126 '';
127
128 # The Phase 3 integrator (dcr-439b771). Go, standard library only,
129 # same trade as attest — hence vendorHash = null and no module fetch.
130 integrator-unwrapped = pkgs.buildGoModule {
131 pname = "valley-integrator";
132 version = "0";
133 src = ../integrator;
134 vendorHash = null;
135 meta.mainProgram = "integrator";
136 };
137
138 # The shipping form. The integrator drives four programs rather than
139 # reimplementing what they do: attest judges every statement and
140 # every note, the valley deriver and cue compose the policy, and git
141 # holds the requests and the refs. All four are pinned to this
142 # flake's nixpkgs so an instance's integrators agree; `nix` is
143 # deliberately absent for the same reason it is absent from attest —
144 # a closure must be recomputed by the nix the machine actually runs.
145 integrator =
146 pkgs.runCommand "valley-integrator"
147 {
148 nativeBuildInputs = [ pkgs.makeWrapper ];
149 meta.mainProgram = "integrator";
150 }
151 ''
152 mkdir -p $out/bin
153 makeWrapper ${lib.getExe integrator-unwrapped} $out/bin/integrator \
154 --prefix PATH : ${
155 lib.makeBinPath [
156 pkgs.git
157 pkgs.cue
158 pkgs.natscli
159 attest
160 valley-script
161 ]
162 } \
163 --set-default VALLEY_ATTEST_SCHEMA ${../schema/attestation.cue} \
164 --set-default VALLEY_VERIFICATION_SCHEMA ${../schema/verification.cue} \
165 --set-default VALLEY_EVENT_SCHEMA ${../schema/events.cue}
166 '';
167}