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