gunk-dev/the-valley

flow.nix

source6a6791929c36main's published tip history
5.6 KiB
1# flow (flow/): its shipping packages, its unit tests, go vet, and its
2# end-to-end suite, which drives the real binary against real git and a
3# private tmux server.
4{
5 pkgs,
6 lib,
7 self,
8 system,
9 packages,
10 ...
11}:
12let
13 inherit (packages) valley-flow version;
14
15 # What the checks verify beside klaus's tests: the version the package
16 # reports, and that no test reached tmux by default. Its own tests run in
17 # flow-build, which builds its unit form.
18 checker = packages.goModule {
19 pname = "klaus-flow-checker";
20 dir = ./flow-checker;
21 tests.postCheck = ''
22 go vet ./...
23 '';
24 meta.mainProgram = "flow-checker";
25 };
26
27 # The package rebuilt over the whole module, tests included, with the
28 # package's own vendored modules, running script in place of the build.
29 # It carries no version stamp: no test reads one. Test file paths stay
30 # real, as in buildGoModule's own check phase, so a test finds what it
31 # reads beside its source.
32 flowCheck =
33 name:
34 {
35 inputs ? [ ],
36 script,
37 }:
38 valley-flow.overrideAttrs (old: {
39 pname = "klaus-${name}";
40 version = "0";
41 ldflags = [ ];
42 src = packages.flowComplete;
43 inherit (valley-flow) goModules;
44 nativeBuildInputs = old.nativeBuildInputs ++ inputs;
45 buildPhase = ''
46 runHook preBuild
47 export GOFLAGS=''${GOFLAGS//-trimpath/}
48 ${script}
49 runHook postBuild
50 '';
51 doCheck = false;
52 installPhase = "touch $out";
53 dontFixup = true;
54 });
55
56 # tmux finds a server through $TMUX or a socket under $TMUX_TMPDIR. Both
57 # stay inside the build's temporary directory, as do HOME and the XDG
58 # directories, the runtime one included, so no test reads or reaches
59 # anything of the builder's. Each test starts its own server on its own
60 # socket; a socket left under TMUX_TMPDIR afterwards is a server some test
61 # reached by default, and fails the check. A test that cannot find a tool
62 # it needs fails rather than skipping.
63 isolated = script: ''
64 unset TMUX TMUX_PANE
65 export TMUX_TMPDIR="$TMPDIR/tmux" HOME="$TMPDIR/home" XDG_RUNTIME_DIR="$TMPDIR/run"
66 export XDG_CONFIG_HOME="$HOME/.config" XDG_STATE_HOME="$HOME/.local/state"
67 export XDG_CACHE_HOME="$HOME/.cache" XDG_DATA_HOME="$HOME/.local/share"
68 mkdir -p "$TMUX_TMPDIR" "$HOME"
69 mkdir -m 700 "$XDG_RUNTIME_DIR"
70 export KLAUS_TEST_TOOLS=required
71 ${script}
72 flow-checker sockets "$TMUX_TMPDIR"
73 '';
74
75 # The flake's packages of the client, and the systems it offers them for.
76 flowPackages = [
77 "valley-flow"
78 "klaus"
79 ];
80 flowSystems = [
81 system
82 "aarch64-darwin"
83 ];
84
85 # What is wrong with the client's package attr on system s: a store path
86 # not named <attr>-<version>, which nix profile would install as an
87 # element of another name, or a mainProgram other than the executable
88 # named attr. Reading names evaluates the Darwin packages and builds
89 # nothing for Darwin.
90 identityFaults =
91 s: attr:
92 let
93 pkg = self.packages.${s}.${attr};
94 main = pkg.meta.mainProgram or "none";
95 in
96 lib.optional (pkg.name != "${attr}-${version}" || main != attr)
97 "packages.${s}.${attr} is ${pkg.name} with mainProgram ${main}, not ${attr}-${version} with ${attr}";
98 identity = lib.concatMap (s: lib.concatMap (identityFaults s) flowPackages) flowSystems;
99in
100{
101 # The packages as they ship, and the version they report: the CLI's,
102 # stamped through the-valley/flow/internal/cmd.version. Each of
103 # valley-flow and klaus holds the one program as bin/klaus, which prints
104 # it as klaus, which an installed self-update's smoke test reads, and as
105 # bin/valley-flow, which names itself valley flow, as does the valley
106 # package's `valley flow`, which runs valley-flow from PATH. A package
107 # away from its identity fails the check's evaluation.
108 flow-build =
109 if identity != [ ] then
110 throw "flow-build: ${lib.concatStringsSep "; " identity}"
111 else
112 pkgs.runCommand "klaus-flow-build"
113 {
114 nativeBuildInputs = [
115 self.packages.${system}.valley-flow
116 packages.valley
117 checker.unit
118 ];
119 packages = map (attr: self.packages.${system}.${attr}) flowPackages;
120 }
121 ''
122 for p in $packages; do
123 flow-checker version "klaus version ${version}" "$p/bin/klaus"
124 flow-checker version "valley flow version ${version}" "$p/bin/valley-flow"
125 done
126 flow-checker version "valley flow version ${version}" valley flow
127 touch $out
128 '';
129
130 # The unit tests. TestFlakeRefSurvivesNix has nix parse the flake
131 # references self-update builds, which needs no store: the dummy store
132 # serves an evaluation. It takes the newest nix, because nix 2.31, the
133 # pinned default, refuses git+git:// references. ps and lsof are how
134 # klaus reads processes where there is no /proc, as on macOS, and the
135 # tests read real ones with them here.
136 flow-unit = flowCheck "unit" {
137 inputs = [
138 checker
139 pkgs.git
140 pkgs.tmux
141 pkgs.nixVersions.latest
142 pkgs.procps
143 pkgs.lsof
144 ];
145 script = isolated ''
146 export NIX_CONFIG="store = dummy://"
147 go test ./...
148 '';
149 };
150
151 flow-vet = flowCheck "vet" {
152 script = "go vet ./...";
153 };
154
155 # The end-to-end suite, with the valley command its restack and landing
156 # scenarios run. It is the unstamped valley: those scenarios read no
157 # version.
158 flow-e2e = flowCheck "e2e" {
159 inputs = [
160 checker
161 pkgs.git
162 pkgs.tmux
163 pkgs.bash
164 packages.valley-unstamped
165 ];
166 script = isolated ''
167 go test -tags e2e ./e2e/...
168 '';
169 };
170}