gunk-dev/the-valley

host-module.nix

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