Skip to content

Commit 4cd511f

Browse files
committed
modules/sops: allow forcing systemd-based activation
By allowing users to optionally force using systemd unit-based activation, they can inject dependencies on other services or mountpoints (for instance, when the age key is not stored on the root file system).
1 parent d75e4f8 commit 4cd511f

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

modules/sops/default.nix

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ let
2929
# Currently, all templates are "regular" (there's no support for `neededForUsers` for templates.)
3030
regularTemplates = cfg.templates;
3131

32-
useSystemdActivation =
33-
(options.systemd ? sysusers && config.systemd.sysusers.enable)
34-
|| (options.services ? userborn && config.services.userborn.enable);
35-
3632
withEnvironment = import ./with-environment.nix {
3733
# sops >=3.10.0 now unconditionally searches
3834
# for an SSH key in $HOME/.ssh/, introduced in #1692 [0]. Since in the
@@ -319,6 +315,23 @@ in
319315
'';
320316
};
321317

318+
useSystemdActivation = lib.mkOption {
319+
type = lib.types.bool;
320+
default =
321+
(options.systemd ? sysusers && config.systemd.sysusers.enable)
322+
|| (options.services ? userborn && config.services.userborn.enable);
323+
defaultText = lib.literalExpression (
324+
"(options.systemd ? sysusers && config.systemd.sysusers.enable) "
325+
+ "|| (options.services ? userborn && config.services.userborn.enable)"
326+
);
327+
description = ''
328+
Use a systemd unit to install secrets, instead of deploying them using an activation script.
329+
330+
This option is automatically enabled when systemd-sysusers or userborn are used to manage users and groups.
331+
It can also be useful to specify additional dependencies to be satisfied before secrets are installed, such as required mountpoints for SOPS key files.
332+
'';
333+
};
334+
322335
age = {
323336
keyFile = lib.mkOption {
324337
type = lib.types.nullOr pathNotInStore;
@@ -433,7 +446,7 @@ in
433446
);
434447

435448
# When using sysusers we no longer are started as an activation script because those are started in initrd while sysusers is started later.
436-
systemd.services.sops-install-secrets = lib.mkIf (regularSecrets != { } && useSystemdActivation) {
449+
systemd.services.sops-install-secrets = lib.mkIf (regularSecrets != { } && cfg.useSystemdActivation) {
437450
wantedBy = [ "sysinit.target" ];
438451
after = [ "systemd-sysusers.service" ];
439452
environment = cfg.environment;
@@ -447,7 +460,7 @@ in
447460
};
448461

449462
system.activationScripts = {
450-
setupSecrets = lib.mkIf (regularSecrets != { } && !useSystemdActivation) (
463+
setupSecrets = lib.mkIf (regularSecrets != { } && !cfg.useSystemdActivation) (
451464
lib.stringAfter
452465
(
453466
[

0 commit comments

Comments
 (0)