gunk-dev/the-valley

cli.nix

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