gunk-dev/the-valley

cli.nix

source6f81ceede276main's published tip history
10.7 KiB
1# bin/valley: that it stays a lint-clean script, what its review verb
2# anchors a note to, what its deriver makes of a policy and a diff, that
3# the-valley's own policy composes and names only checks that exist, what
4# its review verb publishes when it files an integration request, what its
5# Go verbs' unit tests hold, what its ready and withdraw verbs write to a
6# change's record through the real push hook, and that its package
7# evaluates for aarch64-darwin.
8{
9 pkgs,
10 self,
11 system,
12 packages,
13 hosts,
14 ...
15}:
16let
17 # A stand-in for git, sort or cue that fails one chosen call; see
18 # fail-nth.sh.
19 failNth = pkgs.writeShellScript "fail-nth" (builtins.readFile ./fail-nth.sh);
20in
21{
22 # The CLI must stay a lint-clean script whose help verb answers
23 # without a repo or a remote — the cheap end of its eviction clause
24 # (dcr-74c3158); anything needing more graduates instead. The
25 # completions are held to the same bar, and the installed package
26 # must carry them at the auto-linked paths.
27 valley-cli = pkgs.runCommand "valley-cli" {
28 nativeBuildInputs = [
29 pkgs.shellcheck
30 pkgs.zsh
31 packages.valley
32 ];
33 cliScript = ../../bin/valley;
34 bashCompletion = ../../completions/valley.bash;
35 zshCompletion = ../../completions/_valley;
36 valley = packages.valley;
37 } (builtins.readFile ./valley-cli.sh);
38
39 # review's notes: the anchors are the whole claim, so they are
40 # pinned here rather than left to the reader of bin/valley. The
41 # session is real — a pty, real less, a pager filter that
42 # restructures the diff, and an $EDITOR that inserts lines while
43 # the pager is open — because every property under test is a
44 # property of that arrangement: that v is handed the raw buffer
45 # and not the rendering, that an inserted line becomes a note,
46 # and that the file and line it names are the ones it sat on.
47 review-notes = pkgs.runCommand "valley-review-notes" {
48 nativeBuildInputs = [
49 pkgs.git
50 pkgs.less
51 pkgs.util-linux # script(1), for the pty less insists on
52 packages.valley-script
53 ];
54 # The reviewer, as a script: four insertions and one edit of a
55 # line that was already there. The edit is deliberately far
56 # from every insertion, since -U0 would otherwise merge them
57 # into one hunk and the note would be dropped with it.
58 reviewer = pkgs.writeShellScript "valley-review-notes-editor" (
59 builtins.readFile ./review-notes-editor.sh
60 );
61 } (builtins.readFile ./review-notes.sh);
62
63 # The verification-policy deriver (dcr-f41f718). Composing the two
64 # layers is CUE's job and is pinned by cue-vet; matching paths is
65 # the script's own, and a path matcher is wrong exactly at the glob
66 # boundaries — `*` inside one segment against `**` across segments,
67 # `**` matching no segment at all — and at the sides of a diff a
68 # naive reader drops: a rename's old path and a deletion. Each is
69 # pinned by driving the real script over a scratch repository and
70 # the scratch policy in examples/policy/deriver/, whose floor is
71 # one glob boundary per class. A check's cost is pinned the same way:
72 # marking a check slow moves it between the summary lines and the
73 # --cost lists, and changes nothing owed.
74 #
75 # And the deriver fails closed: failNth stands in for git, sort and
76 # cue, and fails each call the deriver makes in turn. Every failure
77 # must end the derivation with nothing on stdout, because a failure
78 # read as an empty list is a change that owes nothing. cliScript is
79 # bin/valley itself, because the package's wrapper puts its own git
80 # ahead of anything on PATH.
81 policy-deriver = pkgs.runCommand "valley-policy-deriver" {
82 nativeBuildInputs = [
83 pkgs.git
84 pkgs.cue
85 packages.valley-script
86 ];
87 fixtures = ../../examples/policy/deriver;
88 schema = ../../schema/verification.cue;
89 cliScript = ../../bin/valley;
90 inherit failNth;
91 } (builtins.readFile ./policy-deriver.sh);
92
93 # the-valley's own project layer (policy/project), which is what gates
94 # every change to this repository. A layer that stopped composing would
95 # stop every derivation once it landed, the derivation of its own fix
96 # included, so it is held here before it lands. The floor it is composed
97 # with is the example one: the owning valley's is not in this tree. The
98 # check also holds every check the layer names to being an attribute of
99 # this flake's checks, and holds a docs-only change to owing
100 # prose-format alone. And it holds a check's own files to owing that
101 # check: every file in this directory named after a check, and every
102 # other script here, read from the directory itself so a new one is
103 # held as soon as it is added.
104 own-policy = pkgs.runCommand "valley-own-policy" {
105 nativeBuildInputs = [
106 pkgs.git
107 pkgs.cue
108 packages.valley-script
109 ];
110 schema = ../../schema/verification.cue;
111 project = ../../policy/project;
112 floor = ../../examples/policy/instance/floor-format.cue;
113 template = ../../examples/policy/instance/template-docs.cue;
114 checkNames = builtins.attrNames self.checks.${system};
115 checkFiles = builtins.attrNames (builtins.readDir ./.);
116 } (builtins.readFile ./own-policy.sh);
117
118 # review's [a]pprove and the approve and rebase verbs, driven end to end
119 # over scratch repositories: a branch reviewed, the request filed, and
120 # what the receiving side then holds. The claim is about sequencing, so
121 # it is only observable from there — the bare repo logs every push it
122 # receives, and the check reads that log to see that ONE of them carried
123 # the evidence and the request together. Every check the scratch policy
124 # declares uses the command runner, for the reason attest-e2e gives: a
125 # nix build has no daemon. The packaged CLI carries its own schema, so
126 # the scratch projects that stand for projects other than the-valley
127 # carry no schema/. cliScript is bin/valley itself, for its other
128 # shipping mode: run straight from a the-valley checkout, it reads the
129 # schema there.
130 valley-request = pkgs.runCommand "valley-request" {
131 nativeBuildInputs = [
132 pkgs.git
133 pkgs.cue
134 pkgs.openssh
135 packages.attest
136 packages.valley-script
137 ];
138 schemaFile = ../../schema/verification.cue;
139 cliScript = ../../bin/valley;
140 inherit failNth;
141 } (builtins.readFile ./valley-request.sh);
142
143 # The Go verbs' tests (status/), run in valley-go's checkPhase: the
144 # outcome records status accepts, the names its JSON refuses, and its
145 # shell quoting held to the bash it replaced. valley-status and
146 # valley-ready drive the verbs through the CLI over real repositories.
147 valley-go-unit = packages.valley-go;
148
149 # Read origin's request/outcome refs and distinguish a pending request,
150 # a recorded decision and a landing, without moving the user's checkout.
151 # Each state is read again through --json, and jq holds the object to
152 # the valley-status/v1 contract.
153 valley-status = pkgs.runCommand "valley-status" {
154 nativeBuildInputs = [
155 pkgs.git
156 pkgs.jq
157 packages.valley-script
158 ];
159 } (builtins.readFile ./valley-status.sh);
160
161 # ready, unready and withdraw, through real pushes to a bare repo wired
162 # with the rendered pre-receive hook, as each principal: a change created
163 # at v1, a second version, the same head refused, a withdrawal, revived
164 # at the same version and then at a new one, a principal that neither
165 # owns the change nor holds the request grant refused by the hook, and
166 # the operator, who holds it, let through. Then each source of a change's ID — the jj
167 # header, the Change-Id trailer, a generated ID, --stamp — a header and a
168 # trailer that disagree, and a change whose commits hold a merge. Last, a
169 # change named by its handle is approved, reviewed and rebased at the head
170 # its record names: a record pushed with its branch moved elsewhere in the
171 # same push is refused, the branch at the recorded head is filed at that
172 # head, and a later version whose branch is elsewhere is refused. Then a
173 # draft: unready, ready again at the same head and at a new one, listed
174 # apart by pending, refused by approve, rebase and review's [a]pprove
175 # whether it is named by its handle or its branch, and a request pending
176 # under either name warned of by unready and withdraw, a request for an
177 # earlier version's branch too. A review left open while another
178 # principal unreadies the change, or readies a new version, refuses to
179 # act on it. A branch no record is on is acted on as a branch, and one
180 # two records are on is refused. The hook is followed from the protected
181 # host's rendered init script, so the rules the record meets are the
182 # ones a host applies.
183 valley-ready = pkgs.runCommand "valley-ready" {
184 nativeBuildInputs = [
185 pkgs.git
186 pkgs.jq
187 packages.valley-script
188 ];
189 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
190 passAsFile = [ "initScript" ];
191 } (builtins.readFile ./valley-ready.sh);
192
193 # valley changes and valley pending over the projects of one test host,
194 # made by the integrator host's rendered valley-init, so discovery reads
195 # the project list a host publishes and every record goes through the
196 # hook it installs. Two repositories with ready, draft and withdrawn
197 # records; handles unique across them; one listed repository that cannot
198 # be read; --repo; a version landed by fast-forward, one landed as a new
199 # commit with a transfer statement the integrator signed, one consumed
200 # with no evidence, and one whose statement another key signed; includes
201 # as the nearest ancestor only; pending's human shape and --owes; and a
202 # branch name read as a branch again once its change has landed.
203 valley-changes = pkgs.runCommand "valley-changes" {
204 nativeBuildInputs = [
205 pkgs.git
206 pkgs.jq
207 pkgs.openssh
208 packages.valley-script
209 packages.valley-go
210 packages.attest
211 ];
212 initScript = hosts.integratorHost.config.systemd.services.valley-init.script;
213 passAsFile = [ "initScript" ];
214 # The floor --owes derives under.
215 floor = ../../examples/policy/instance;
216 } (builtins.readFile ./valley-changes.sh);
217
218 # The CLI is offered for aarch64-darwin, which nothing here builds or
219 # tests (flake.nix). This check holds that offer to evaluating: an input
220 # with no Darwin build fails here rather than on a Mac. The package's
221 # drvPath is forced while this check is evaluated, and its string context
222 # is discarded, so the Darwin derivations are written to the store but
223 # are not inputs of this one. Building this check builds and substitutes
224 # nothing for Darwin.
225 valley-darwin-eval = pkgs.runCommand "valley-darwin-eval" {
226 darwinDrv = builtins.unsafeDiscardStringContext self.packages.aarch64-darwin.valley.drvPath;
227 darwinSystem = self.packages.aarch64-darwin.valley.system;
228 } (builtins.readFile ./valley-darwin-eval.sh);
229}