From 8ab4e866f51dbeb08dea3fc176ad4fa3eb675e79 Mon Sep 17 00:00:00 2001 From: Olli Helenius Date: Sat, 11 Nov 2023 01:51:53 +0200 Subject: [PATCH] systemd: avoid creating an empty user.conf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to the defaults in `systemd.user.settings`, the default value when there are no settings explicitly set is `{ Manager = { }; }`. This means an empty file is created even when `systemd.user.settings` is never used in home-manager configuration. Since user’s `user.conf` is preferred to the global `/etc/systemd/user.conf`, this can cause any values set in the latter to be discarded. --- modules/systemd.nix | 6 ++++-- tests/modules/systemd/default.nix | 1 + tests/modules/systemd/empty-user-config.nix | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/modules/systemd/empty-user-config.nix diff --git a/modules/systemd.nix b/modules/systemd.nix index 18e88819d..041b9dfac 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -4,7 +4,9 @@ let cfg = config.systemd.user; - inherit (lib) getAttr hm isBool literalExpression mkIf mkMerge mkOption types; + inherit (lib) + any attrValues getAttr hm isBool literalExpression mkIf mkMerge mkOption + types; settingsFormat = pkgs.formats.ini { listsAsDuplicateKeys = true; }; @@ -93,7 +95,7 @@ let + "\n"; }; - settings = mkIf (cfg.settings != { }) { + settings = mkIf (any (v: v != { }) (attrValues cfg.settings)) { "systemd/user.conf".source = settingsFormat.generate "user.conf" cfg.settings; }; diff --git a/tests/modules/systemd/default.nix b/tests/modules/systemd/default.nix index 250b8c79c..ee8a9ae6b 100644 --- a/tests/modules/systemd/default.nix +++ b/tests/modules/systemd/default.nix @@ -3,6 +3,7 @@ systemd-services-disabled-for-root = ./services-disabled-for-root.nix; systemd-session-variables = ./session-variables.nix; systemd-user-config = ./user-config.nix; + systemd-empty-user-config = ./empty-user-config.nix; systemd-slices = ./slices.nix; systemd-timers = ./timers.nix; } diff --git a/tests/modules/systemd/empty-user-config.nix b/tests/modules/systemd/empty-user-config.nix new file mode 100644 index 000000000..9e192ae4a --- /dev/null +++ b/tests/modules/systemd/empty-user-config.nix @@ -0,0 +1,8 @@ +{ pkgs, ... }: + +{ + nmt.script = '' + userConf=home-files/.config/systemd/user.conf + assertPathNotExists $userConf + ''; +}