From 1a68e21d474c5d6005812459c9bce28168625384 Mon Sep 17 00:00:00 2001 From: Orivej Desh Date: Wed, 2 Sep 2020 02:54:11 +0000 Subject: [PATCH] nixos/systemd: support adding and overriding tmpfiles.d via environment.etc (#96766) This allows the user to configure systemd tmpfiles.d via `environment.etc."tmpfiles.d/X.conf".text = "..."`, which after #93073 causes permission denied (with new X.conf): ``` ln: failed to create symbolic link '/nix/store/...-etc/etc/tmpfiles.d/X.conf': Permission denied builder for '/nix/store/...-etc.drv' failed with exit code 1 ``` or collision between environment.etc and systemd-default-tmpfiles packages (with existing X.conf, such as tmp.conf): ``` duplicate entry tmpfiles.d/tmp.conf -> /nix/store/...-etc-tmp.conf mismatched duplicate entry /nix/store/...-systemd-246/example/tmpfiles.d/tmp.conf <-> /nix/store/...-etc-tmp.conf builder for '/nix/store/...-etc.drv' failed with exit code 1 ``` Fixes #96755 --- nixos/modules/system/boot/systemd.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index 10343df70aa..f6c23c9b900 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -1006,7 +1006,7 @@ in "sysctl.d/50-coredump.conf".source = "${systemd}/example/sysctl.d/50-coredump.conf"; "sysctl.d/50-default.conf".source = "${systemd}/example/sysctl.d/50-default.conf"; - "tmpfiles.d".source = pkgs.symlinkJoin { + "tmpfiles.d".source = (pkgs.symlinkJoin { name = "tmpfiles.d"; paths = map (p: p + "/lib/tmpfiles.d") cfg.tmpfiles.packages; postBuild = '' @@ -1016,8 +1016,10 @@ in exit 1 ) done - ''; - }; + '' + concatMapStrings (name: optionalString (hasPrefix "tmpfiles.d/" name) '' + rm -f $out/${removePrefix "tmpfiles.d/" name} + '') config.system.build.etc.targets; + }) + "/*"; "systemd/system-generators" = { source = hooks "generators" cfg.generators; }; "systemd/system-shutdown" = { source = hooks "shutdown" cfg.shutdown; };