From 78ceec68f29ed56d6118617e9f0f588bf164067f Mon Sep 17 00:00:00 2001 From: arcnmx Date: Sun, 7 May 2023 14:59:56 -0700 Subject: [PATCH] xsession: cleanup systemd variables (#3636) --- modules/xsession.nix | 7 ++++++- tests/modules/misc/xsession/basic-xprofile-expected.txt | 2 +- tests/modules/misc/xsession/basic-xsession-expected.txt | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/xsession.nix b/modules/xsession.nix index 7ba9b54e9..6d05d4329 100644 --- a/modules/xsession.nix +++ b/modules/xsession.nix @@ -78,6 +78,7 @@ in { importedVariables = mkOption { type = types.listOf (types.strMatching "[a-zA-Z_][a-zA-Z0-9_]*"); + apply = unique; example = [ "GDK_PIXBUF_ICON_LOADER" ]; visible = false; description = '' @@ -184,7 +185,7 @@ in { ${optionalString (cfg.importedVariables != [ ]) ("systemctl --user import-environment " - + toString (unique cfg.importedVariables))} + + escapeShellArgs cfg.importedVariables)} ${cfg.profileExtra} @@ -212,6 +213,10 @@ in { while [ -n "$(systemctl --user --no-legend --state=deactivating list-units)" ]; do sleep 0.5 done + + ${optionalString (cfg.importedVariables != [ ]) + ("systemctl --user unset-environment " + + escapeShellArgs cfg.importedVariables)} ''; }; }; diff --git a/tests/modules/misc/xsession/basic-xprofile-expected.txt b/tests/modules/misc/xsession/basic-xprofile-expected.txt index 282f8f5c5..b3d591c22 100644 --- a/tests/modules/misc/xsession/basic-xprofile-expected.txt +++ b/tests/modules/misc/xsession/basic-xprofile-expected.txt @@ -9,7 +9,7 @@ fi # script starts up graphical-session.target. systemctl --user stop graphical-session.target graphical-session-pre.target -systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS DISPLAY SSH_AUTH_SOCK XAUTHORITY XDG_DATA_DIRS XDG_RUNTIME_DIR XDG_SESSION_ID EXTRA_IMPORTED_VARIABLE +systemctl --user import-environment 'DBUS_SESSION_BUS_ADDRESS' 'DISPLAY' 'SSH_AUTH_SOCK' 'XAUTHORITY' 'XDG_DATA_DIRS' 'XDG_RUNTIME_DIR' 'XDG_SESSION_ID' 'EXTRA_IMPORTED_VARIABLE' profile extra commands diff --git a/tests/modules/misc/xsession/basic-xsession-expected.txt b/tests/modules/misc/xsession/basic-xsession-expected.txt index 423e7779c..a95bb35ab 100644 --- a/tests/modules/misc/xsession/basic-xsession-expected.txt +++ b/tests/modules/misc/xsession/basic-xsession-expected.txt @@ -16,3 +16,5 @@ systemctl --user stop graphical-session-pre.target while [ -n "$(systemctl --user --no-legend --state=deactivating list-units)" ]; do sleep 0.5 done + +systemctl --user unset-environment 'DBUS_SESSION_BUS_ADDRESS' 'DISPLAY' 'SSH_AUTH_SOCK' 'XAUTHORITY' 'XDG_DATA_DIRS' 'XDG_RUNTIME_DIR' 'XDG_SESSION_ID' 'EXTRA_IMPORTED_VARIABLE'