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`.
This commit is contained in:
oxalica 2022-07-08 01:03:58 +08:00 committed by GitHub
parent 12cfcc1b9d
commit 25a9948361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 31 additions and 23 deletions

View File

@ -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 <filename>sway-session.target</filename> on
sway startup. This links to
<filename>graphical-session.target</filename>.
Some important environment variables will be imported to systemd
and dbus user environment before reaching the target, including
<itemizedlist>
<listitem><para><literal>DISPLAY</literal></para></listitem>
<listitem><para><literal>WAYLAND_DISPLAY</literal></para></listitem>
<listitem><para><literal>SWAYSOCK</literal></para></listitem>
<listitem><para><literal>XDG_CURRENT_DESKTOP</literal></para></listitem>
</itemizedlist>
'';
};

View File

@ -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"

View File

@ -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}
'';
}

View File

@ -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"

View File

@ -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}
'';
}

View File

@ -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"

View File

@ -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}
'';
}

View File

@ -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"

View File

@ -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"

View File

@ -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}
'';
}

View File

@ -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}
'';
}

View File

@ -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"

View File

@ -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}
'';
}

View File

@ -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

View File

@ -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" ""}
'';
}

View File

@ -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"

View File

@ -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}
'';
}

View File

@ -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}
'';
}

View File

@ -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"

View File

@ -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}
'';
}

View File

@ -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"

View File

@ -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}
'';
}