gunk-dev/the-valley

flow.nix

source672eff5ffaecmain's published tip history
3.7 KiB
1# klaus (flow/): its shipping package, 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 packages,
8 ...
9}:
10let
11 inherit (packages) klaus version;
12
13 # What the checks verify beside klaus's tests: the version the package
14 # reports, and that no test reached tmux by default. Its own tests run in
15 # flow-build, which builds its unit form.
16 checker = packages.goModule {
17 pname = "klaus-flow-checker";
18 dir = ./flow-checker;
19 tests.postCheck = ''
20 go vet ./...
21 '';
22 meta.mainProgram = "flow-checker";
23 };
24
25 # The package rebuilt over the whole module, tests included, with the
26 # package's own vendored modules, running script in place of the build.
27 # It carries no version stamp: no test reads one. Test file paths stay
28 # real, as in buildGoModule's own check phase, so a test finds what it
29 # reads beside its source.
30 flowCheck =
31 name:
32 {
33 inputs ? [ ],
34 script,
35 }:
36 klaus.overrideAttrs (old: {
37 pname = "klaus-${name}";
38 version = "0";
39 ldflags = [ ];
40 src = packages.flowComplete;
41 inherit (klaus) goModules;
42 nativeBuildInputs = old.nativeBuildInputs ++ inputs;
43 buildPhase = ''
44 runHook preBuild
45 export GOFLAGS=''${GOFLAGS//-trimpath/}
46 ${script}
47 runHook postBuild
48 '';
49 doCheck = false;
50 installPhase = "touch $out";
51 dontFixup = true;
52 });
53
54 # tmux finds a server through $TMUX or a socket under $TMUX_TMPDIR. Both
55 # stay inside the build's temporary directory, as do HOME and the XDG
56 # directories, the runtime one included, so no test reads or reaches
57 # anything of the builder's. Each test starts its own server on its own
58 # socket; a socket left under TMUX_TMPDIR afterwards is a server some test
59 # reached by default, and fails the check. A test that cannot find a tool
60 # it needs fails rather than skipping.
61 isolated = script: ''
62 unset TMUX TMUX_PANE
63 export TMUX_TMPDIR="$TMPDIR/tmux" HOME="$TMPDIR/home" XDG_RUNTIME_DIR="$TMPDIR/run"
64 export XDG_CONFIG_HOME="$HOME/.config" XDG_STATE_HOME="$HOME/.local/state"
65 export XDG_CACHE_HOME="$HOME/.cache" XDG_DATA_HOME="$HOME/.local/share"
66 mkdir -p "$TMUX_TMPDIR" "$HOME"
67 mkdir -m 700 "$XDG_RUNTIME_DIR"
68 export KLAUS_TEST_TOOLS=required
69 ${script}
70 flow-checker sockets "$TMUX_TMPDIR"
71 '';
72in
73{
74 # The package as it ships, and the version it reports: the CLI's,
75 # stamped through the-valley/flow/internal/cmd.version.
76 flow-build =
77 pkgs.runCommand "klaus-flow-build"
78 {
79 nativeBuildInputs = [
80 klaus
81 checker.unit
82 ];
83 }
84 ''
85 flow-checker version klaus "klaus version ${version}"
86 touch $out
87 '';
88
89 # The unit tests. TestFlakeRefSurvivesNix has nix parse the flake
90 # references self-update builds, which needs no store: the dummy store
91 # serves an evaluation. It takes the newest nix, because nix 2.31, the
92 # pinned default, refuses git+git:// references.
93 flow-unit = flowCheck "unit" {
94 inputs = [
95 checker
96 pkgs.git
97 pkgs.tmux
98 pkgs.nixVersions.latest
99 ];
100 script = isolated ''
101 export NIX_CONFIG="store = dummy://"
102 go test ./...
103 '';
104 };
105
106 flow-vet = flowCheck "vet" {
107 script = "go vet ./...";
108 };
109
110 # The end-to-end suite, with the valley command its restack and landing
111 # scenarios run. It is the unstamped valley: those scenarios read no
112 # version.
113 flow-e2e = flowCheck "e2e" {
114 inputs = [
115 checker
116 pkgs.git
117 pkgs.tmux
118 pkgs.bash
119 packages.valley-unstamped
120 ];
121 script = isolated ''
122 go test -tags e2e ./e2e/...
123 '';
124 };
125}