gunk-dev/the-valley

cli.nix

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