gunk-dev/the-valley

hosts.nix

source818813f26b40main's published tip history
7.7 KiB
1# The hosts the module checks are about: eval-only instantiations of the
2# NixOS module, one per declaration worth holding it to. Evaluating one
3# catches option-surface and cue-export regressions without building or
4# booting anything, and the hook checks read the scripts these render.
5{
6 pkgs,
7 lib,
8 self,
9 system,
10}:
11let
12 # Each check host shares the machine baseline and supplies its own
13 # declaration (and, where the declaration asks for backup, the secret
14 # paths).
15 mkHost =
16 module:
17 lib.nixosSystem {
18 inherit system;
19 modules = [
20 self.nixosModules.default
21 {
22 fileSystems."/" = {
23 device = "/dev/disk/by-label/nixos";
24 fsType = "ext4";
25 };
26 boot.loader.grub.enable = false;
27 system.stateVersion = "25.11";
28 services.valley = {
29 enable = true;
30 authorizedKeys = [
31 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck0 valley-check"
32 ];
33 };
34 }
35 module
36 ];
37 };
38in
39{
40 # The example declaration enables backup, so this host supplies
41 # the four secret paths (eval-only placeholders).
42 host = mkHost {
43 services.valley = {
44 config = ../../examples/host.cue;
45 backup = {
46 repositoryFile = "/run/agenix/valley-restic-repo";
47 passwordFile = "/run/agenix/valley-restic-password";
48 sshKeyFile = "/run/agenix/valley-git-ssh-key";
49 knownHostsFile = "/var/lib/valley-backup/known_hosts";
50 };
51 };
52 };
53
54 # A declaration with no optional field set at all — no backup, no
55 # protection — must keep evaluating exactly as it did before those
56 # fields existed: zero restic machinery, no hook.
57 noBackupHost = mkHost {
58 services.valley.config = ../../examples/hosts/no-backup.cue;
59 };
60
61 # The example declaration with the secret paths left unset: the
62 # module must refuse with assertions naming the missing options.
63 noSecretsHost = mkHost {
64 services.valley.config = ../../examples/host.cue;
65 };
66
67 # Bus enabled, minimal declaration. The bus-e2e check drives this
68 # host's rendered hooks and stream-init against a real server.
69 busHost = mkHost {
70 services.valley = {
71 config = ../../examples/hosts/bus.cue;
72 bus.enable = true;
73 };
74 };
75
76 # Two mirror URLs the sandbox can serve: git resolves a relative
77 # URL against the pushing repo's directory, so the mirror-e2e
78 # check drives the rendered script with no substitution at all —
79 # one reachable sibling repo, one that does not exist.
80 mirrorHost = mkHost {
81 services.valley.config = ../../examples/hosts/mirrors.cue;
82 };
83
84 # The protection declaration, plus the machine half it needs: keys
85 # bound to the principal names it uses, and the request grant held by
86 # hand. The baseline key above is anonymous and stays in the list, so
87 # this host also renders the two forms of key side by side.
88 protectedHost = mkHost {
89 services.valley = {
90 config = ../../examples/hosts/protected.cue;
91 authorizedKeys = [
92 {
93 principal = "integrator";
94 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck1 integrator";
95 }
96 {
97 principal = "contributor";
98 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor";
99 }
100 {
101 principal = "requester";
102 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck3 requester";
103 }
104 ];
105 grants.request = [ "requester" ];
106 # released composes a hook of its own after the push policy: it
107 # refuses branches under frozen/, which the policy would accept.
108 extraPreReceive.released = pkgs.writeShellScript "valley-check-released-pre-receive" ''
109 while read -r _ _ ref; do
110 case "$ref" in
111 refs/heads/frozen/*)
112 echo "released: $ref is frozen" >&2
113 exit 1
114 ;;
115 esac
116 done
117 '';
118 };
119 };
120
121 # The same protection declaration with the controllers switched on. The
122 # integrator serves exactly what that declaration protects, so this host
123 # renders two controllers and no third; the paths are eval-only
124 # placeholders, like the backup host's.
125 integratorHost = mkHost {
126 services.valley = {
127 config = ../../examples/hosts/protected.cue;
128 integrator = {
129 enable = true;
130 signingKeyFile = "/run/agenix/valley-integrator-key";
131 knownSignersFile = "/var/lib/valley-instance/known_signers";
132 # The floor comes from "sealed", which declares protection, as the
133 # instance repository has to. Every other controller here reads the
134 # floor out of a repository that is not the one it serves, which is
135 # the cross-repository read the unit has to grant.
136 instanceProject = "sealed";
137 };
138 };
139 };
140
141 # The registry machinery switched on, over the same declaration. The
142 # signers file is not supplied: the compiler renders it, and a consumer
143 # that also named one would be asking which of the two won. The
144 # integrator's signing name is set here too, because a host that compiles
145 # a registry is a host whose registry publishes the integrator's key under
146 # a name, and the controller has to sign under that same name.
147 identityHost = mkHost {
148 services.valley = {
149 config = ../../examples/hosts/protected.cue;
150 identity.enable = true;
151 integrator = {
152 enable = true;
153 signingKeyFile = "/run/agenix/valley-integrator-key";
154 signingName = "integrator";
155 instanceProject = "sealed";
156 };
157 };
158 };
159
160 # The same host with the instance repository among the served projects —
161 # the shape a group's own instance takes, where the repository carrying
162 # the floor is itself integrated. The controller serving it reads the
163 # floor from the repository it is already serving.
164 integratorSelfHost = mkHost {
165 services.valley = {
166 config = ../../examples/hosts/protected.cue;
167 integrator = {
168 enable = true;
169 signingKeyFile = "/run/agenix/valley-integrator-key";
170 knownSignersFile = "/var/lib/valley-instance/known_signers";
171 instanceProject = "guarded";
172 };
173 };
174 };
175
176 # Hosts the module must refuse. Each is one way for the push policy to be
177 # quietly wrong, and each must fail an assertion naming what is wrong.
178 #
179 # The instance repository unprotected: the floor and the registry would
180 # be read from a main any key could push.
181 unprotectedInstanceHost = mkHost {
182 services.valley = {
183 config = ../../examples/hosts/protected.cue;
184 integrator = {
185 enable = true;
186 signingKeyFile = "/run/agenix/valley-integrator-key";
187 knownSignersFile = "/var/lib/valley-instance/known_signers";
188 instanceProject = "open";
189 };
190 };
191 };
192
193 # sshd accepting the principal variable from the client.
194 acceptEnvHost = mkHost {
195 services.valley.config = ../../examples/hosts/protected.cue;
196 services.openssh.settings.AcceptEnv = "LANG LC_* VALLEY_*";
197 };
198
199 # sshd honouring every variable a key's entry or ~/.ssh/environment sets.
200 permitUserEnvironmentHost = mkHost {
201 services.valley.config = ../../examples/hosts/protected.cue;
202 services.openssh.settings.PermitUserEnvironment = lib.mkForce "yes";
203 };
204
205 # One key declared untagged and tagged: which principal it pushes as
206 # would depend on which line sshd reads first.
207 conflictingKeysHost = mkHost {
208 services.valley = {
209 config = ../../examples/hosts/protected.cue;
210 authorizedKeys = [
211 "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor"
212 {
213 principal = "contributor";
214 key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPlaceholderKeyForEvalOnlyCheck2 contributor";
215 }
216 ];
217 };
218 };
219}