gunk-dev/the-valley

cli.nix

source3fb0dd7d42a9main's published tip history
2.8 KiB
1# bin/valley: that it stays a lint-clean script, what its review verb
2# anchors a note to, and what its deriver makes of a policy and a diff.
3{ pkgs, packages, ... }:
4{
5 # The CLI must stay a lint-clean script whose help verb answers
6 # without a repo or a remote — the cheap end of its eviction clause
7 # (dcr-74c3158); anything needing more graduates instead. The
8 # completions are held to the same bar, and the installed package
9 # must carry them at the auto-linked paths.
10 valley-cli = pkgs.runCommand "valley-cli" {
11 nativeBuildInputs = [
12 pkgs.shellcheck
13 pkgs.zsh
14 packages.valley
15 ];
16 cliScript = ../../bin/valley;
17 bashCompletion = ../../completions/valley.bash;
18 zshCompletion = ../../completions/_valley;
19 valley = packages.valley;
20 } (builtins.readFile ./valley-cli.sh);
21
22 # review's notes: the anchors are the whole claim, so they are
23 # pinned here rather than left to the reader of bin/valley. The
24 # session is real — a pty, real less, a pager filter that
25 # restructures the diff, and an $EDITOR that inserts lines while
26 # the pager is open — because every property under test is a
27 # property of that arrangement: that v is handed the raw buffer
28 # and not the rendering, that an inserted line becomes a note,
29 # and that the file and line it names are the ones it sat on.
30 review-notes = pkgs.runCommand "valley-review-notes" {
31 nativeBuildInputs = [
32 pkgs.git
33 pkgs.less
34 pkgs.util-linux # script(1), for the pty less insists on
35 packages.valley-script
36 ];
37 # The reviewer, as a script: four insertions and one edit of a
38 # line that was already there. The edit is deliberately far
39 # from every insertion, since -U0 would otherwise merge them
40 # into one hunk and the note would be dropped with it.
41 reviewer = pkgs.writeShellScript "valley-review-notes-editor" (
42 builtins.readFile ./review-notes-editor.sh
43 );
44 } (builtins.readFile ./review-notes.sh);
45
46 # The verification-policy deriver (dcr-f41f718). Composing the two
47 # layers is CUE's job and is pinned by cue-vet; matching paths is
48 # the script's own, and a path matcher is wrong exactly at the glob
49 # boundaries — `*` inside one segment against `**` across segments,
50 # `**` matching no segment at all — and at the sides of a diff a
51 # naive reader drops: a rename's old path and a deletion. Each is
52 # pinned by driving the real script over a scratch repository and
53 # the scratch policy in examples/policy/deriver/, whose floor is
54 # one glob boundary per class.
55 policy-deriver = pkgs.runCommand "valley-policy-deriver" {
56 nativeBuildInputs = [
57 pkgs.git
58 pkgs.cue
59 packages.valley-script
60 ];
61 fixtures = ../../examples/policy/deriver;
62 schema = ../../schema/verification.cue;
63 } (builtins.readFile ./policy-deriver.sh);
64}