|
430 | 430 | ]; |
431 | 431 | config = lib.mkMerge [ |
432 | 432 | (lib.mkIf (cfg.secrets != { }) { |
433 | | - assertions = |
434 | | - [ |
435 | | - { |
436 | | - assertion = |
437 | | - cfg.gnupg.home != null |
438 | | - || cfg.gnupg.sshKeyPaths != [ ] |
439 | | - || cfg.age.keyFile != null |
440 | | - || cfg.age.sshKeyPaths != [ ]; |
441 | | - message = "No key source configured for sops. Either set services.openssh.enable or set sops.age.keyFile or sops.gnupg.home"; |
442 | | - } |
443 | | - { |
444 | | - assertion = !(cfg.gnupg.home != null && cfg.gnupg.sshKeyPaths != [ ]); |
445 | | - message = "Exactly one of sops.gnupg.home and sops.gnupg.sshKeyPaths must be set"; |
446 | | - } |
447 | | - ] |
448 | | - ++ lib.optionals cfg.validateSopsFiles ( |
449 | | - lib.concatLists ( |
450 | | - lib.mapAttrsToList (name: secret: [ |
451 | | - { |
452 | | - assertion = secret.uid != null && secret.uid != 0 -> secret.owner == null; |
453 | | - message = "In ${secret.name} exactly one of sops.owner and sops.uid must be set"; |
454 | | - } |
455 | | - { |
456 | | - assertion = secret.gid != null && secret.gid != 0 -> secret.group == null; |
457 | | - message = "In ${secret.name} exactly one of sops.group and sops.gid must be set"; |
458 | | - } |
459 | | - ]) cfg.secrets |
460 | | - ) |
461 | | - ); |
| 433 | + assertions = [ |
| 434 | + { |
| 435 | + assertion = |
| 436 | + cfg.gnupg.home != null |
| 437 | + || cfg.gnupg.sshKeyPaths != [ ] |
| 438 | + || cfg.age.keyFile != null |
| 439 | + || cfg.age.sshKeyPaths != [ ]; |
| 440 | + message = "No key source configured for sops. Either set services.openssh.enable or set sops.age.keyFile or sops.gnupg.home"; |
| 441 | + } |
| 442 | + { |
| 443 | + assertion = !(cfg.gnupg.home != null && cfg.gnupg.sshKeyPaths != [ ]); |
| 444 | + message = "Exactly one of sops.gnupg.home and sops.gnupg.sshKeyPaths must be set"; |
| 445 | + } |
| 446 | + ] |
| 447 | + ++ lib.optionals cfg.validateSopsFiles ( |
| 448 | + lib.concatLists ( |
| 449 | + lib.mapAttrsToList (name: secret: [ |
| 450 | + { |
| 451 | + assertion = secret.uid != null && secret.uid != 0 -> secret.owner == null; |
| 452 | + message = "In ${secret.name} exactly one of sops.owner and sops.uid must be set"; |
| 453 | + } |
| 454 | + { |
| 455 | + assertion = secret.gid != null && secret.gid != 0 -> secret.group == null; |
| 456 | + message = "In ${secret.name} exactly one of sops.group and sops.gid must be set"; |
| 457 | + } |
| 458 | + ]) cfg.secrets |
| 459 | + ) |
| 460 | + ); |
462 | 461 |
|
463 | 462 | sops.environment.SOPS_GPG_EXEC = lib.mkIf (cfg.gnupg.home != null || cfg.gnupg.sshKeyPaths != [ ]) ( |
464 | 463 | lib.mkDefault "${cfg.gnupg.package}/bin/gpg" |
465 | 464 | ); |
466 | 465 |
|
467 | 466 | # When using sysusers we no longer are started as an activation script because those are started in initrd while sysusers is started later. |
468 | | - systemd.services.sops-install-secrets = lib.mkIf (regularSecrets != { } && cfg.useSystemdActivation) { |
469 | | - wantedBy = [ "sysinit.target" ]; |
470 | | - after = [ "local-fs.target" "systemd-sysusers.service" "userborn.service" ]; |
471 | | - requiredBy = [ "sysinit-reactivation.target" ]; |
472 | | - before = [ "sysinit-reactivation.target" ]; |
473 | | - environment = cfg.environment; |
474 | | - unitConfig.DefaultDependencies = "no"; |
475 | | - path = cfg.age.plugins; |
476 | | - |
477 | | - serviceConfig = { |
478 | | - Type = "oneshot"; |
479 | | - ExecStart = [ "${cfg.package}/bin/sops-install-secrets ${manifest}" ]; |
480 | | - RemainAfterExit = true; |
481 | | - }; |
482 | | - }; |
| 467 | + systemd.services.sops-install-secrets = |
| 468 | + lib.mkIf (regularSecrets != { } && cfg.useSystemdActivation) |
| 469 | + { |
| 470 | + wantedBy = [ "sysinit.target" ]; |
| 471 | + after = [ |
| 472 | + "local-fs.target" |
| 473 | + "systemd-sysusers.service" |
| 474 | + "userborn.service" |
| 475 | + ]; |
| 476 | + requiredBy = [ "sysinit-reactivation.target" ]; |
| 477 | + before = [ "sysinit-reactivation.target" ]; |
| 478 | + environment = cfg.environment; |
| 479 | + unitConfig.DefaultDependencies = "no"; |
| 480 | + path = cfg.age.plugins; |
| 481 | + |
| 482 | + serviceConfig = { |
| 483 | + Type = "oneshot"; |
| 484 | + ExecStart = [ "${cfg.package}/bin/sops-install-secrets ${manifest}" ]; |
| 485 | + RemainAfterExit = true; |
| 486 | + }; |
| 487 | + unitConfig.RequiresMountsFor = lib.concatLists [ |
| 488 | + (lib.lists.optional (cfg.gnupg.home != null) cfg.gnupg.home) |
| 489 | + cfg.gnupg.sshKeyPaths |
| 490 | + (lib.lists.optional (cfg.age.keyFile != null) cfg.age.keyFile) |
| 491 | + cfg.age.sshKeyPaths |
| 492 | + ]; |
| 493 | + }; |
483 | 494 |
|
484 | 495 | system.activationScripts = { |
485 | 496 | setupSecrets = lib.mkIf (regularSecrets != { } && !cfg.useSystemdActivation) ( |
|
0 commit comments