1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-24 02:39:48 +01:00

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
)
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 <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>
systemd = {
enable = mkOption {
type = types.bool;
default = pkgs.stdenv.isLinux;
example = false;
description = ''
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>
'';
};
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 = {
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";
};
};

View file

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

View file

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

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;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
config = null;
systemdIntegration = false;
systemd.enable = false;
xwayland = false;
};

View file

@ -7,7 +7,7 @@
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
config = null;
systemdIntegration = false;
systemd.enable = false;
};
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