@@ -14,6 +14,11 @@ with lib; let
1414
1515 users = config . users . users ;
1616
17+ sysusersEnabled =
18+ if isDarwin
19+ then false
20+ else options . systemd ? sysusers && ( config . systemd . sysusers . enable || config . services . userborn . enable ) ;
21+
1722 mountCommand =
1823 if isDarwin
1924 then ''
@@ -261,44 +266,67 @@ in {
261266 }
262267 ] ;
263268 }
264-
265269 ( optionalAttrs ( ! isDarwin ) {
270+ # When using sysusers we no longer be started as an activation script
271+ # because those are started in initrd while sysusers is started later.
272+ systemd . services . agenix-install-secrets = mkIf sysusersEnabled {
273+ wantedBy = [ "sysinit.target" ] ;
274+ after = [ "systemd-sysusers.service" ] ;
275+ unitConfig . DefaultDependencies = "no" ;
276+
277+ path = [ pkgs . mount ] ;
278+ serviceConfig = {
279+ Type = "oneshot" ;
280+ ExecStart = pkgs . writeShellScript "agenix-install" (
281+ concatLines [
282+ newGeneration
283+ installSecrets
284+ chownSecrets
285+ ]
286+ ) ;
287+ RemainAfterExit = true ;
288+ } ;
289+ } ;
290+
266291 # Create a new directory full of secrets for symlinking (this helps
267292 # ensure removed secrets are actually removed, or at least become
268293 # invalid symlinks).
269- system . activationScripts . agenixNewGeneration = {
270- text = newGeneration ;
271- deps = [
272- "specialfs"
273- ] ;
274- } ;
294+ system . activationScripts = mkIf ( ! sysusersEnabled ) {
295+ agenixNewGeneration = {
296+ text = newGeneration ;
297+ deps = [
298+ "specialfs"
299+ ] ;
300+ } ;
275301
276- system . activationScripts . agenixInstall = {
277- text = installSecrets ;
278- deps = [
279- "agenixNewGeneration"
280- "specialfs"
281- ] ;
282- } ;
302+ agenixInstall = {
303+ text = installSecrets ;
304+ deps = [
305+ "agenixNewGeneration"
306+ "specialfs"
307+ ] ;
308+ } ;
283309
284- # So user passwords can be encrypted.
285- system . activationScripts . users . deps = [ "agenixInstall" ] ;
310+ # So user passwords can be encrypted.
311+ users . deps = [ "agenixInstall" ] ;
286312
287- # Change ownership and group after users and groups are made.
288- system . activationScripts . agenixChown = {
289- text = chownSecrets ;
290- deps = [
291- "users"
292- "groups"
293- ] ;
294- } ;
313+ # Change ownership and group after users and groups are made.
314+ agenixChown = {
315+ text = chownSecrets ;
316+ deps = [
317+ "users"
318+ "groups"
319+ ] ;
320+ } ;
295321
296- # So other activation scripts can depend on agenix being done.
297- system . activationScripts . agenix = {
298- text = "" ;
299- deps = [ "agenixChown" ] ;
322+ # So other activation scripts can depend on agenix being done.
323+ agenix = {
324+ text = "" ;
325+ deps = [ "agenixChown" ] ;
326+ } ;
300327 } ;
301328 } )
329+
302330 ( optionalAttrs isDarwin {
303331 launchd . daemons . activate-agenix = {
304332 script = ''
0 commit comments