gunk-dev/the-valley

host-module.nix

sourceb115ae7362ffmain's published tip history
74.7 KiB
1# What the NixOS modules render from a declaration, and what they must refuse.
2# This covers the valley host module, the web publisher module alongside it,
3# and the web receiver module on an edge host.
4# The refusals are eval-time: a host that must not evaluate is caught by a
5# throw here, since there is nothing to build once it has. What a host does
6# render is pinned by module-eval.sh over the rendered scripts.
7#
8# Every host here runs the stand-ins for this flake's programs
9# (nix/checks/hosts.nix). Nothing here runs a program: each assertion is
10# about the units, hooks and scripts the module renders, which name a
11# program's path and the flags it is given. So module-eval changes when the
12# module, a host declaration or this check does, and not when a program
13# does.
14{
15 pkgs,
16 lib,
17 self,
18 stubbedHosts,
19 ...
20}:
21let
22 inherit (stubbedHosts)
23 unprotectedInstanceHost
24 acceptEnvHost
25 matchAcceptEnvHost
26 wildcardAcceptEnvHost
27 quotedAcceptEnvHost
28 tabAcceptEnvHost
29 setEnvHost
30 permitUserEnvironmentHost
31 conflictingKeysHost
32 host
33 noBackupHost
34 noSecretsHost
35 protectedHost
36 busHost
37 mirrorHost
38 integratorHost
39 integratorSelfHost
40 restrictedHost
41 spacedSignerProjectsHost
42 unicodeSpacedSignerProjectsHost
43 identityHost
44 workerHost
45 capacityWorkerHost
46 defaultWorkerHost
47 narrowedWorkerHost
48 mismatchedWorkerHost
49 buildSliceHost
50 noSliceWorkerHost
51 unrestrictedWorkerHost
52 widerWorkerHost
53 integratorNamedWorkerHost
54 restackerHost
55 defaultRestackerHost
56 unservedRestackerHost
57 keylessRestackerHost
58 telemetryHost
59 ;
60
61 # The web publisher's module (nix/web-publisher.nix) beside the host
62 # module, over integratorHost: its instance repository is the one the
63 # controllers read the floor from. The host also has a backup key the
64 # publisher must not read. The publisher is a stand-in, as the host's
65 # programs are. webPublisherOffHost imports the module and leaves it off.
66 webPublisherStub = pkgs.writeShellScriptBin "valley-web-publish" ''
67 echo "valley-web-publish: a stand-in the module checks render hosts over, which runs nothing" >&2
68 exit 1
69 '';
70 webPublisherOffHost = stubbedHosts.integratorHost.extendModules {
71 modules = [
72 self.nixosModules.web-publisher
73 { services.valley.webPublisher.package = webPublisherStub; }
74 ];
75 };
76 webPublisherHost = webPublisherOffHost.extendModules {
77 modules = [
78 {
79 networking.hostName = "valley-host";
80 services.valley.backup.sshKeyFile = "/run/agenix/valley-git-ssh-key";
81 services.valley.webPublisher = {
82 enable = true;
83 destination = "example.org";
84 receiver = "https://example.org";
85 receiverTokenFile = "/run/keys/valley-web-receiver-token";
86 allowedAddresses = [
87 "192.0.2.10"
88 "2001:db8::10"
89 ];
90 principals = {
91 operator = "operator";
92 alice = "agent";
93 };
94 };
95 }
96 ];
97 };
98 # The publisher on a host whose declaration asks for a backup.
99 backupWebPublisherHost = webPublisherHost.extendModules {
100 modules = [
101 {
102 services.valley.config = lib.mkForce (
103 pkgs.runCommand "protected-with-backup.cue" { } ''
104 cat ${../../examples/hosts/protected.cue} > $out
105 printf '\nbackup: target: "restic-sftp"\n' >> $out
106 ''
107 );
108 services.valley.backup = {
109 repositoryFile = "/run/agenix/valley-restic-repo";
110 passwordFile = "/run/agenix/valley-restic-password";
111 knownHostsFile = "/var/lib/valley-backup/known_hosts";
112 };
113 }
114 ];
115 };
116 # The publisher reading the registry at a ref the instance repository's
117 # protection does not cover.
118 unprotectedRegistryWebPublisherHost = webPublisherHost.extendModules {
119 modules = [ { services.valley.identity.ref = "refs/heads/registry"; } ];
120 };
121 # The publisher reading the registry at a short ref name, which git would
122 # resolve by trying other names in turn.
123 shortRegistryRefWebPublisherHost = webPublisherHost.extendModules {
124 modules = [ { services.valley.identity.ref = "registry"; } ];
125 };
126 # The publisher with no instance repository to discover the projects and
127 # the signers through.
128 noInstanceWebPublisherHost = webPublisherHost.extendModules {
129 modules = [
130 {
131 services.valley.integrator = {
132 instanceProject = lib.mkForce null;
133 instancePolicy = "/var/lib/valley-instance/policy/instance";
134 };
135 }
136 ];
137 };
138
139 # The web receiver module (nix/web-receiver.nix) on a standalone edge
140 # host, evaluated with stand-in binaries. webReceiverOffHost imports the
141 # module while leaving it disabled.
142 edgeStub =
143 name:
144 pkgs.writeShellScriptBin name ''
145 echo "${name}: a stand-in the module checks render hosts over, which runs nothing" >&2
146 exit 1
147 '';
148 webReceiverOffHost = lib.nixosSystem {
149 inherit pkgs;
150 modules = [
151 self.nixosModules.web-receiver
152 {
153 fileSystems."/" = {
154 device = "/dev/disk/by-label/nixos";
155 fsType = "ext4";
156 };
157 boot.loader.grub.enable = false;
158 system.stateVersion = "25.11";
159 services.valley.webReceiver = {
160 receiverPackage = edgeStub "valley-web-receive";
161 webPackage = edgeStub "valley-web";
162 };
163 }
164 ];
165 };
166 webReceiverHost = webReceiverOffHost.extendModules {
167 modules = [
168 {
169 services.valley.webReceiver = {
170 enable = true;
171 instance = "valley-host";
172 destination = "example.org";
173 verifiers = [ "valley-host/web-export+1a2b3c4d+AQ" ];
174 tokenFile = "/run/keys/valley-web-receiver-token";
175 listen = "192.0.2.10:8081";
176 webListen = "127.0.0.1:8080";
177 };
178 }
179 ];
180 };
181 # The receiver and valley-web with readers signing in at an origin.
182 webReaderHost = webReceiverHost.extendModules {
183 modules = [ { services.valley.webReceiver.origin = "https://example.org"; } ];
184 };
185 # The receiver with its token in the Nix store, and with no verifier.
186 storeTokenWebReceiverHost = webReceiverHost.extendModules {
187 modules = [
188 { services.valley.webReceiver.tokenFile = lib.mkForce "${pkgs.writeText "token" "x"}"; }
189 ];
190 };
191 noVerifierWebReceiverHost = webReceiverHost.extendModules {
192 modules = [ { services.valley.webReceiver.verifiers = lib.mkForce [ ]; } ];
193 };
194 # The publisher allowed to connect to no address.
195 noAddressWebPublisherHost = webPublisherHost.extendModules {
196 modules = [ { services.valley.webPublisher.allowedAddresses = lib.mkForce [ ]; } ];
197 };
198 # The publisher allowed the canary its unit's check must be denied.
199 canaryWebPublisherHost = webPublisherHost.extendModules {
200 modules = [ { services.valley.webPublisher.allowedAddresses = [ "198.51.100.0/24" ]; } ];
201 };
202 # The publisher with its token in the Nix store.
203 storeTokenWebPublisherHost = webPublisherHost.extendModules {
204 modules = [
205 { services.valley.webPublisher.receiverTokenFile = lib.mkForce "${pkgs.writeText "token" "x"}"; }
206 ];
207 };
208
209 # The same, with the source named as one of the module's own.
210 collidingTelemetryHost = telemetryHost.extendModules {
211 modules = [
212 {
213 services.valley.telemetry.localSources = [
214 {
215 name = "worker";
216 description = "a name the module already uses";
217 units = [ "converge.service" ];
218 }
219 ];
220 }
221 ];
222 };
223
224 failedAssertions = builtins.filter (a: !a.assertion) (
225 host.config.assertions
226 ++ noBackupHost.config.assertions
227 ++ busHost.config.assertions
228 ++ mirrorHost.config.assertions
229 ++ protectedHost.config.assertions
230 ++ integratorHost.config.assertions
231 ++ integratorSelfHost.config.assertions
232 ++ restrictedHost.config.assertions
233 ++ identityHost.config.assertions
234 ++ workerHost.config.assertions
235 ++ capacityWorkerHost.config.assertions
236 ++ defaultWorkerHost.config.assertions
237 ++ narrowedWorkerHost.config.assertions
238 ++ restackerHost.config.assertions
239 ++ telemetryHost.config.assertions
240 ++ defaultRestackerHost.config.assertions
241 ++ buildSliceHost.config.assertions
242 ++ webPublisherHost.config.assertions
243 ++ webPublisherOffHost.config.assertions
244 ++ webReceiverHost.config.assertions
245 ++ webReaderHost.config.assertions
246 ++ webReceiverOffHost.config.assertions
247 );
248
249 missingSecretAssertions = builtins.filter (a: !a.assertion) noSecretsHost.config.assertions;
250
251 # The hosts the module must refuse, each with the words its refusal must
252 # say. An assertion that stopped firing would leave the push policy
253 # quietly wrong, so each is held to naming what is wrong.
254 refusedHosts = [
255 {
256 host = unprotectedInstanceHost;
257 says = "whose refs/heads/main is not protected";
258 why = "an instance repository without protection would let any key that can push rewrite the floor and the registry";
259 }
260 {
261 host = acceptEnvHost;
262 says = "AcceptEnv";
263 why = "sshd accepting the principal variable from the client would let any key name any principal";
264 }
265 {
266 host = matchAcceptEnvHost;
267 says = "GIT_CONFIG_*";
268 why = "sshd accepting GIT_ variables in the git user's Match block, in whatever case the keyword is written, would let a client set git's configuration";
269 }
270 {
271 host = wildcardAcceptEnvHost;
272 says = "G?T_*";
273 why = "a wildcard that admits GIT_ variables admits them however it is spelled";
274 }
275 {
276 host = quotedAcceptEnvHost;
277 says = "holds a quote or a backslash";
278 why = "a quoted name is one sshd unquotes and admits, so a check that read it differently would pass it";
279 }
280 {
281 host = tabAcceptEnvHost;
282 says = "VALLEY_PRINCIPAL from the client";
283 why = "a name after a tab is a name sshd admits";
284 }
285 {
286 host = setEnvHost;
287 says = "SetEnv";
288 why = "sshd setting the principal itself would make every key push as it";
289 }
290 {
291 host = permitUserEnvironmentHost;
292 says = "PermitUserEnvironment";
293 why = "a PermitUserEnvironment wider than the principal variable would let a key's entry or ~/.ssh/environment set what the push policy does not expect";
294 }
295 {
296 host = spacedSignerProjectsHost;
297 says = "services.valley.integrator.signerProjects holds";
298 why = "a project with a space in it would be read back as two projects the declaration never listed";
299 }
300 {
301 host = unicodeSpacedSignerProjectsHost;
302 says = "services.valley.integrator.signerProjects holds";
303 why = "a project holding a no-break space would be read back by the integrator as two projects, or refused at start";
304 }
305 {
306 host = noSliceWorkerHost;
307 says = "services.valley.worker.enable needs services.valley.buildSlice.enable";
308 why = "a worker on a host without the build slice would build uncapped, and capping every build of the daemon is the host's decision, not the worker's";
309 }
310 {
311 host = unrestrictedWorkerHost;
312 says = "must restrict worker.valley.invalid/attestations, the worker's signer, to exactly the worker's projects";
313 why = "a worker whose signer no project list restricts would have its evidence counted in every project by every controller that holds its key";
314 }
315 {
316 host = widerWorkerHost;
317 says = "must restrict worker.valley.invalid/attestations, the worker's signer, to exactly the worker's projects";
318 why = "a worker trusted in a project it does not build would be trusted where it does no work";
319 }
320 {
321 host = mismatchedWorkerHost;
322 says = "must restrict worker.valley.invalid/attestations, the worker's signer, to exactly the worker's projects";
323 why = "a host that writes the signer's list must write the worker's projects, and the module's own entry must not be merged into it";
324 }
325 {
326 host = integratorNamedWorkerHost;
327 says = "services.valley.worker.signerName must differ from integrator";
328 why = "a worker signing under the controllers' name would make every controller refuse to start";
329 }
330 {
331 host = unservedRestackerHost;
332 says = "services.valley.restacker.projects must name at least one project, and only projects this host serves, and it names nowhere";
333 why = "a controller for a project the host does not serve would fail every pass";
334 }
335 {
336 host = keylessRestackerHost;
337 says = "services.valley.restacker.sshKeyFile must be set";
338 why = "a restacker with no key cannot reach the repositories it serves, except as a user that could write them on disk";
339 }
340 {
341 host = conflictingKeysHost;
342 says = "more than one principal tag";
343 why = "a key declared under two tags would push as whichever entry sshd reads first";
344 }
345 {
346 host = unprotectedRegistryWebPublisherHost;
347 says = "whose refs/heads/registry is not protected";
348 why = "a publisher reading the registry at an unprotected ref would let any key that can push there grant anyone read";
349 }
350 {
351 host = shortRegistryRefWebPublisherHost;
352 says = "services.valley.identity.ref is registry, which is not a full ref name";
353 why = "git resolves a ref that is not a full name by trying several refs in turn, and a pusher can make one of them";
354 }
355 {
356 host = storeTokenWebPublisherHost;
357 says = "services.valley.webPublisher.receiverTokenFile is in the Nix store";
358 why = "the publisher's receiver token is in the Nix store";
359 }
360 {
361 host = noAddressWebPublisherHost;
362 says = "services.valley.webPublisher.allowedAddresses is empty: list the receiver's IP addresses";
363 why = "a publisher with no allowed address would either reach nothing or, allowed everything, reach any host";
364 }
365 {
366 host = canaryWebPublisherHost;
367 says = "services.valley.webPublisher.allowedAddresses covers 198.51.100.1";
368 why = "the check before each pass could not prove the filter in force if the filter allowed its canary";
369 }
370 {
371 host = storeTokenWebReceiverHost;
372 says = "services.valley.webReceiver.tokenFile is in the Nix store";
373 why = "the receiver's token is in the Nix store";
374 }
375 {
376 host = noVerifierWebReceiverHost;
377 says = "services.valley.webReceiver.verifiers names no verifier line";
378 why = "the receiver pins no verifier";
379 }
380 {
381 host = collidingTelemetryHost;
382 says = "source names must be unique, and localSources or remoteSources repeats one: worker";
383 why = "a local source named as one of the module's own would make the catalog name two sources alike";
384 }
385 {
386 host = noInstanceWebPublisherHost;
387 says = "services.valley.webPublisher needs services.valley.integrator.instanceProject";
388 why = "a publisher with no instance repository has no publication to discover the projects and their signers through";
389 }
390 ];
391
392 unrefusedHosts = builtins.filter (
393 r: !(lib.any (a: !a.assertion && lib.hasInfix r.says a.message) r.host.config.assertions)
394 ) refusedHosts;
395
396 protectedKeyLines = protectedHost.config.users.users.git.openssh.authorizedKeys.keys;
397
398 resticRenderedWithoutDeclaration =
399 noBackupHost.config.systemd.services ? "restic-backups-valley"
400 || noBackupHost.config.systemd.timers ? "restic-backups-valley";
401
402 # The bus defaults off; a host that never asked for one must
403 # render zero bus machinery.
404 busRenderedWithoutEnable =
405 noBackupHost.config.systemd.services ? valley-bus
406 || noBackupHost.config.systemd.services ? valley-bus-init;
407
408 # A declaration with no protection block and no tagged key still gets
409 # the push policy on every project — the policy is the host's, and a
410 # protection block only adds protected refs to it — and nothing of the
411 # principal machinery: no tag on a key, no sshd change.
412 protectionRenderedWithoutDeclaration =
413 noBackupHost.config.services.openssh.settings ? PermitUserEnvironment
414 || lib.any (lib.hasInfix "environment=") (
415 noBackupHost.config.users.users.git.openssh.authorizedKeys.keys
416 );
417
418 policyMissingWithoutDeclaration =
419 !(lib.hasInfix "valley-protect-the-valley" noBackupHost.config.systemd.services.valley-init.script);
420
421 # The integrator's units. What a controller *does* is not checked here
422 # and no VM is booted: that is integrator-e2e's job (the real binaries
423 # over real repositories) and, past it, live exercise on a host. These
424 # assertions cover the wiring — that a controller is rendered for what
425 # the declaration protects and for nothing else, under an identity that
426 # is not the git user's, pointed at the key and the signers the consumer
427 # supplied.
428 #
429 # There is a seam between those two halves that neither reaches, and in a
430 # single day it produced five deployment failures. Every assertion below is
431 # an eval of the unit's text; integrator-e2e runs the binaries with no unit
432 # around them at all. What sits between is the unit's sandbox and identity
433 # meeting the filesystem the binaries actually use at runtime:
434 #
435 # - git refusing a repository the service does not own (bd-500adf7)
436 # - a push authenticating as the operator rather than as the run
437 # (bd-353c59d)
438 # - no writable temporary directory, so no worktree could be made
439 # - the worktree metadata root, created by whichever service reached it
440 # first and then unchmodable by the other, which failed valley-init and
441 # took every valley unit down with it
442 # - the state directory not writable under ProtectSystem=strict unless
443 # the unit names it, which the previous fix had made the scratch root
444 #
445 # Each was found by a host, minutes of a live service after a deploy that
446 # every check here passed. They compose: the third's fix set up the fourth,
447 # and the fourth's fix set up the fifth. That is the argument. A seam whose
448 # failures feed each other is not one to pin an assertion at a time, and
449 # each assertion here that marks a piece of it — the git ownership
450 # exception, TMPDIR, the worktrees root, ReadWritePaths — marks a place a
451 # smoke boot would have spoken first.
452 #
453 # A nixosTest that boots one host, starts the units and reconciles one
454 # change end to end is the next check this module needs. Nothing else
455 # closes the seam, and five incidents is enough evidence of what it costs
456 # to leave open. Not built here.
457 #
458 # Protection and integration are separable declarations: protectedHost
459 # declares the same protected projects with the service off, and must
460 # evaluate to no controller at all.
461 integratorRenderedWithoutEnable =
462 protectedHost.config.systemd.services ? "valley-integrator@"
463 || protectedHost.config.systemd.targets ? valley-integrators
464 || lib.hasInfix "sharedRepository" protectedHost.config.systemd.services.valley-init.script;
465
466 # One target pulls in each controller, and another the path unit that
467 # publishes each project's queued moves, landings included.
468 integratorWants = integratorHost.config.systemd.targets.valley-integrators.wants;
469 controllers = lib.filter (lib.hasPrefix "valley-integrator@") integratorWants;
470 publishers = integratorHost.config.systemd.targets.valley-publish.wants;
471
472 integratorUser = integratorHost.config.systemd.services."valley-integrator@".serviceConfig.User;
473
474 # The controller is not the repositories' owner, which is the whole point
475 # of running it as itself — so git needs an ownership exception, and
476 # where that exception lives is load-bearing. GIT_CONFIG_* is command
477 # scope, the only scope besides system and global that safe.directory is
478 # read from, and the unit's environment is inherited by every git the
479 # controller drives. It names one repository: a wildcard here would hand
480 # a compromised controller every repository on the host.
481 integratorGitEnv = integratorHost.config.systemd.services."valley-integrator@".environment;
482
483 # The count is what git reads; an entry past it is an entry git ignores,
484 # silently. So it is checked against the entries actually rendered rather
485 # than against a number written here, which would have to be edited every
486 # time a grant is added and would go on passing if it were not.
487 integratorSafeDirectory =
488 integratorGitEnv.GIT_CONFIG_KEY_0 or null != "safe.directory"
489 || integratorGitEnv.GIT_CONFIG_VALUE_0 or null != "/srv/git/%i.git"
490 || integratorGitEnv.GIT_CONFIG_COUNT or null
491 != toString (
492 lib.length (lib.filter (lib.hasPrefix "GIT_CONFIG_KEY_") (lib.attrNames integratorGitEnv))
493 );
494
495 integratorService = integratorHost.config.systemd.services."valley-integrator@".serviceConfig;
496
497 # Scratch goes under the state directory, because the sandbox leaves no
498 # writable temporary directory and a verdict needs a checkout on disk. Two
499 # halves, and each was a live failure on its own. TMPDIR naming a path
500 # outside the state directory is the first; the state directory not being
501 # named in ReadWritePaths is the second, which failed even though
502 # ProtectSystem=strict is documented to leave a declared state directory
503 # writable. Everything the unit may write is enumerated, so what a reader
504 # of the unit sees is the whole of it.
505 # The floor is read from the instance repository's integrated tip
506 # (dcr-f41f718, dcr-b87f6e8), so a controller is told which repository
507 # carries it and reads it there. Three things have to be true of that, and
508 # each was a way for it to be silently wrong.
509 #
510 # The controller has to be told at all — the failure this replaced was a
511 # binary looking for a materialized directory nothing populated.
512 #
513 # It has to work when the repository carrying the floor is not the one the
514 # controller serves, which is the ordinary case: on integratorHost every
515 # controller serves a protected project and reads the floor out of
516 # "open", which no controller serves. git refuses a repository the caller
517 # does not own, so that read needs its own safe.directory entry, named and
518 # not wildcarded — the same failure as the served repository's, one
519 # repository over.
520 #
521 # And it has to keep working when the two coincide, which is what an
522 # instance's own host looks like: integratorSelfHost's controller for
523 # "guarded" reads the floor from "guarded".
524 integratorFloor =
525 let
526 command = integratorHost.config.systemd.services."valley-integrator@".serviceConfig.ExecStart;
527 selfCommand = integratorSelfHost.config.systemd.services."valley-integrator@".serviceConfig.ExecStart;
528 env = integratorHost.config.systemd.services."valley-integrator@".environment;
529 in
530 !(lib.hasInfix "--instance-repo /srv/git/sealed.git" command)
531 || !(lib.hasInfix "--instance-repo /srv/git/guarded.git" selfCommand)
532 || env.GIT_CONFIG_COUNT or null != "2"
533 || env.GIT_CONFIG_KEY_1 or null != "safe.directory"
534 || env.GIT_CONFIG_VALUE_1 or null != "/srv/git/sealed.git";
535
536 integratorScratch =
537 integratorGitEnv.TMPDIR or null != "/var/lib/${integratorService.StateDirectory}"
538 || !(builtins.elem "/var/lib/${integratorService.StateDirectory}" integratorService.ReadWritePaths);
539
540 # The controllers' wake directories. Each controller watches its own,
541 # under /run, which the host makes owned by the integrator's user and the
542 # writers' group of the git user and the integrator's user. Its sandbox
543 # may write its own and, for the instance project's controller alone,
544 # each other controller's, which that controller marks after a floor
545 # landing. The drop-in that grants those sets nothing else. The push hook
546 # is wired for every served project and no other repository.
547 integratorWakeMisrendered =
548 let
549 wakeOf = name: "/run/valley-integrator-wake/${name}";
550 dropIn = host: name: host.config.systemd.units."valley-integrator@${name}.service" or null;
551 readers =
552 host: instance: others:
553 let
554 unit = dropIn host instance;
555 in
556 unit == null
557 || unit.overrideStrategy or null != "asDropin"
558 || unit.text != "[Service]\n" + lib.concatMapStrings (o: "ReadWritePaths=-${wakeOf o}\n") others;
559 init = integratorHost.config.systemd.services.valley-init.script;
560 in
561 !(lib.hasInfix "--woken-by /run/valley-integrator-wake/%i" integratorService.ExecStart)
562 || !(lib.hasInfix "$VALLEY_FLOOR_READERS" integratorService.ExecStart)
563 || !(lib.hasPrefix "-/nix/store/" integratorService.EnvironmentFile or "")
564 || !(builtins.elem "-${wakeOf "%i"}" integratorService.ReadWritePaths)
565 || builtins.elem "/run/valley-integrator-wake" integratorService.ReadWritePaths
566 || lib.any (
567 name:
568 !(builtins.elem "d ${wakeOf name} 0770 valley-integrator valley-integrator-wake - -" integratorHost.config.systemd.tmpfiles.rules)
569 || !(lib.hasInfix "${name}.git/hooks/post-receive.d/valley-integrator-wake" init)
570 ) [ "guarded" "released" "sealed" ]
571 || lib.hasInfix "ln -s /nix/store/" (lib.concatStrings (lib.filter (lib.hasInfix "open.git/hooks/post-receive.d/valley-integrator-wake") (lib.splitString "ihook=" init)))
572 || lib.sort lib.lessThan integratorHost.config.users.groups.valley-integrator-wake.members != lib.sort lib.lessThan [
573 integratorHost.config.services.valley.user
574 integratorHost.config.services.valley.integrator.user
575 ]
576 || readers integratorHost "sealed" [ "guarded" "released" ]
577 || readers integratorSelfHost "guarded" [ "released" "sealed" ]
578 || dropIn integratorHost "guarded" != null
579 || dropIn integratorHost "released" != null
580 || protectedHost.config.users.groups ? valley-integrator-wake;
581
582 # The registry compiler. It is off by default and must stay inert: a
583 # consumer that has not asked for it renders the system it always did.
584 # integratorHost is the strongest witness available — the integrator on,
585 # the signers file supplied by hand, and every option of the identity
586 # block left alone.
587 identityRenderedWithoutEnable =
588 integratorHost.config.systemd.services ? valley-identity
589 || integratorHost.config.systemd.timers ? valley-identity
590 || integratorHost.config.systemd.timers ? valley-identity-midnight
591 || integratorHost.config.systemd.paths ? valley-identity
592 || integratorHost.config.services.openssh.settings ? PermitUserEnvironment
593 || lib.any (lib.hasInfix "valley-identity") integratorHost.config.services.openssh.authorizedKeysFiles
594 || lib.hasInfix "valley-identity" integratorHost.config.services.openssh.extraConfig
595 || lib.hasInfix "valley-identity" (
596 integratorHost.config.systemd.services."valley-integrator@".serviceConfig.ExecStart
597 )
598 || lib.hasInfix "--name " (
599 integratorHost.config.systemd.services."valley-integrator@".serviceConfig.ExecStart
600 );
601
602 identityService = identityHost.config.systemd.services.valley-identity.serviceConfig;
603
604 identityStateDir = "/var/lib/${identityService.StateDirectory or ""}";
605
606 # What the compiled artifacts have to be true of, and each was a way for
607 # the machinery to be quietly wrong.
608 #
609 # The compiler writes into its state directory and nowhere else, so that
610 # directory has to be the one path the unit may write.
611 #
612 # sshd walks every directory above an authorized-keys file and refuses a
613 # group- or world-writable one, so the state directory is 0755 rather than
614 # the 0700 a service's state usually takes — and the unit runs as the git
615 # user, because sshd equally refuses a file owned by anyone but root or
616 # the account it authorizes.
617 #
618 # The compiled file is added to what sshd reads for the git user rather
619 # than replacing it, and for the git user alone: the user's Match block
620 # names the declared keys and the compiled ones, and nothing else — no
621 # ~/.ssh/authorized_keys, no AuthorizedKeysCommand — so every key the git
622 # user accepts carries a tag this module or the compiler wrote. The
623 # compiler is handed the declared keys, so it can refuse a registry key
624 # declared under another tag.
625 identityCompiler =
626 identityService.User or null != identityHost.config.services.valley.user
627 || identityService.StateDirectoryMode or null != "0755"
628 || identityService.ReadWritePaths or [ ] != [ identityStateDir ]
629 || !(lib.hasInfix "--repo /srv/git/sealed.git" identityService.ExecStart)
630 || !(lib.hasInfix "--known-signers ${identityStateDir}/known-signers" identityService.ExecStart)
631 || !(lib.hasInfix "--authorized-keys ${identityStateDir}/authorized_keys.git" identityService.ExecStart)
632 || !(lib.hasInfix "--grants ${identityStateDir}/grants" identityService.ExecStart)
633 || !(lib.hasInfix "-valley-declared-keys" identityService.ExecStart)
634 || !(lib.hasInfix "AuthorizedKeysFile /etc/ssh/authorized_keys.d/%u ${identityStateDir}/authorized_keys.git\n" identityHost.config.services.openssh.extraConfig)
635 || !(lib.hasInfix "AuthorizedKeysCommand none" identityHost.config.services.openssh.extraConfig);
636
637 # A unit that must not run unless valley-init's latest start succeeded,
638 # and must not run valley-init either: ordered after it and requisite on
639 # it, which valley-init stays active after success for, never requiring
640 # it, which would start it again; and started by valley-init's success.
641 gatedOnInit =
642 host: name:
643 let
644 unit = host.config.systemd.services.${name};
645 init = host.config.systemd.services.valley-init;
646 in
647 builtins.elem "valley-init.service" unit.after
648 && builtins.elem "valley-init.service" unit.requisite
649 && !(builtins.elem "valley-init.service" unit.requires)
650 && !(unit.serviceConfig ? ExecCondition)
651 && init.serviceConfig.RemainAfterExit or false
652 && builtins.elem "${name}.service" init.wants;
653
654 # What starts the compiler: a move of the registry's ref in the instance
655 # repository, seen at its loose file, the one path the unit watches;
656 # 00:00 UTC, when entries expire, at once and with no catch-up start,
657 # since every boot compiles; and the interval timer, kept as recovery.
658 # None of them reruns valley-init, and no burst of starts can fail the
659 # path unit or the compiler.
660 identityStarts =
661 let
662 timers = identityHost.config.systemd.timers;
663 path = identityHost.config.systemd.paths.valley-identity or { };
664 in
665 !(gatedOnInit identityHost "valley-identity")
666 # A successful valley-init starts the controllers too, which require
667 # it, so its repair restores them.
668 || identityHost.config.systemd.targets.valley-integrators.wants == [ ]
669 || !(lib.all (
670 controller: builtins.elem controller identityHost.config.systemd.services.valley-init.wants
671 ) identityHost.config.systemd.targets.valley-integrators.wants)
672 || !(builtins.elem "valley-init.service" identityHost.config.systemd.services."valley-integrator@".requires)
673 || path.pathConfig or null != {
674 PathChanged = [ "/srv/git/sealed.git/refs/heads/main" ];
675 TriggerLimitIntervalSec = 0;
676 }
677 || identityHost.config.systemd.services.valley-identity.startLimitIntervalSec or null != 0
678 || !(builtins.elem "multi-user.target" path.wantedBy or [ ])
679 || timers.valley-identity-midnight.timerConfig or null != {
680 Unit = "valley-identity.service";
681 OnCalendar = "*-*-* 00:00:00 UTC";
682 AccuracySec = "1s";
683 RandomizedDelaySec = "0";
684 Persistent = false;
685 }
686 || !(builtins.elem "timers.target" timers.valley-identity-midnight.wantedBy or [ ])
687 || timers.valley-identity.timerConfig or null != {
688 OnBootSec = "1m";
689 OnUnitActiveSec = "5m";
690 };
691
692 # A controller under a compiled registry reads the compiled signers file
693 # and signs under the name the registry publishes its key under. The key
694 # hash binds name to key, so a controller signing under the host's default
695 # name while the registry publishes it as "integrator" would produce notes
696 # no verifier can find a key for.
697 identityIntegrator =
698 let
699 command = identityHost.config.systemd.services."valley-integrator@".serviceConfig.ExecStart;
700 in
701 !(lib.hasInfix "--known-signers ${identityStateDir}/known-signers" command)
702 || !(lib.hasInfix "--name integrator" command)
703 || !(builtins.elem "valley-identity.service"
704 identityHost.config.systemd.services."valley-integrator@".after
705 );
706
707 # The signers publication. A host whose integrator runs and which serves
708 # the instance repository publishes there what a client verifies its
709 # transfer statements with. What it publishes has to be what the
710 # controllers use: the same signers file and the same --name, or none on
711 # either, in which case both take the binary's default. The publisher
712 # writes as the git user, which owns the instance repository, may write
713 # that repository and nothing else, runs after the compilation when there
714 # is one, and runs again whenever a file it publishes from changes: the
715 # signers file, the approval signers files, and the instance repository's
716 # main, loose or packed. The signer projects file is the controllers'
717 # too, or neither has one. The approval signers files are the ones the
718 # compiler writes, or none on a host that compiles no registry.
719 flagValue =
720 flag: command:
721 let
722 m = builtins.match ".*--${flag} ([^ ]+).*" command;
723 in
724 if m == null then null else lib.head m;
725
726 signersPublisher =
727 host: repo:
728 let
729 unit = host.config.systemd.services.valley-signers;
730 publish = unit.serviceConfig.ExecStart;
731 controller = host.config.systemd.services."valley-integrator@".serviceConfig.ExecStart;
732 compile = host.config.systemd.services.valley-identity.serviceConfig.ExecStart or "";
733 approvalFlags = [
734 "approval-signers"
735 "approval-signers-hardware"
736 ];
737 approvalFiles = map (flag: flagValue flag publish) approvalFlags;
738 compiled = map (flag: flagValue flag compile) approvalFlags;
739 inputs = [
740 (flagValue "known-signers" controller)
741 ]
742 ++ lib.remove null approvalFiles
743 ++ [
744 "${repo}/refs/heads/main"
745 "${repo}/packed-refs"
746 ];
747 in
748 !(lib.hasInfix "/bin/integrator publish-signers " publish)
749 || flagValue "instance-repo" publish != repo
750 || flagValue "known-signers" publish != flagValue "known-signers" controller
751 || flagValue "name" publish != flagValue "name" controller
752 || flagValue "signer-projects" publish != flagValue "signer-projects" controller
753 || unit.serviceConfig.User or null != "git"
754 || unit.serviceConfig.ReadWritePaths or [ ] != [ repo ]
755 || !(gatedOnInit host "valley-signers")
756 || !(builtins.elem "multi-user.target" unit.wantedBy)
757 || approvalFiles != compiled
758 || (compile != "" && lib.elem null approvalFiles)
759 || host.config.systemd.paths.valley-signers.pathConfig.PathChanged or null != inputs
760 || !(builtins.elem "multi-user.target" host.config.systemd.paths.valley-signers.wantedBy);
761
762 # Each controller takes the approval inputs as paths: the approval
763 # signers files the compiler writes, or none on a host that compiles no
764 # registry, and its project's push policy, which its environment file
765 # names. module-eval.sh follows that file to the one the hook reads.
766 controllerApprovalInputsMisrendered = lib.any (
767 host:
768 let
769 controller = host.config.systemd.services."valley-integrator@".serviceConfig.ExecStart;
770 compile = host.config.systemd.services.valley-identity.serviceConfig.ExecStart or "";
771 flags = [
772 "approval-signers"
773 "approval-signers-hardware"
774 ];
775 in
776 map (f: flagValue f controller) flags != map (f: flagValue f compile) flags
777 || !(lib.hasInfix "--push-policy=\${VALLEY_PUSH_POLICY}" controller)
778 ) [
779 integratorHost
780 identityHost
781 ];
782
783 # A project that retains its change records hands the hook that setting,
784 # and one that does not leaves it out, which the hook reads as false.
785 retentionMisrendered =
786 protectedHost.config.services.valley.pushPolicies.sealed.retainChangeRecords or null != true
787 || protectedHost.config.services.valley.pushPolicies.open ? retainChangeRecords;
788
789 signersRenderedWithoutIntegrator =
790 protectedHost.config.systemd.services ? valley-signers
791 || protectedHost.config.systemd.paths ? valley-signers;
792
793 signersUnpublished =
794 signersPublisher integratorHost "/srv/git/sealed.git"
795 || signersPublisher restrictedHost "/srv/git/sealed.git"
796 || signersPublisher integratorSelfHost "/srv/git/guarded.git"
797 || signersPublisher identityHost "/srv/git/sealed.git"
798 || flagValue "name" identityHost.config.systemd.services.valley-signers.serviceConfig.ExecStart
799 != "integrator"
800 || !(builtins.elem "valley-identity.service" identityHost.config.systemd.services.valley-signers.after);
801
802 # A host that restricts no signer gives its controllers no signer
803 # projects file, and one that restricts some gives them one.
804 signerProjectsMisrendered =
805 flagValue "signer-projects" integratorHost.config.systemd.services."valley-integrator@".serviceConfig.ExecStart
806 != null
807 || flagValue "signer-projects" restrictedHost.config.systemd.services."valley-integrator@".serviceConfig.ExecStart
808 == null;
809
810 # The declared keys stay authorized beside the compiled ones. A compiled
811 # file that replaced them would make a bad compilation — or a first boot
812 # before the first one — a locked-out git user, which is the one failure
813 # this machinery must never have.
814 identityKeepsDeclaredKeys =
815 identityHost.config.users.users.git.openssh.authorizedKeys.keys == [ ];
816
817 # The check worker and the build slice. Both are off by default, and a
818 # host that never asked for them renders none of either: no unit, no
819 # account, no slice, and a nix daemon where NixOS puts it. integratorHost
820 # is the strongest witness, with the integrator the worker would need
821 # already on.
822 workerRenderedWithoutEnable =
823 integratorHost.config.systemd.services ? valley-worker
824 || integratorHost.config.systemd.timers ? valley-worker
825 || integratorHost.config.systemd.paths ? valley-worker
826 || integratorHost.config.users.groups ? valley-worker-wake
827 || lib.hasInfix "--wake" integratorHost.config.systemd.services."valley-integrator@".serviceConfig.ExecStart
828 || integratorHost.config.systemd.slices ? valley-builds
829 || integratorHost.config.users.users ? valley-worker
830 || integratorHost.config.systemd.services.nix-daemon.serviceConfig ? Slice;
831
832 # The build slice is a host decision of its own. On, it puts the daemon
833 # in the slice at the caps the host names, with no swap, and nothing of
834 # the worker.
835 buildSliceMisrendered =
836 let
837 slice = buildSliceHost.config.systemd.slices.valley-builds.sliceConfig or { };
838 in
839 buildSliceHost.config.systemd.services.nix-daemon.serviceConfig.Slice or null
840 != "valley-builds.slice"
841 || slice.CPUQuota or null != "200%"
842 || slice.MemoryMax or null != "4G"
843 || slice.MemorySwapMax or null != "0"
844 || buildSliceHost.config.systemd.services ? valley-worker
845 || buildSliceHost.config.users.users ? valley-worker;
846
847 # What the VM check runs, held at the operator's values. worker-e2e
848 # boots the worker and lowers the memory cap at runtime to make a build
849 # run past it, so the values themselves are held here. The caps are on
850 # a slice that holds the worker and the nix daemon both, since a build
851 # runs in the daemon's cgroup and never in the worker's; the slice and
852 # the daemon set no device policy, so a NixOS test still gets /dev/kvm.
853 # The worker may run on any CPU. A host that sets no build capacity has
854 # the worker run two batches at once and build one check at a time in
855 # each, each nix build building one derivation at a time with 4 cores,
856 # and a pass whose batches run reads again every minute. Its
857 # evaluations share 0.6 of its memory limit (--eval-share 0.6).
858 # capacityWorkerHost's values reach the worker's --batches, --slots,
859 # --interval, --eval-budget and its NIX_CONFIG. The worker keeps check
860 # outputs for 7 days unless a host sets keepOutputs to null, as
861 # capacityWorkerHost does. The account is not in the git
862 # group, so the repositories on disk are not the worker's to read or
863 # write, and it reaches them only through this host's sshd, checking the
864 # host's key. Its timer starts the first pass a second after the timer
865 # starts, not after boot, and each later pass one minute after the last
866 # one ended. Its path unit starts a pass while the wake directory holds
867 # due; the directory is the worker's, in a group of the git user and the
868 # integrator's user, and every writer's sandbox may write it. Nothing
869 # waits for the service at boot, a burst never start-limits it, and a
870 # pass that could not claim due is started again one interval later.
871 workerMisrendered =
872 let
873 unit = workerHost.config.systemd.services.valley-worker;
874 capacity = capacityWorkerHost.config.systemd.services.valley-worker;
875 service = unit.serviceConfig;
876 daemon = workerHost.config.systemd.services.nix-daemon.serviceConfig;
877 slice = workerHost.config.systemd.slices.valley-builds.sliceConfig;
878 account = workerHost.config.users.users.valley-worker;
879 timer = workerHost.config.systemd.timers.valley-worker;
880 wakePath = workerHost.config.systemd.paths.valley-worker;
881 integrator = workerHost.config.systemd.services."valley-integrator@".serviceConfig;
882 signers = workerHost.config.systemd.services.valley-signers.serviceConfig;
883 devicePolicy = c: c ? DevicePolicy || c ? DeviceAllow || c ? PrivateDevices;
884 in
885 service.User or null != "valley-worker"
886 || account.group != "valley-worker"
887 || account.extraGroups != [ ]
888 || service.Type or null != "oneshot"
889 # A switch must not wait on a running pass: the unit is neither
890 # restarted nor stopped when it changes, and no target starts it.
891 || unit.restartIfChanged != false
892 || unit.stopIfChanged != false
893 || unit.wantedBy != [ ]
894 || unit.requiredBy != [ ]
895 || service.Slice or null != "valley-builds.slice"
896 || daemon.Slice or null != "valley-builds.slice"
897 || slice.CPUQuota or null != "400%"
898 || slice.MemoryMax or null != "8G"
899 || slice.MemorySwapMax or null != "0"
900 # The daemon's unit delegates its cgroup, so systemd's OOM policy for
901 # it is continue: a build the kernel's OOM killer kills leaves the
902 # daemon running. Nothing here may set another.
903 || daemon.OOMPolicy or "continue" != "continue"
904 || devicePolicy slice
905 || devicePolicy daemon
906 || service ? CPUAffinity
907 || !(lib.hasInfix "max-jobs = 1\n" unit.environment.NIX_CONFIG)
908 || !(lib.hasInfix "cores = 4\n" unit.environment.NIX_CONFIG)
909 || !(lib.hasInfix "max-jobs = 2\n" capacity.environment.NIX_CONFIG)
910 || !(lib.hasInfix "cores = 2\n" capacity.environment.NIX_CONFIG)
911 || capacity.serviceConfig ? CPUAffinity
912 || !(lib.hasInfix "builders =\n" unit.environment.NIX_CONFIG)
913 || !(lib.hasInfix "-o StrictHostKeyChecking=yes -o HostKeyAlias=localhost" unit.environment.GIT_SSH_COMMAND)
914 || service.ReadWritePaths or [ ] != [
915 "/var/lib/valley-worker"
916 "/var/lib/valley-worker-wake"
917 "/nix/var/nix/daemon-socket"
918 ]
919 || !(lib.hasInfix "exec valley-worker --repo guarded --repo sealed --key \"$key\" --name worker.valley.invalid/attestations --state \"$state\" --wake /var/lib/valley-worker-wake --slots 1 --batches 2 --interval 1m --eval-share 0.6 --keep-outputs 168h\n" unit.script)
920 || !(lib.hasInfix "exec valley-worker --repo guarded --repo sealed --key \"$key\" --name worker.valley.invalid/attestations --state \"$state\" --wake /var/lib/valley-worker-wake --slots 3 --batches 3 --interval 5min --eval-budget 12G\n" capacity.script)
921 || unit.wantedBy != [ ]
922 || unit.unitConfig.StartLimitIntervalSec or null != 0
923 || service.RestartForceExitStatus or null != "75"
924 || service.RestartSec or null != "1m"
925 || service ? Restart
926 || wakePath.pathConfig.PathExists or null != "/var/lib/valley-worker-wake/due"
927 || !(builtins.elem "multi-user.target" wakePath.wantedBy)
928 || !(builtins.elem "d /var/lib/valley-worker-wake 0770 valley-worker valley-worker-wake - -" workerHost.config.systemd.tmpfiles.rules)
929 || lib.sort lib.lessThan workerHost.config.users.groups.valley-worker-wake.members != lib.sort lib.lessThan [
930 workerHost.config.services.valley.user
931 workerHost.config.services.valley.integrator.user
932 ]
933 || !(builtins.elem "/var/lib/valley-worker-wake" integrator.ReadWritePaths)
934 || !(lib.hasInfix "--wake=\${VALLEY_WAKE}" integrator.ExecStart)
935 || !(lib.hasPrefix "-/nix/store/" integrator.EnvironmentFile or "")
936 || !(lib.hasInfix "--wake /var/lib/valley-worker-wake" signers.ExecStart)
937 || !(builtins.elem "/var/lib/valley-worker-wake" signers.ReadWritePaths)
938 || !(lib.hasInfix "git -C \"$origin\" remote add origin git@localhost:sealed.git\n" unit.script)
939 || timer.timerConfig.OnActiveSec or null != "1s"
940 || timer.timerConfig ? OnBootSec
941 || timer.timerConfig.OnUnitInactiveSec or null != "1m"
942 || !(builtins.elem "timers.target" timer.wantedBy);
943
944 # The worker's projects when a host leaves them unwritten. A worker host
945 # that writes neither list builds for every project its controllers
946 # serve, one that narrows the worker's projects builds for those alone,
947 # and the signers publication carries the controllers' signer projects
948 # file. That file's lines are pinned by module-eval.sh.
949 workerDefaultsMisrendered =
950 let
951 unpublished =
952 host:
953 flagValue "signer-projects" host.config.systemd.services.valley-signers.serviceConfig.ExecStart
954 != flagValue "signer-projects"
955 host.config.systemd.services."valley-integrator@".serviceConfig.ExecStart;
956 in
957 defaultWorkerHost.config.services.valley.worker.projects != [
958 "guarded"
959 "released"
960 "sealed"
961 ]
962 || !(lib.hasInfix "exec valley-worker --repo guarded --repo released --repo sealed --key "
963 defaultWorkerHost.config.systemd.services.valley-worker.script
964 )
965 || !(lib.hasInfix "exec valley-worker --repo guarded --key "
966 narrowedWorkerHost.config.systemd.services.valley-worker.script
967 )
968 || unpublished defaultWorkerHost
969 || unpublished narrowedWorkerHost;
970
971 # The restacker. When disabled, it renders no units or user account on
972 # integratorHost. When enabled, each configured project gets a
973 # valley-restacker@<project>.service running valley-restacker run as the
974 # valley-restacker user in its own group, with no access to the bare
975 # repositories on disk. It connects through localhost sshd as its
976 # principal using the key passed via LoadCredential, verifies the host's
977 # own SSH key, has its 0700 state directory as its only persistent
978 # writable path (its private temporary directories are writable too),
979 # and reads the floor from the instance repository over the same SSH
980 # connection. A host that lists one project gets only that one; a host
981 # that lists none gets one for each project it integrates.
982 restackerRenderedWithoutEnable =
983 integratorHost.config.systemd.services ? "valley-restacker@"
984 || integratorHost.config.systemd.targets ? valley-restackers
985 || integratorHost.config.users.users ? valley-restacker;
986
987 # The host's own unit is one more local source, enabled, with the units
988 # it lists, and the module's own sources stay beside it.
989 telemetrySourceMisrendered =
990 let
991 sources = telemetryHost.config.services.valley.telemetry.catalog.sources;
992 named = builtins.filter (s: s.name == "converge") sources;
993 in
994 lib.length named != 1
995 || (lib.head named) != {
996 name = "converge";
997 description = "the service that converges this host";
998 enabled = true;
999 units = [ "converge.service" ];
1000 location = "local";
1001 }
1002 || !(lib.any (s: s.name == "worker") sources);
1003
1004 restackerMisrendered =
1005 let
1006 unit = restackerHost.config.systemd.services."valley-restacker@";
1007 service = unit.serviceConfig;
1008 account = restackerHost.config.users.users.valley-restacker;
1009 target = restackerHost.config.systemd.targets.valley-restackers;
1010 command = service.ExecStart;
1011 in
1012 service.User or null != "valley-restacker"
1013 || service.Group or null != "valley-restacker"
1014 || account.group != "valley-restacker"
1015 || account.extraGroups != [ ]
1016 || service.LoadCredential or [ ] != [ "key:/run/agenix/valley-restacker-key" ]
1017 || service.StateDirectory or null != "valley-restacker/%i"
1018 || service.StateDirectoryMode or null != "0700"
1019 || service.ProtectSystem or null != "strict"
1020 || service ? ReadWritePaths
1021 || !(lib.hasInfix " -i %d/key " unit.environment.GIT_SSH_COMMAND)
1022 || !(lib.hasInfix "-o StrictHostKeyChecking=yes -o HostKeyAlias=localhost" unit.environment.GIT_SSH_COMMAND)
1023 || !(lib.hasInfix "-o UserKnownHostsFile=%S/valley-restacker/%i/known_hosts -o GlobalKnownHostsFile=/dev/null" unit.environment.GIT_SSH_COMMAND)
1024 || !(lib.hasInfix "/bin/valley-restacker run --repo git@localhost:%i.git --state %S/valley-restacker/%i --principal valley-restacker --interval 15s " command)
1025 || !(lib.hasInfix " --instance-repo git@localhost:sealed.git" command)
1026 || target.wants != [ "valley-restacker@guarded.service" ]
1027 || !(builtins.elem "multi-user.target" target.wantedBy)
1028 # A host that lists no projects serves every project it integrates.
1029 || defaultRestackerHost.config.systemd.targets.valley-restackers.wants != [
1030 "valley-restacker@guarded.service"
1031 "valley-restacker@released.service"
1032 "valley-restacker@sealed.service"
1033 ];
1034
1035 # The web publisher (nix/web-publisher.nix). Off, it renders nothing.
1036 # On, one pass is a oneshot on a five-minute timer whose first pass waits
1037 # five minutes after the timer starts, and which no switch starts or
1038 # restarts. It runs as the dynamic user valley-web-publish, which the
1039 # policy path's unit shares, in the git group, with an empty
1040 # safe.directory entry that resets the system's and the user's, then an
1041 # exact entry for each repository the host serves and no wildcard, the
1042 # repositories read-only, nothing writable but its state and cache, and
1043 # the mirror, backup and signing keys out of reach. It may connect to the
1044 # addresses it is allowed and to no other, and checks before each pass that
1045 # this filter is in force. Its Go lookups use the C library. Its memory is
1046 # capped with no swap. It reads the instance repository the controllers
1047 # read, names the host as the instance, and is given the receiver, the
1048 # destination, the display mapping and the bounds on its bundles and its
1049 # storage.
1050 webPublisherRenderedWithoutEnable =
1051 webPublisherOffHost.config.systemd.services ? valley-web-publish
1052 || webPublisherOffHost.config.systemd.services ? valley-web-publish-policy
1053 || webPublisherOffHost.config.systemd.timers ? valley-web-publish
1054 || lib.any (p: (p.name or "") == "valley-web-link") webPublisherOffHost.config.environment.systemPackages;
1055
1056 # The read links: the policy path's own unit, the same pass with
1057 # --policy-only in the same sandbox, as the same dynamic user, so the two
1058 # share their state and cache directories, and with the same
1059 # credentials; the
1060 # credential file read live by both through a static group, root's to
1061 # write, under the links lock tmpfiles makes beside it, which only root
1062 # can make or replace; the operator's wrapper, with the unit's
1063 # safe.directory entries, passing issue alone the flags for reading the
1064 # registry, and starting the policy pass after every issue or revoke,
1065 # and once more while a link is pending; and the backup holding the
1066 # file's directory and the publisher's durable state beside the data
1067 # directory.
1068 webPublisherLinksMisrendered =
1069 let
1070 units = webPublisherHost.config.systemd.services;
1071 pass = units.valley-web-publish.serviceConfig;
1072 policy = units.valley-web-publish-policy.serviceConfig or { };
1073 wrapper = lib.findFirst (
1074 p: (p.name or "") == "valley-web-link"
1075 ) null webPublisherHost.config.environment.systemPackages;
1076 in
1077 lib.filter (x: x != null) (lib.imap0 (i: c: if c then i else null) [
1078 (!(units ? valley-web-publish-policy))
1079 (lib.any (u: u.DynamicUser or null != true || u.User or null != "valley-web-publish" || u.Group or null != "valley-web-publish") [
1080 pass
1081 policy
1082 ])
1083 (policy.ExecStart or null != "${pass.ExecStart} --policy-only")
1084 (removeAttrs policy [ "ExecStart" ] != removeAttrs pass [ "ExecStart" ])
1085 (units.valley-web-publish-policy.environment != units.valley-web-publish.environment)
1086 (!(lib.hasSuffix " --links /var/lib/valley-web-links/links" pass.ExecStart))
1087 (!(lib.all (r: builtins.elem r webPublisherHost.config.systemd.tmpfiles.rules) [
1088 "d /var/lib/valley-web-links 0750 root valley-web-links -"
1089 "f /var/lib/valley-web-links/links 0640 root valley-web-links -"
1090 "f /var/lib/valley-web-links/lock 0640 root valley-web-links -"
1091 ]))
1092 (!(webPublisherHost.config.users.groups ? valley-web-links))
1093 (wrapper == null)
1094 (!(lib.hasInfix "valley-web-publish link \"$@\" --links /var/lib/valley-web-links/links \\\n --state /var/lib/valley-web-publish\n}" wrapper.text or ""))
1095 (!(lib.hasInfix "issue)\n link \"$@\" --instance-repo /srv/git/sealed.git" wrapper.text or ""))
1096 (!(lib.hasInfix "revoke) link \"$@\" ;;" wrapper.text or ""))
1097 (!(lib.all (e: lib.hasInfix e wrapper.text or "") [
1098 "ulimit -c 0\n"
1099 "export GIT_CONFIG_COUNT=5\n"
1100 "export GIT_CONFIG_VALUE_0=''\n"
1101 "export GIT_CONFIG_VALUE_4=/srv/git/sealed.git\n"
1102 "systemctl start valley-web-publish-policy.service"
1103 "deliver\nif ! link list --check > /dev/null 2>&1; then\n deliver\nfi\nif link list --check > /dev/null; then"
1104 ]))
1105 (backupWebPublisherHost.config.services.restic.backups.valley.paths or [ ] != [
1106 "/srv/git"
1107 "/var/lib/valley-web-links"
1108 "/var/lib/private/valley-web-publish"
1109 ])
1110 ]);
1111
1112 webPublisherMisrendered =
1113 let
1114 unit = webPublisherHost.config.systemd.services.valley-web-publish;
1115 service = unit.serviceConfig;
1116 env = unit.environment;
1117 timer = webPublisherHost.config.systemd.timers.valley-web-publish;
1118 repos = [
1119 "/srv/git/guarded.git"
1120 "/srv/git/open.git"
1121 "/srv/git/released.git"
1122 "/srv/git/sealed.git"
1123 ];
1124 entries = lib.genList (i: {
1125 key = env."GIT_CONFIG_KEY_${toString i}" or null;
1126 value = env."GIT_CONFIG_VALUE_${toString i}" or null;
1127 }) (lib.length (lib.filter (lib.hasPrefix "GIT_CONFIG_KEY_") (lib.attrNames env)));
1128 command = service.ExecStart;
1129 in
1130 service.Type or null != "oneshot"
1131 || service.DynamicUser or null != true
1132 || service.User or null != "valley-web-publish"
1133 || service.Group or null != "valley-web-publish"
1134 || service.SupplementaryGroups or [ ] != [
1135 "git"
1136 "valley-web-links"
1137 ]
1138 || env.GIT_CONFIG_COUNT or null != toString (lib.length repos + 1)
1139 || entries != map (r: {
1140 key = "safe.directory";
1141 value = r;
1142 }) ([ "" ] ++ repos)
1143 || lib.any (e: lib.hasInfix "*" e.value) entries
1144 || service.ProtectSystem or null != "strict"
1145 || service ? ReadWritePaths
1146 || service.ReadOnlyPaths or [ ] != map (r: "-${r}") repos
1147 || service.StateDirectory or null != "valley-web-publish"
1148 || service.CacheDirectory or null != "valley-web-publish"
1149 || env.XDG_CACHE_HOME or null != "/var/cache/valley-web-publish"
1150 || !(lib.all (p: builtins.elem p service.InaccessiblePaths) [
1151 "-/srv/git/.ssh"
1152 "-/run/agenix/valley-integrator-key"
1153 "-/run/agenix/valley-git-ssh-key"
1154 "-/var/lib/valley-integrator"
1155 ])
1156 || !(lib.hasInfix "/bin/valley-web-publish --instance-repo /srv/git/sealed.git --instance valley-host --destination example.org --host /nix/store/" command)
1157 || !(lib.hasInfix "-valley-config.json --receiver https://example.org --receiver-token %d/receiver-token --principals /nix/store/" command)
1158 || service.LoadCredential or [ ] != [ "receiver-token:/run/keys/valley-web-receiver-token" ]
1159 || !(lib.hasInfix "-valley-web-principals.json --state /var/lib/valley-web-publish --max-bundles 1G --max-storage 16G --registry-ref refs/heads/main --registry-dir identity" command)
1160 || !(lib.hasSuffix "/bin/valley-web-publish-egress-check 198.51.100.1 9" (service.ExecStartPre or ""))
1161 || env.GODEBUG or null != "netdns=cgo"
1162 || service.IPAddressDeny or null != "any"
1163 || service.IPAddressAllow or null != [
1164 "192.0.2.10"
1165 "2001:db8::10"
1166 ]
1167 || service.RestrictAddressFamilies or null != [
1168 "AF_INET"
1169 "AF_INET6"
1170 "AF_UNIX"
1171 ]
1172 || service.MemoryMax or null != "1G"
1173 || service.MemorySwapMax or null != "0"
1174 || unit.restartIfChanged != false
1175 || unit.wantedBy != [ ]
1176 || timer.timerConfig.OnActiveSec or null != "5min"
1177 || timer.timerConfig.OnUnitInactiveSec or null != "5min"
1178 || !(builtins.elem "timers.target" timer.wantedBy);
1179
1180 # The web receiver module (nix/web-receiver.nix). When disabled, it
1181 # renders no units or users. When enabled, it renders separate systemd
1182 # units for valley-web-receive and valley-web; both start at boot, restart
1183 # on failure, and run independently. The receiver runs as
1184 # valley-web-receive in group valley-web, owns the mode-0750 state
1185 # directory, and takes the instance, the destination, the pinned verifiers
1186 # from the Nix store, the bearer token as a systemd credential from outside
1187 # the store, and the body and storage caps. valley-web runs as valley-web
1188 # in the same group, orders after the receiver, mounts the state directory
1189 # read-only with no persistent writable paths, and takes the state
1190 # directory and its listener address. Each unit has its own memory cap and
1191 # disables swap.
1192 webReceiverRenderedWithoutEnable =
1193 webReceiverOffHost.config.systemd.services ? valley-web-receive
1194 || webReceiverOffHost.config.systemd.services ? valley-web
1195 || webReceiverOffHost.config.users.users ? valley-web-receive;
1196
1197 webReceiverMisrendered =
1198 let
1199 cfg = webReceiverHost.config;
1200 receive = cfg.systemd.services.valley-web-receive;
1201 web = cfg.systemd.services.valley-web;
1202 confined =
1203 unit:
1204 unit.serviceConfig.ProtectSystem or null == "strict"
1205 && unit.serviceConfig.NoNewPrivileges or null == true
1206 && unit.serviceConfig.CapabilityBoundingSet or null == ""
1207 && unit.serviceConfig.MemorySwapMax or null == "0"
1208 && unit.serviceConfig.Restart or null == "on-failure"
1209 && builtins.elem "multi-user.target" unit.wantedBy
1210 && unit.requires == [ ]
1211 && unit.bindsTo == [ ];
1212 in
1213 !(confined receive && confined web)
1214 || cfg.users.users.valley-web-receive.group != "valley-web"
1215 || cfg.users.users.valley-web.group != "valley-web"
1216 || receive.serviceConfig.User or null != "valley-web-receive"
1217 || receive.serviceConfig.Group or null != "valley-web"
1218 || receive.serviceConfig.StateDirectory or null != "valley-web"
1219 || receive.serviceConfig.StateDirectoryMode or null != "0750"
1220 || receive.serviceConfig.LoadCredential or [ ] != [ "token:/run/keys/valley-web-receiver-token" ]
1221 || receive.serviceConfig.MemoryMax or null != "2G"
1222 || !(lib.hasInfix "/bin/valley-web-receive --state /var/lib/valley-web/store --listen 192.0.2.10:8081 --instance valley-host --destination example.org --verifiers /nix/store/" receive.serviceConfig.ExecStart)
1223 || !(lib.hasSuffix "-valley-web-verifiers --token-file %d/token --max-body 1G --max-upload 2G --max-storage 8G" receive.serviceConfig.ExecStart)
1224 || web.serviceConfig.User or null != "valley-web"
1225 || web.serviceConfig.Group or null != "valley-web"
1226 || web.serviceConfig ? StateDirectory
1227 || web.serviceConfig ? ReadWritePaths
1228 || web.serviceConfig ? LoadCredential
1229 || web.serviceConfig.ReadOnlyPaths or [ ] != [ "-/var/lib/valley-web" ]
1230 || web.serviceConfig.MemoryMax or null != "1G"
1231 || !(builtins.elem "valley-web-receive.service" web.after)
1232 || !(lib.hasSuffix "/bin/valley-web --state /var/lib/valley-web/store --listen 127.0.0.1:8080" web.serviceConfig.ExecStart)
1233 || receive.serviceConfig ? InaccessiblePaths
1234 || lib.any (lib.hasInfix "/var/lib/valley-web") cfg.systemd.tmpfiles.rules;
1235
1236 # With an origin, valley-web signs readers in: it takes --origin, and may
1237 # write browser/ in the state directory alone, which tmpfiles makes as
1238 # its own, mode 0700, under the state directory made as the receiver's.
1239 # Its unit takes no core dump. The receiver's unit cannot reach browser/.
1240 webReaderMisrendered =
1241 let
1242 cfg = webReaderHost.config;
1243 receive = cfg.systemd.services.valley-web-receive.serviceConfig;
1244 web = cfg.systemd.services.valley-web.serviceConfig;
1245 in
1246 !(lib.hasSuffix "/bin/valley-web --state /var/lib/valley-web/store --listen 127.0.0.1:8080 --origin https://example.org" web.ExecStart)
1247 || web.ReadOnlyPaths or [ ] != [ "-/var/lib/valley-web" ]
1248 || web.ReadWritePaths or [ ] != [ "/var/lib/valley-web/browser" ]
1249 || web.LimitCORE or null != 0
1250 || receive.InaccessiblePaths or [ ] != [ "-/var/lib/valley-web/browser" ]
1251 || receive.StateDirectory or null != "valley-web"
1252 || !(lib.all (r: builtins.elem r cfg.systemd.tmpfiles.rules) [
1253 "d /var/lib/valley-web 0750 valley-web-receive valley-web -"
1254 "d /var/lib/valley-web/browser 0700 valley-web valley-web -"
1255 ]);
1256in
1257{
1258 module-eval =
1259 if failedAssertions != [ ] then
1260 throw "valley module-eval: failed assertions: ${
1261 lib.concatMapStringsSep "; " (a: a.message) failedAssertions
1262 }"
1263 else if resticRenderedWithoutDeclaration then
1264 throw "valley module-eval: restic machinery rendered for a declaration without a backup block"
1265 else if busRenderedWithoutEnable then
1266 throw "valley module-eval: bus machinery rendered without services.valley.bus.enable"
1267 else if
1268 !(lib.any (a: lib.hasInfix "services.valley.backup." a.message) missingSecretAssertions)
1269 then
1270 throw "valley module-eval: enabling backup without the secret-path options must fail an assertion naming them"
1271 else if unrefusedHosts != [ ] then
1272 throw "valley module-eval: ${lib.concatMapStringsSep "; " (r: "a host was not refused although ${r.why}") unrefusedHosts}"
1273 else if protectionRenderedWithoutDeclaration then
1274 throw "valley module-eval: principal machinery rendered for a declaration with no protection block and no tagged key"
1275 else if policyMissingWithoutDeclaration then
1276 throw "valley module-eval: a project with no protection block got no pre-receive hook — the push policy is installed on every project a host serves"
1277 else if protectedHost.config.services.openssh.settings ? PermitUserEnvironment then
1278 throw "valley module-eval: sshd must pass no key's environment on: the git user's shell derives the principal from the authenticated key"
1279 else if
1280 !(lib.hasInfix "valley-git-shell" protectedHost.config.users.users.git.shell)
1281 then
1282 throw "valley module-eval: the git user's login shell must be the valley's, which derives the principal and pauses pushes until init converges"
1283 else if integratorRenderedWithoutEnable then
1284 throw "valley module-eval: integrator machinery rendered for a protected declaration that never enabled the service"
1285 else if !(integratorHost.config.systemd.services ? "valley-integrator@") then
1286 throw "valley module-eval: the integrator is enabled and no controller unit was rendered"
1287 else if
1288 controllers != [
1289 "valley-integrator@guarded.service"
1290 "valley-integrator@released.service"
1291 "valley-integrator@sealed.service"
1292 ]
1293 then
1294 throw "valley module-eval: a controller runs for each protected project and no other, not ${lib.concatStringsSep ", " controllers}"
1295 else if
1296 publishers != [
1297 "valley-publish@guarded.path"
1298 "valley-publish@released.path"
1299 "valley-publish@sealed.path"
1300 ]
1301 then
1302 throw "valley module-eval: each controller's landings are published by a path unit of its own, not ${lib.concatStringsSep ", " publishers}"
1303 else if integratorHost.config.systemd.services."valley-publish@".serviceConfig.User != "git" then
1304 throw "valley module-eval: a landing is published as the git user, which holds the mirror credentials"
1305 else if
1306 let
1307 drain = integratorHost.config.systemd.services."valley-publish@".serviceConfig;
1308 in
1309 drain.Restart or null != "on-failure"
1310 || drain.RestartSec or null != "30s"
1311 || drain.RestartSteps or null != 5
1312 || drain.RestartMaxDelaySec or null != "15min"
1313 then
1314 throw "valley module-eval: a failed drain must be run again 30 seconds later, each later retry waiting longer, up to 15 minutes from the fifth, so a queued move reaches its mirror once the mirror is back"
1315 else if integratorUser == integratorHost.config.services.valley.user then
1316 throw "valley module-eval: the integrator must not run as the git user — it has its own (bd-500adf7)"
1317 else if !(integratorHost.config.users.users ? ${integratorUser}) then
1318 throw "valley module-eval: the integrator runs as ${integratorUser}, which the module never declares"
1319 else if integratorHost.config.users.users.${integratorUser}.group != "git" then
1320 throw "valley module-eval: the integrator reaches the repositories through the git group, and holds no other grant"
1321 else if integratorSafeDirectory then
1322 throw "valley module-eval: a controller must carry safe.directory for the one repository it serves in its own environment — it does not own the repositories, and git refuses what it does not own"
1323 else if integratorFloor then
1324 throw "valley module-eval: a controller must be told which repository carries the floor, and must carry a safe.directory exception for it — the floor is read from that repository's integrated tip, and git refuses a repository its caller does not own"
1325 else if integratorScratch then
1326 throw "valley module-eval: a controller's TMPDIR must be its state directory and that directory must be named in ReadWritePaths — under ProtectSystem=strict a path the unit does not enumerate is one it cannot write, and a verdict needs a worktree on disk"
1327 else if integratorWakeMisrendered then
1328 throw "valley module-eval: each controller watches its own wake directory under /run/valley-integrator-wake, owned by the integrator and the group of the git user and the integrator; its sandbox writes that one, the instance project's controller alone writes the floor readers' too, and every served project carries the push hook that marks it"
1329 else if identityRenderedWithoutEnable then
1330 throw "valley module-eval: registry-compilation machinery rendered for a host that never enabled it — nothing may change until a consumer opts in"
1331 else if identityCompiler then
1332 throw "valley module-eval: the compiler must run as the git user, write only its own 0755 state directory, read the registry from the instance repository, write the grants the pre-receive hook reads, and have its authorized_keys added to what sshd reads under the %u token — sshd refuses a keys file owned by anyone but root or the account it authorizes, and a fixed path in that global list would authorize every registry key for every account on the host"
1333 else if identityStarts then
1334 throw "valley module-eval: the compiler must start when the registry's ref moves in the instance repository, watching its loose file alone with no trigger or start limit, and at 00:00 UTC within a second, with no randomized delay and no catch-up start, beside the recovery timer five minutes after each compilation, and it must start only while valley-init is active after success, which starts it and the controllers, without ever starting valley-init"
1335 else if identityIntegrator then
1336 throw "valley module-eval: a controller under a compiled registry must read the compiled signers file, start after the compilation, and sign under the name the registry publishes its key under"
1337 else if signersRenderedWithoutIntegrator then
1338 throw "valley module-eval: a signers publication rendered for a host whose integrator is off — there is no transfer statement to verify"
1339 else if signersUnpublished then
1340 throw "valley module-eval: the signers publisher must publish the controllers' own signers file and signing name into the instance repository, as the git user, writing nothing else, after valley-init and the compilation, at boot and whenever a file it publishes from changes, starting only while valley-init is active after success, which starts it, without ever starting valley-init"
1341 else if controllerApprovalInputsMisrendered then
1342 throw "valley module-eval: each controller must be handed the approval signers files the compiler writes, or none on a host that compiles no registry, and its project's push policy through its environment file"
1343 else if retentionMisrendered then
1344 throw "valley module-eval: a project that retains its change records must hand the hook retainChangeRecords = true, and one that does not must leave the key out"
1345 else if signerProjectsMisrendered then
1346 throw "valley module-eval: a controller is given a signer projects file exactly when the host restricts a signer to projects"
1347 else if identityKeepsDeclaredKeys then
1348 throw "valley module-eval: the declared authorized keys must stay authorized beside the compiled ones — a compiled file that replaced them would make a bad compilation a locked-out git user"
1349 else if workerRenderedWithoutEnable then
1350 throw "valley module-eval: check-worker machinery rendered for a host that never enabled it — nothing, the nix daemon's slice included, may change until a consumer opts in"
1351 else if buildSliceMisrendered then
1352 throw "valley module-eval: the build slice must put the nix daemon in valley-builds.slice at the quota and memory cap the host names, with no swap, and render nothing of the worker"
1353 else if workerMisrendered then
1354 throw "valley module-eval: the check worker must run as its own account outside the git group, free to run on any CPU, building as many checks at once as worker.buildSlots says (1 unset), keeping their outputs for worker.keepOutputs days (7 unset, none when null), each with nix's max-jobs and cores set from worker.maxJobs and worker.cores (1 and 4 unset), in a slice that holds it and the nix daemon to 4 CPUs and 8 GiB with no swap and no device policy, leaving the daemon's OOM policy at continue, reaching this host's projects through its sshd under the host's own key, on a timer whose first pass waits five minutes after the timer starts and whose later passes are counted from the end of each pass"
1355 else if workerDefaultsMisrendered then
1356 throw "valley module-eval: a check worker whose projects the host leaves unwritten must build for every project the controllers serve, one the host narrows must build for those alone, and the signers publication must carry the controllers' signer projects file"
1357 else if restackerRenderedWithoutEnable then
1358 throw "valley module-eval: restacker machinery rendered for a host that never enabled it"
1359 else if restackerMisrendered then
1360 throw "valley module-eval: each restacker controller must run valley-restacker run for its project as its own account outside the git group, with its own 0700 state directory as the only persistent path it may write, pushing over this host's sshd as its principal with the key systemd hands it as a credential, checking the host's own key, and reading the floor from the instance repository"
1361 else if telemetrySourceMisrendered then
1362 throw "valley module-eval: a unit the host lists in telemetry.localSources must be catalogued as an enabled local source with exactly those units, beside the module's own"
1363 else if webPublisherRenderedWithoutEnable then
1364 throw "valley module-eval: web publisher machinery rendered for a host that imports its module and never enabled it"
1365 else if webPublisherMisrendered then
1366 throw "valley module-eval: the web publisher must be a oneshot on a five-minute timer whose first pass waits five minutes and which no switch starts, run as a dynamic user in the git group with an empty safe.directory entry and then one exact entry per served repository, the repositories read-only, only its state and cache writable, the host's keys inaccessible and its memory capped with no swap, reading the instance repository and naming the host, the receiver, its token as a credential, the destination, the display mapping, the bounds on its bundles and storage, and the identity registry's directory"
1367 else if webPublisherLinksMisrendered != [ ] then
1368 throw "${builtins.toJSON webPublisherLinksMisrendered} valley module-eval: the web publisher's read links must be read live by each pass through the valley-web-links group from a file only root writes, under a links lock tmpfiles makes beside it, with a policy-only unit in the same sandbox that valley-web-link starts after every issue or revoke and once more while a link is pending, the wrapper trusting the unit's repositories and dumping no core, and the backup must hold the credential file's directory and the publisher's state"
1369 else if webReceiverRenderedWithoutEnable then
1370 throw "valley module-eval: web receiver machinery rendered for a host that imports its module and never enabled it"
1371 else if webReceiverMisrendered then
1372 throw "valley module-eval: the web receiver and valley-web must be two confined units started at boot, restarted on failure and requiring nothing of each other, as two users of the valley-web group, the receiver owning the state directory at 0750 with its token as a credential, its pinned verifiers, its caps and its own memory cap, and valley-web after it with the state directory read-only, no credential and a memory cap of its own"
1373 else if webReaderMisrendered then
1374 throw "valley module-eval: with an origin, valley-web must take --origin, take no core dump, and write the state directory's browser/ alone, which tmpfiles makes as its own at 0700 under the receiver's state directory at 0750, and the receiver's unit must not reach browser/"
1375 else
1376 pkgs.runCommand "valley-module-eval" {
1377 initScript = host.config.systemd.services.valley-init.script;
1378 sshdConfig = host.config.services.openssh.extraConfig;
1379 resticService = host.config.systemd.units."restic-backups-valley.service".text;
1380 resticTimer = host.config.systemd.units."restic-backups-valley.timer".text;
1381 protectedInit = protectedHost.config.systemd.services.valley-init.script;
1382 protectedKeys = lib.concatStringsSep "\n" protectedKeyLines;
1383 protectedShell = protectedHost.config.users.users.git.shell;
1384 integratorUnit = integratorHost.config.systemd.units."valley-integrator@.service".text;
1385 integratorInit = integratorHost.config.systemd.services.valley-init.script;
1386 integratorGuardedEnv = lib.removePrefix "-" (
1387 lib.replaceStrings [ "%i" ] [ "guarded" ]
1388 integratorHost.config.systemd.services."valley-integrator@".serviceConfig.EnvironmentFile
1389 );
1390 publishUnit = host.config.systemd.units."valley-publish@.service".text;
1391 identityInit = identityHost.config.systemd.services.valley-init.script;
1392 defaultWorkerController =
1393 defaultWorkerHost.config.systemd.services."valley-integrator@".serviceConfig.ExecStart;
1394 narrowedWorkerController =
1395 narrowedWorkerHost.config.systemd.services."valley-integrator@".serviceConfig.ExecStart;
1396 passAsFile = [
1397 "initScript"
1398 "sshdConfig"
1399 "resticService"
1400 "resticTimer"
1401 "protectedInit"
1402 "protectedKeys"
1403 "integratorUnit"
1404 "integratorInit"
1405 "publishUnit"
1406 "identityInit"
1407 ];
1408 } (builtins.readFile ./module-eval.sh);
1409}