gunk-dev/the-valley

cli.nix

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