gunk-dev/the-valley

cli.nix

source32276166ab1fmain's published tip history
9.5 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 # The name main's policy still owes for status/**, so a change can be
149 # approved while the rename lands; a later change drops it once the
150 # renamed policy is on main.
151 valley-status-unit = packages.valley-go;
152
153 # Read origin's request/outcome refs and distinguish a pending request,
154 # a recorded decision and a landing, without moving the user's checkout.
155 # Each state is read again through --json, and jq holds the object to
156 # the valley-status/v1 contract.
157 valley-status = pkgs.runCommand "valley-status" {
158 nativeBuildInputs = [
159 pkgs.git
160 pkgs.jq
161 packages.valley-script
162 ];
163 } (builtins.readFile ./valley-status.sh);
164
165 # ready, unready and withdraw, through real pushes to a bare repo wired
166 # with the rendered pre-receive hook, as each principal: a change created
167 # at v1, a second version, the same head refused, a withdrawal, revived
168 # at the same version and then at a new one, a principal that neither
169 # owns the change nor holds the request grant refused by the hook, and
170 # the operator, who holds it, let through. Then each source of a change's ID — the jj
171 # header, the Change-Id trailer, a generated ID, --stamp — a header and a
172 # trailer that disagree, and a change whose commits hold a merge. Last, a
173 # change named by its handle is approved, reviewed and rebased at the head
174 # its record names: a record pushed with its branch moved elsewhere in the
175 # same push is refused, the branch at the recorded head is filed at that
176 # head, and a later version whose branch is elsewhere is refused. Then a
177 # draft: unready, ready again at the same head and at a new one, listed
178 # apart by pending, refused by approve, rebase and review's [a]pprove,
179 # and a request pending under either name warned of by unready and
180 # withdraw. The hook is followed from the protected host's rendered init
181 # script, so the rules the record meets are the ones a host applies.
182 valley-ready = pkgs.runCommand "valley-ready" {
183 nativeBuildInputs = [
184 pkgs.git
185 pkgs.jq
186 packages.valley-script
187 ];
188 initScript = hosts.protectedHost.config.systemd.services.valley-init.script;
189 passAsFile = [ "initScript" ];
190 } (builtins.readFile ./valley-ready.sh);
191
192 # The CLI is offered for aarch64-darwin, which nothing here builds or
193 # tests (flake.nix). This check holds that offer to evaluating: an input
194 # with no Darwin build fails here rather than on a Mac. The package's
195 # drvPath is forced while this check is evaluated, and its string context
196 # is discarded, so the Darwin derivations are written to the store but
197 # are not inputs of this one. Building this check builds and substitutes
198 # nothing for Darwin.
199 valley-darwin-eval = pkgs.runCommand "valley-darwin-eval" {
200 darwinDrv = builtins.unsafeDiscardStringContext self.packages.aarch64-darwin.valley.drvPath;
201 darwinSystem = self.packages.aarch64-darwin.valley.system;
202 } (builtins.readFile ./valley-darwin-eval.sh);
203}