From a4b0a3faa4055521f2a20cfafe26eb85e6954751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Fri, 18 Mar 2022 03:22:53 +0100 Subject: [PATCH] xdg: add `XDG_*_HOME` variables to `systemd.user.sessionVariables` (#2790) Make sure those variables are set in systemd user services. This mirrors the situation for `XDG_*_DIRS` variables. --- modules/misc/xdg.nix | 18 +++++++++++------- tests/modules/misc/xdg/system-dirs.nix | 4 ++++ .../systemd/session-variables-expected.conf | 3 --- tests/modules/systemd/session-variables.nix | 4 ++++ 4 files changed, 19 insertions(+), 10 deletions(-) delete mode 100644 tests/modules/systemd/session-variables-expected.conf diff --git a/modules/misc/xdg.nix b/modules/misc/xdg.nix index 5961cac39..247e73192 100644 --- a/modules/misc/xdg.nix +++ b/modules/misc/xdg.nix @@ -80,18 +80,22 @@ in { }; config = mkMerge [ - (mkIf cfg.enable { - xdg.cacheHome = mkDefault defaultCacheHome; - xdg.configHome = mkDefault defaultConfigHome; - xdg.dataHome = mkDefault defaultDataHome; - xdg.stateHome = mkDefault defaultStateHome; - - home.sessionVariables = { + (let + variables = { XDG_CACHE_HOME = cfg.cacheHome; XDG_CONFIG_HOME = cfg.configHome; XDG_DATA_HOME = cfg.dataHome; XDG_STATE_HOME = cfg.stateHome; }; + in mkIf cfg.enable { + xdg.cacheHome = mkDefault defaultCacheHome; + xdg.configHome = mkDefault defaultConfigHome; + xdg.dataHome = mkDefault defaultDataHome; + xdg.stateHome = mkDefault defaultStateHome; + + home.sessionVariables = variables; + systemd.user.sessionVariables = + mkIf pkgs.stdenv.hostPlatform.isLinux variables; }) # Legacy non-deterministic setup. diff --git a/tests/modules/misc/xdg/system-dirs.nix b/tests/modules/misc/xdg/system-dirs.nix index 9bfa2ae44..fa34ae0b5 100644 --- a/tests/modules/misc/xdg/system-dirs.nix +++ b/tests/modules/misc/xdg/system-dirs.nix @@ -11,8 +11,12 @@ assertFileContent $envFile ${ pkgs.writeText "expected" '' LOCALE_ARCHIVE_2_27=${pkgs.glibcLocales}/lib/locale/locale-archive + XDG_CACHE_HOME=/home/hm-user/.cache XDG_CONFIG_DIRS=/etc/xdg:/foo/bar''${XDG_CONFIG_DIRS:+:$XDG_CONFIG_DIRS} + XDG_CONFIG_HOME=/home/hm-user/.config XDG_DATA_DIRS=/usr/local/share:/usr/share:/baz/quux''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS} + XDG_DATA_HOME=/home/hm-user/.local/share + XDG_STATE_HOME=/home/hm-user/.local/state '' } diff --git a/tests/modules/systemd/session-variables-expected.conf b/tests/modules/systemd/session-variables-expected.conf deleted file mode 100644 index 65ced43ea..000000000 --- a/tests/modules/systemd/session-variables-expected.conf +++ /dev/null @@ -1,3 +0,0 @@ -LOCALE_ARCHIVE_2_27=@glibcLocales@/lib/locale/locale-archive -V_int=1 -V_str=2 diff --git a/tests/modules/systemd/session-variables.nix b/tests/modules/systemd/session-variables.nix index 8722a9ab3..cbc348c44 100644 --- a/tests/modules/systemd/session-variables.nix +++ b/tests/modules/systemd/session-variables.nix @@ -15,6 +15,10 @@ LOCALE_ARCHIVE_2_27=${pkgs.glibcLocales}/lib/locale/locale-archive V_int=1 V_str=2 + XDG_CACHE_HOME=/home/hm-user/.cache + XDG_CONFIG_HOME=/home/hm-user/.config + XDG_DATA_HOME=/home/hm-user/.local/share + XDG_STATE_HOME=/home/hm-user/.local/state '' } '';