gunk-dev/the-valley

cli.nix

sourced4ea94f6bcd7main's published tip history
7.6 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# status helper's unit tests hold, and that its package evaluates for
6# aarch64-darwin.
7{
8 pkgs,
9 self,
10 system,
11 packages,
12 ...
13}:
14let
15 # A stand-in for git, sort or cue that fails one chosen call; see
16 # fail-nth.sh.
17 failNth = pkgs.writeShellScript "fail-nth" (builtins.readFile ./fail-nth.sh);
18in
19{
20 # The CLI must stay a lint-clean script whose help verb answers
21 # without a repo or a remote — the cheap end of its eviction clause
22 # (dcr-74c3158); anything needing more graduates instead. The
23 # completions are held to the same bar, and the installed package
24 # must carry them at the auto-linked paths.
25 valley-cli = pkgs.runCommand "valley-cli" {
26 nativeBuildInputs = [
27 pkgs.shellcheck
28 pkgs.zsh
29 packages.valley
30 ];
31 cliScript = ../../bin/valley;
32 bashCompletion = ../../completions/valley.bash;
33 zshCompletion = ../../completions/_valley;
34 valley = packages.valley;
35 } (builtins.readFile ./valley-cli.sh);
36
37 # review's notes: the anchors are the whole claim, so they are
38 # pinned here rather than left to the reader of bin/valley. The
39 # session is real — a pty, real less, a pager filter that
40 # restructures the diff, and an $EDITOR that inserts lines while
41 # the pager is open — because every property under test is a
42 # property of that arrangement: that v is handed the raw buffer
43 # and not the rendering, that an inserted line becomes a note,
44 # and that the file and line it names are the ones it sat on.
45 review-notes = pkgs.runCommand "valley-review-notes" {
46 nativeBuildInputs = [
47 pkgs.git
48 pkgs.less
49 pkgs.util-linux # script(1), for the pty less insists on
50 packages.valley-script
51 ];
52 # The reviewer, as a script: four insertions and one edit of a
53 # line that was already there. The edit is deliberately far
54 # from every insertion, since -U0 would otherwise merge them
55 # into one hunk and the note would be dropped with it.
56 reviewer = pkgs.writeShellScript "valley-review-notes-editor" (
57 builtins.readFile ./review-notes-editor.sh
58 );
59 } (builtins.readFile ./review-notes.sh);
60
61 # The verification-policy deriver (dcr-f41f718). Composing the two
62 # layers is CUE's job and is pinned by cue-vet; matching paths is
63 # the script's own, and a path matcher is wrong exactly at the glob
64 # boundaries — `*` inside one segment against `**` across segments,
65 # `**` matching no segment at all — and at the sides of a diff a
66 # naive reader drops: a rename's old path and a deletion. Each is
67 # pinned by driving the real script over a scratch repository and
68 # the scratch policy in examples/policy/deriver/, whose floor is
69 # one glob boundary per class. A check's cost is pinned the same way:
70 # marking a check slow moves it between the summary lines and the
71 # --cost lists, and changes nothing owed.
72 #
73 # And the deriver fails closed: failNth stands in for git, sort and
74 # cue, and fails each call the deriver makes in turn. Every failure
75 # must end the derivation with nothing on stdout, because a failure
76 # read as an empty list is a change that owes nothing. cliScript is
77 # bin/valley itself, because the package's wrapper puts its own git
78 # ahead of anything on PATH.
79 policy-deriver = pkgs.runCommand "valley-policy-deriver" {
80 nativeBuildInputs = [
81 pkgs.git
82 pkgs.cue
83 packages.valley-script
84 ];
85 fixtures = ../../examples/policy/deriver;
86 schema = ../../schema/verification.cue;
87 cliScript = ../../bin/valley;
88 inherit failNth;
89 } (builtins.readFile ./policy-deriver.sh);
90
91 # the-valley's own project layer (policy/project), which is what gates
92 # every change to this repository. A layer that stopped composing would
93 # stop every derivation once it landed, the derivation of its own fix
94 # included, so it is held here before it lands. The floor it is composed
95 # with is the example one: the owning valley's is not in this tree. The
96 # check also holds every check the layer names to being an attribute of
97 # this flake's checks, and holds a docs-only change to owing
98 # prose-format alone. And it holds a check's own files to owing that
99 # check: every file in this directory named after a check, and every
100 # other script here, read from the directory itself so a new one is
101 # held as soon as it is added.
102 own-policy = pkgs.runCommand "valley-own-policy" {
103 nativeBuildInputs = [
104 pkgs.git
105 pkgs.cue
106 packages.valley-script
107 ];
108 schema = ../../schema/verification.cue;
109 project = ../../policy/project;
110 floor = ../../examples/policy/instance/floor-format.cue;
111 template = ../../examples/policy/instance/template-docs.cue;
112 checkNames = builtins.attrNames self.checks.${system};
113 checkFiles = builtins.attrNames (builtins.readDir ./.);
114 } (builtins.readFile ./own-policy.sh);
115
116 # review's [a]pprove and the approve and rebase verbs, driven end to end
117 # over scratch repositories: a branch reviewed, the request filed, and
118 # what the receiving side then holds. The claim is about sequencing, so
119 # it is only observable from there — the bare repo logs every push it
120 # receives, and the check reads that log to see that ONE of them carried
121 # the evidence and the request together. Every check the scratch policy
122 # declares uses the command runner, for the reason attest-e2e gives: a
123 # nix build has no daemon. The packaged CLI carries its own schema, so
124 # the scratch projects that stand for projects other than the-valley
125 # carry no schema/. cliScript is bin/valley itself, for its other
126 # shipping mode: run straight from a the-valley checkout, it reads the
127 # schema there.
128 valley-request = pkgs.runCommand "valley-request" {
129 nativeBuildInputs = [
130 pkgs.git
131 pkgs.cue
132 pkgs.openssh
133 packages.attest
134 packages.valley-script
135 ];
136 schemaFile = ../../schema/verification.cue;
137 cliScript = ../../bin/valley;
138 inherit failNth;
139 } (builtins.readFile ./valley-request.sh);
140
141 # The status helper's Go tests (status/), run in the package's
142 # checkPhase: the outcome records it accepts, the names its JSON
143 # refuses, and its shell quoting held to the bash it replaced.
144 # valley-status below drives the verb through the CLI over real
145 # repositories.
146 valley-status-unit = packages.valley-status;
147
148 # Read origin's request/outcome refs and distinguish a pending request,
149 # a recorded decision and a landing, without moving the user's checkout.
150 # Each state is read again through --json, and jq holds the object to
151 # the valley-status/v1 contract.
152 valley-status = pkgs.runCommand "valley-status" {
153 nativeBuildInputs = [
154 pkgs.git
155 pkgs.jq
156 packages.valley-script
157 ];
158 } (builtins.readFile ./valley-status.sh);
159
160 # The CLI is offered for aarch64-darwin, which nothing here builds or
161 # tests (flake.nix). This check holds that offer to evaluating: an input
162 # with no Darwin build fails here rather than on a Mac. The package's
163 # drvPath is forced while this check is evaluated, and its string context
164 # is discarded, so the Darwin derivations are written to the store but
165 # are not inputs of this one. Building this check builds and substitutes
166 # nothing for Darwin.
167 valley-darwin-eval = pkgs.runCommand "valley-darwin-eval" {
168 darwinDrv = builtins.unsafeDiscardStringContext self.packages.aarch64-darwin.valley.drvPath;
169 darwinSystem = self.packages.aarch64-darwin.valley.system;
170 } (builtins.readFile ./valley-darwin-eval.sh);
171}