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 <contact@scrumplex.net>

* sway: add Scrumplex to maintainers

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>

---------

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2023-06-10 12:10:40 +02:00 committed by GitHub
parent 0945875a2a
commit 0144ac418e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 22 deletions

View file

@ -316,7 +316,7 @@ let
++ map workspaceOutputStr workspaceOutputAssign # custom mapping ++ map workspaceOutputStr workspaceOutputAssign # custom mapping
) )
else 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"'') 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 ])); ++ (optional (!cfg.xwayland) "xwayland disable") ++ [ cfg.extraConfig ]));
@ -328,7 +328,19 @@ let
}; };
in { 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 = { options.wayland.windowManager.sway = {
enable = mkEnableOption "sway wayland compositor"; enable = mkEnableOption "sway wayland compositor";
@ -346,22 +358,32 @@ in {
''; '';
}; };
systemdIntegration = mkOption { systemd = {
type = types.bool; enable = mkOption {
default = pkgs.stdenv.isLinux; type = types.bool;
example = false; default = pkgs.stdenv.isLinux;
description = '' example = false;
Whether to enable <filename>sway-session.target</filename> on description = ''
sway startup. This links to Whether to enable <filename>sway-session.target</filename> on
<filename>graphical-session.target</filename>. sway startup. This links to
Some important environment variables will be imported to systemd <filename>graphical-session.target</filename>.
and dbus user environment before reaching the target, including Some important environment variables will be imported to systemd
<itemizedlist> and dbus user environment before reaching the target, including
<listitem><para><literal>DISPLAY</literal></para></listitem> <itemizedlist>
<listitem><para><literal>WAYLAND_DISPLAY</literal></para></listitem> <listitem><para><literal>DISPLAY</literal></para></listitem>
<listitem><para><literal>SWAYSOCK</literal></para></listitem> <listitem><para><literal>WAYLAND_DISPLAY</literal></para></listitem>
<listitem><para><literal>XDG_CURRENT_DESKTOP</literal></para></listitem> <listitem><para><literal>SWAYSOCK</literal></para></listitem>
</itemizedlist> <listitem><para><literal>XDG_CURRENT_DESKTOP</literal></para></listitem>
</itemizedlist>
'';
};
xdgAutostart = mkEnableOption ''
autostart of applications using
<citerefentry>
<refentrytitle>systemd-xdg-autostart-generator</refentrytitle>
<manvolnum>8</manvolnum>
</citerefentry>
''; '';
}; };
@ -469,13 +491,16 @@ in {
''; '';
}; };
systemd.user.targets.sway-session = mkIf cfg.systemdIntegration { systemd.user.targets.sway-session = mkIf cfg.systemd.enable {
Unit = { Unit = {
Description = "sway compositor session"; Description = "sway compositor session";
Documentation = [ "man:systemd.special(7)" ]; Documentation = [ "man:systemd.special(7)" ];
BindsTo = [ "graphical-session.target" ]; 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" ]; After = [ "graphical-session-pre.target" ];
Before =
optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target";
}; };
}; };

View file

@ -10,6 +10,7 @@
sway-null-config = ./sway-null-config.nix; sway-null-config = ./sway-null-config.nix;
sway-null-package = ./sway-null-package.nix; sway-null-package = ./sway-null-package.nix;
sway-post-2003 = ./sway-post-2003.nix; sway-post-2003 = ./sway-post-2003.nix;
sway-systemd-autostart = ./sway-systemd-autostart.nix;
sway-workspace-default = ./sway-workspace-default.nix; sway-workspace-default = ./sway-workspace-default.nix;
sway-workspace-output = ./sway-workspace-output.nix; sway-workspace-output = ./sway-workspace-output.nix;
swaynag-example-settings = ./swaynag-example-settings.nix; swaynag-example-settings = ./swaynag-example-settings.nix;

View file

@ -14,5 +14,9 @@
assertFileExists home-files/.config/sway/config assertFileExists home-files/.config/sway/config
assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \
${./sway-default.conf} ${./sway-default.conf}
assertFileExists home-files/.config/systemd/user/sway-session.target
assertFileContent home-files/.config/systemd/user/sway-session.target \
${./sway-default.target}
''; '';
} }

View file

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

View file

@ -7,7 +7,7 @@
enable = true; enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; }; package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
config = null; config = null;
systemdIntegration = false; systemd.enable = false;
xwayland = false; xwayland = false;
}; };

View file

@ -7,7 +7,7 @@
enable = true; enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; }; package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
config = null; config = null;
systemdIntegration = false; systemd.enable = false;
}; };
nmt.script = '' nmt.script = ''

View file

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

View file

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