From 0144ac418ef633bfc9dbd89b8c199ad3a617c59f Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sat, 10 Jun 2023 12:10:40 +0200 Subject: [PATCH] sway: add support for XDG autostart using systemd (#3747) * sway: add support for XDG autostart using systemd Using the option wayland.windowManager.sway.systemd.xdgAutostart, users can now choose to start applications present in $XDG_CONFIG_HOME/autostart when starting their sway session. This change also renames wayland.windowManager.sway.systemdIntegration to wayland.windowManager.sway.systemd.enable; Signed-off-by: Sefa Eyeoglu * sway: add Scrumplex to maintainers Signed-off-by: Sefa Eyeoglu --------- Signed-off-by: Sefa Eyeoglu --- .../services/window-managers/i3-sway/sway.nix | 65 +++++++++++++------ .../services/window-managers/sway/default.nix | 1 + .../window-managers/sway/sway-default.nix | 4 ++ .../window-managers/sway/sway-default.target | 6 ++ .../window-managers/sway/sway-no-xwayland.nix | 2 +- .../window-managers/sway/sway-null-config.nix | 2 +- .../sway/sway-systemd-autostart.nix | 20 ++++++ .../sway/sway-systemd-autostart.target | 8 +++ 8 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 tests/modules/services/window-managers/sway/sway-default.target create mode 100644 tests/modules/services/window-managers/sway/sway-systemd-autostart.nix create mode 100644 tests/modules/services/window-managers/sway/sway-systemd-autostart.target diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix index 6f61e31d..5568d6ab 100644 --- a/modules/services/window-managers/i3-sway/sway.nix +++ b/modules/services/window-managers/i3-sway/sway.nix @@ -316,7 +316,7 @@ let ++ map workspaceOutputStr workspaceOutputAssign # custom mapping ) else - [ ]) ++ (optional cfg.systemdIntegration '' + [ ]) ++ (optional cfg.systemd.enable '' exec "${pkgs.dbus}/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP XDG_SESSION_TYPE NIXOS_OZONE_WL; systemctl --user start sway-session.target"'') ++ (optional (!cfg.xwayland) "xwayland disable") ++ [ cfg.extraConfig ])); @@ -328,7 +328,19 @@ let }; in { - meta.maintainers = with maintainers; [ alexarice sumnerevans sebtm oxalica ]; + meta.maintainers = with maintainers; [ + Scrumplex + alexarice + sumnerevans + sebtm + oxalica + ]; + + imports = let modulePath = [ "wayland" "windowManager" "sway" ]; + in [ + (mkRenamedOptionModule (modulePath ++ [ "systemdIntegration" ]) + (modulePath ++ [ "systemd" "enable" ])) + ]; options.wayland.windowManager.sway = { enable = mkEnableOption "sway wayland compositor"; @@ -346,22 +358,32 @@ in { ''; }; - systemdIntegration = mkOption { - type = types.bool; - default = pkgs.stdenv.isLinux; - example = false; - description = '' - 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 - + systemd = { + enable = mkOption { + type = types.bool; + default = pkgs.stdenv.isLinux; + example = false; + description = '' + 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 + + ''; + }; + + xdgAutostart = mkEnableOption '' + autostart of applications using + + systemd-xdg-autostart-generator + 8 + ''; }; @@ -469,13 +491,16 @@ in { ''; }; - systemd.user.targets.sway-session = mkIf cfg.systemdIntegration { + systemd.user.targets.sway-session = mkIf cfg.systemd.enable { Unit = { Description = "sway compositor session"; Documentation = [ "man:systemd.special(7)" ]; BindsTo = [ "graphical-session.target" ]; - Wants = [ "graphical-session-pre.target" ]; + Wants = [ "graphical-session-pre.target" ] + ++ optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target"; After = [ "graphical-session-pre.target" ]; + Before = + optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target"; }; }; diff --git a/tests/modules/services/window-managers/sway/default.nix b/tests/modules/services/window-managers/sway/default.nix index f11ef7e3..2c7f5ff7 100644 --- a/tests/modules/services/window-managers/sway/default.nix +++ b/tests/modules/services/window-managers/sway/default.nix @@ -10,6 +10,7 @@ sway-null-config = ./sway-null-config.nix; sway-null-package = ./sway-null-package.nix; sway-post-2003 = ./sway-post-2003.nix; + sway-systemd-autostart = ./sway-systemd-autostart.nix; sway-workspace-default = ./sway-workspace-default.nix; sway-workspace-output = ./sway-workspace-output.nix; swaynag-example-settings = ./swaynag-example-settings.nix; diff --git a/tests/modules/services/window-managers/sway/sway-default.nix b/tests/modules/services/window-managers/sway/sway-default.nix index 24796118..59527247 100644 --- a/tests/modules/services/window-managers/sway/sway-default.nix +++ b/tests/modules/services/window-managers/sway/sway-default.nix @@ -14,5 +14,9 @@ assertFileExists home-files/.config/sway/config assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ ${./sway-default.conf} + + assertFileExists home-files/.config/systemd/user/sway-session.target + assertFileContent home-files/.config/systemd/user/sway-session.target \ + ${./sway-default.target} ''; } diff --git a/tests/modules/services/window-managers/sway/sway-default.target b/tests/modules/services/window-managers/sway/sway-default.target new file mode 100644 index 00000000..be32aac8 --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-default.target @@ -0,0 +1,6 @@ +[Unit] +After=graphical-session-pre.target +BindsTo=graphical-session.target +Description=sway compositor session +Documentation=man:systemd.special(7) +Wants=graphical-session-pre.target 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 44077d44..b4091267 100644 --- a/tests/modules/services/window-managers/sway/sway-no-xwayland.nix +++ b/tests/modules/services/window-managers/sway/sway-no-xwayland.nix @@ -7,7 +7,7 @@ enable = true; package = config.lib.test.mkStubPackage { outPath = "@sway@"; }; config = null; - systemdIntegration = false; + systemd.enable = false; xwayland = false; }; 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 0c0d1e7b..a859e04e 100644 --- a/tests/modules/services/window-managers/sway/sway-null-config.nix +++ b/tests/modules/services/window-managers/sway/sway-null-config.nix @@ -7,7 +7,7 @@ enable = true; package = config.lib.test.mkStubPackage { outPath = "@sway@"; }; config = null; - systemdIntegration = false; + systemd.enable = false; }; nmt.script = '' diff --git a/tests/modules/services/window-managers/sway/sway-systemd-autostart.nix b/tests/modules/services/window-managers/sway/sway-systemd-autostart.nix new file mode 100644 index 00000000..5a1d90e2 --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-systemd-autostart.nix @@ -0,0 +1,20 @@ +{ config, lib, pkgs, ... }: + +{ + imports = [ ./sway-stubs.nix ]; + + wayland.windowManager.sway = { + enable = true; + package = config.lib.test.mkStubPackage { outPath = "@sway@"; }; + # overriding findutils causes issues + config.menu = "${pkgs.dmenu}/bin/dmenu_run"; + + systemd.xdgAutostart = true; + }; + + nmt.script = '' + assertFileExists home-files/.config/systemd/user/sway-session.target + assertFileContent home-files/.config/systemd/user/sway-session.target \ + ${./sway-systemd-autostart.target} + ''; +} diff --git a/tests/modules/services/window-managers/sway/sway-systemd-autostart.target b/tests/modules/services/window-managers/sway/sway-systemd-autostart.target new file mode 100644 index 00000000..201f0ac6 --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-systemd-autostart.target @@ -0,0 +1,8 @@ +[Unit] +After=graphical-session-pre.target +Before=xdg-desktop-autostart.target +BindsTo=graphical-session.target +Description=sway compositor session +Documentation=man:systemd.special(7) +Wants=graphical-session-pre.target +Wants=xdg-desktop-autostart.target