From 25a9948361cc6676e70c1b439e4d40f0610e8f76 Mon Sep 17 00:00:00 2001 From: oxalica Date: Fri, 8 Jul 2022 01:03:58 +0800 Subject: [PATCH] sway: import dbus env vars and explicitly specify them (#3031) - Importing all environment variables is considered deprecated for `systemdctl import-environment`. The list of variables are picked from: https://github.com/swaywm/sway/wiki/Systemd-integration#managing-user-applications-with-systemd The `XDG_CURRENT_DESKTOP` is said to be required for portals, see: https://github.com/nix-community/home-manager/pull/2385#issuecomment-1026454162 - DBus activation environment should also be updated. Otherwise, DBus activated programs, without a coresponding systemd service, cannot get a correct environment and would fail, eg. `mako`. --- modules/services/window-managers/i3-sway/sway.nix | 12 ++++++++++-- .../sway/sway-bar-focused-colors.conf | 2 +- .../window-managers/sway/sway-bar-focused-colors.nix | 2 +- .../window-managers/sway/sway-bindkeys-to-code.conf | 2 +- .../window-managers/sway/sway-bindkeys-to-code.nix | 2 +- .../services/window-managers/sway/sway-default.conf | 2 +- .../services/window-managers/sway/sway-default.nix | 2 +- .../sway/sway-followmouse-expected.conf | 2 +- .../sway/sway-followmouse-legacy-expected.conf | 2 +- .../window-managers/sway/sway-followmouse-legacy.nix | 2 +- .../window-managers/sway/sway-followmouse.nix | 2 +- .../services/window-managers/sway/sway-modules.conf | 2 +- .../services/window-managers/sway/sway-modules.nix | 2 +- .../window-managers/sway/sway-no-xwayland.nix | 2 +- .../window-managers/sway/sway-null-config.nix | 2 +- .../window-managers/sway/sway-null-package.conf | 2 +- .../window-managers/sway/sway-null-package.nix | 2 +- .../services/window-managers/sway/sway-post-2003.nix | 2 +- .../sway/sway-workspace-default-expected.conf | 2 +- .../window-managers/sway/sway-workspace-default.nix | 2 +- .../sway/sway-workspace-output-expected.conf | 2 +- .../window-managers/sway/sway-workspace-output.nix | 2 +- 22 files changed, 31 insertions(+), 23 deletions(-) diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix index f8ad577b9..55e9ab03e 100644 --- a/modules/services/window-managers/i3-sway/sway.nix +++ b/modules/services/window-managers/i3-sway/sway.nix @@ -309,7 +309,7 @@ let ) else [ ]) ++ (optional cfg.systemdIntegration '' - exec "systemctl --user import-environment; systemctl --user start sway-session.target"'') + exec "${pkgs.dbus}/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target"'') ++ (optional (!cfg.xwayland) "xwayland disable") ++ [ cfg.extraConfig ])); defaultSwayPackage = pkgs.sway.override { @@ -320,7 +320,7 @@ let }; in { - meta.maintainers = with maintainers; [ alexarice sumnerevans sebtm ]; + meta.maintainers = with maintainers; [ alexarice sumnerevans sebtm oxalica ]; options.wayland.windowManager.sway = { enable = mkEnableOption "sway wayland compositor"; @@ -346,6 +346,14 @@ in { Whether to enable sway-session.target on sway startup. This links to graphical-session.target. + Some important environment variables will be imported to systemd + and dbus user environment before reaching the target, including + + DISPLAY + WAYLAND_DISPLAY + SWAYSOCK + XDG_CURRENT_DESKTOP + ''; }; diff --git a/tests/modules/services/window-managers/sway/sway-bar-focused-colors.conf b/tests/modules/services/window-managers/sway/sway-bar-focused-colors.conf index f8e109aab..7f44a2b5b 100644 --- a/tests/modules/services/window-managers/sway/sway-bar-focused-colors.conf +++ b/tests/modules/services/window-managers/sway/sway-bar-focused-colors.conf @@ -106,4 +106,4 @@ bar { } } -exec "systemctl --user import-environment; systemctl --user start sway-session.target" +exec "/nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-bar-focused-colors.nix b/tests/modules/services/window-managers/sway/sway-bar-focused-colors.nix index 9746d0503..399790fbe 100644 --- a/tests/modules/services/window-managers/sway/sway-bar-focused-colors.nix +++ b/tests/modules/services/window-managers/sway/sway-bar-focused-colors.nix @@ -18,7 +18,7 @@ nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${./sway-bar-focused-colors.conf} ''; } diff --git a/tests/modules/services/window-managers/sway/sway-bindkeys-to-code.conf b/tests/modules/services/window-managers/sway/sway-bindkeys-to-code.conf index ce9fac65d..975bf2a89 100644 --- a/tests/modules/services/window-managers/sway/sway-bindkeys-to-code.conf +++ b/tests/modules/services/window-managers/sway/sway-bindkeys-to-code.conf @@ -103,4 +103,4 @@ bar { } } -exec "systemctl --user import-environment; systemctl --user start sway-session.target" +exec "/nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-bindkeys-to-code.nix b/tests/modules/services/window-managers/sway/sway-bindkeys-to-code.nix index 5e62748cb..0c3929256 100644 --- a/tests/modules/services/window-managers/sway/sway-bindkeys-to-code.nix +++ b/tests/modules/services/window-managers/sway/sway-bindkeys-to-code.nix @@ -13,7 +13,7 @@ nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${./sway-bindkeys-to-code.conf} ''; } diff --git a/tests/modules/services/window-managers/sway/sway-default.conf b/tests/modules/services/window-managers/sway/sway-default.conf index 82cf254e5..0ca82f99a 100644 --- a/tests/modules/services/window-managers/sway/sway-default.conf +++ b/tests/modules/services/window-managers/sway/sway-default.conf @@ -103,4 +103,4 @@ bar { } } -exec "systemctl --user import-environment; systemctl --user start sway-session.target" +exec "/nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-default.nix b/tests/modules/services/window-managers/sway/sway-default.nix index 7bd437317..24796118c 100644 --- a/tests/modules/services/window-managers/sway/sway-default.nix +++ b/tests/modules/services/window-managers/sway/sway-default.nix @@ -12,7 +12,7 @@ nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${./sway-default.conf} ''; } diff --git a/tests/modules/services/window-managers/sway/sway-followmouse-expected.conf b/tests/modules/services/window-managers/sway/sway-followmouse-expected.conf index 287e03225..e8afc19dd 100644 --- a/tests/modules/services/window-managers/sway/sway-followmouse-expected.conf +++ b/tests/modules/services/window-managers/sway/sway-followmouse-expected.conf @@ -81,4 +81,4 @@ mode "resize" { bindsym l resize grow width 10 px } -exec "systemctl --user import-environment; systemctl --user start sway-session.target" +exec "/nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-followmouse-legacy-expected.conf b/tests/modules/services/window-managers/sway/sway-followmouse-legacy-expected.conf index e6f308c3d..bba46942e 100644 --- a/tests/modules/services/window-managers/sway/sway-followmouse-legacy-expected.conf +++ b/tests/modules/services/window-managers/sway/sway-followmouse-legacy-expected.conf @@ -81,4 +81,4 @@ mode "resize" { bindsym l resize grow width 10 px } -exec "systemctl --user import-environment; systemctl --user start sway-session.target" +exec "/nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix b/tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix index ce69d9f7f..52aa3cc4a 100644 --- a/tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix +++ b/tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix @@ -18,7 +18,7 @@ with lib; nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${./sway-followmouse-legacy-expected.conf} ''; } diff --git a/tests/modules/services/window-managers/sway/sway-followmouse.nix b/tests/modules/services/window-managers/sway/sway-followmouse.nix index 7065dd1ca..788ad218f 100644 --- a/tests/modules/services/window-managers/sway/sway-followmouse.nix +++ b/tests/modules/services/window-managers/sway/sway-followmouse.nix @@ -16,7 +16,7 @@ nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${./sway-followmouse-expected.conf} ''; } diff --git a/tests/modules/services/window-managers/sway/sway-modules.conf b/tests/modules/services/window-managers/sway/sway-modules.conf index 99e54c841..8753b24a0 100644 --- a/tests/modules/services/window-managers/sway/sway-modules.conf +++ b/tests/modules/services/window-managers/sway/sway-modules.conf @@ -115,4 +115,4 @@ bar { } } -exec "systemctl --user import-environment; systemctl --user start sway-session.target" +exec "/nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-modules.nix b/tests/modules/services/window-managers/sway/sway-modules.nix index 96366ab0a..567f7b5c6 100644 --- a/tests/modules/services/window-managers/sway/sway-modules.nix +++ b/tests/modules/services/window-managers/sway/sway-modules.nix @@ -18,7 +18,7 @@ nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${./sway-modules.conf} ''; } diff --git a/tests/modules/services/window-managers/sway/sway-no-xwayland.nix b/tests/modules/services/window-managers/sway/sway-no-xwayland.nix index f9111089a..44077d441 100644 --- a/tests/modules/services/window-managers/sway/sway-no-xwayland.nix +++ b/tests/modules/services/window-managers/sway/sway-no-xwayland.nix @@ -13,7 +13,7 @@ nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${ pkgs.writeText "expected" '' xwayland disable diff --git a/tests/modules/services/window-managers/sway/sway-null-config.nix b/tests/modules/services/window-managers/sway/sway-null-config.nix index 00128c8f3..0c0d1e7b4 100644 --- a/tests/modules/services/window-managers/sway/sway-null-config.nix +++ b/tests/modules/services/window-managers/sway/sway-null-config.nix @@ -12,7 +12,7 @@ nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${pkgs.writeText "expected" ""} ''; } diff --git a/tests/modules/services/window-managers/sway/sway-null-package.conf b/tests/modules/services/window-managers/sway/sway-null-package.conf index 82cf254e5..0ca82f99a 100644 --- a/tests/modules/services/window-managers/sway/sway-null-package.conf +++ b/tests/modules/services/window-managers/sway/sway-null-package.conf @@ -103,4 +103,4 @@ bar { } } -exec "systemctl --user import-environment; systemctl --user start sway-session.target" +exec "/nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-null-package.nix b/tests/modules/services/window-managers/sway/sway-null-package.nix index fe2a45196..a449b42c4 100644 --- a/tests/modules/services/window-managers/sway/sway-null-package.nix +++ b/tests/modules/services/window-managers/sway/sway-null-package.nix @@ -21,7 +21,7 @@ nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${./sway-null-package.conf} ''; } diff --git a/tests/modules/services/window-managers/sway/sway-post-2003.nix b/tests/modules/services/window-managers/sway/sway-post-2003.nix index 7596250ec..72e1fd9ea 100644 --- a/tests/modules/services/window-managers/sway/sway-post-2003.nix +++ b/tests/modules/services/window-managers/sway/sway-post-2003.nix @@ -14,7 +14,7 @@ nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${./sway-default.conf} ''; } diff --git a/tests/modules/services/window-managers/sway/sway-workspace-default-expected.conf b/tests/modules/services/window-managers/sway/sway-workspace-default-expected.conf index 233e567d9..2f2dd1259 100644 --- a/tests/modules/services/window-managers/sway/sway-workspace-default-expected.conf +++ b/tests/modules/services/window-managers/sway/sway-workspace-default-expected.conf @@ -102,4 +102,4 @@ bar { } } -exec "systemctl --user import-environment; systemctl --user start sway-session.target" +exec "/nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-workspace-default.nix b/tests/modules/services/window-managers/sway/sway-workspace-default.nix index d94110980..6af944eb0 100644 --- a/tests/modules/services/window-managers/sway/sway-workspace-default.nix +++ b/tests/modules/services/window-managers/sway/sway-workspace-default.nix @@ -13,7 +13,7 @@ nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${./sway-workspace-default-expected.conf} ''; } diff --git a/tests/modules/services/window-managers/sway/sway-workspace-output-expected.conf b/tests/modules/services/window-managers/sway/sway-workspace-output-expected.conf index 683298b6d..4ec1e7ce6 100644 --- a/tests/modules/services/window-managers/sway/sway-workspace-output-expected.conf +++ b/tests/modules/services/window-managers/sway/sway-workspace-output-expected.conf @@ -107,4 +107,4 @@ workspace "1" output eDP workspace "ABC" output DP workspace "3: Test" output HDMI workspace "!"§$%&/(){}[]=?\*#<>-_.:,;²³" output DVI -exec "systemctl --user import-environment; systemctl --user start sway-session.target" +exec "/nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target" diff --git a/tests/modules/services/window-managers/sway/sway-workspace-output.nix b/tests/modules/services/window-managers/sway/sway-workspace-output.nix index ce51c1f51..e096aa1f4 100644 --- a/tests/modules/services/window-managers/sway/sway-workspace-output.nix +++ b/tests/modules/services/window-managers/sway/sway-workspace-output.nix @@ -39,7 +39,7 @@ in { nmt.script = '' assertFileExists home-files/.config/sway/config - assertFileContent home-files/.config/sway/config \ + assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${./sway-workspace-output-expected.conf} ''; }