gunk-dev/the-valley

hosts.nix

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