gunk-dev/the-valley

hosts.nix

sourceef0e6a83672emain's published tip history
5.8 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 };
107 };
108
109 # The same protection declaration with the controllers switched on. The
110 # integrator serves exactly what that declaration protects, so this host
111 # renders two controllers and no third; the paths are eval-only
112 # placeholders, like the backup host's.
113 integratorHost = mkHost {
114 services.valley = {
115 config = ../../examples/hosts/protected.cue;
116 integrator = {
117 enable = true;
118 signingKeyFile = "/run/agenix/valley-integrator-key";
119 knownSignersFile = "/var/lib/valley-instance/known_signers";
120 # The floor comes from a repository this host serves and no
121 # controller serves: "open" is declared, unprotected, so it gets no
122 # controller of its own. Every controller here therefore reads the
123 # floor out of a repository that is not the one it serves, which is
124 # the cross-repository read the unit has to grant.
125 instanceProject = "open";
126 };
127 };
128 };
129
130 # The registry machinery switched on, over the same declaration. The
131 # signers file is not supplied: the compiler renders it, and a consumer
132 # that also named one would be asking which of the two won. The
133 # integrator's signing name is set here too, because a host that compiles
134 # a registry is a host whose registry publishes the integrator's key under
135 # a name, and the controller has to sign under that same name.
136 identityHost = mkHost {
137 services.valley = {
138 config = ../../examples/hosts/protected.cue;
139 identity.enable = true;
140 integrator = {
141 enable = true;
142 signingKeyFile = "/run/agenix/valley-integrator-key";
143 signingName = "integrator";
144 instanceProject = "open";
145 };
146 };
147 };
148
149 # The same host with the instance repository among the served projects —
150 # the shape a group's own instance takes, where the repository carrying
151 # the floor is itself integrated. The controller serving it reads the
152 # floor from the repository it is already serving.
153 integratorSelfHost = mkHost {
154 services.valley = {
155 config = ../../examples/hosts/protected.cue;
156 integrator = {
157 enable = true;
158 signingKeyFile = "/run/agenix/valley-integrator-key";
159 knownSignersFile = "/var/lib/valley-instance/known_signers";
160 instanceProject = "guarded";
161 };
162 };
163 };
164}