From 0734cfab07a90a34bb91428e24646e5fe78d9e24 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 09:54:37 +0000 Subject: [PATCH 01/12] wayland: add module --- modules/modules.nix | 1 + modules/wayland.nix | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 modules/wayland.nix diff --git a/modules/modules.nix b/modules/modules.nix index c5a81b42..3c422eb5 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -417,6 +417,7 @@ let ./systemd.nix ./targets/darwin ./targets/generic-linux.nix + ./wayland.nix ./xresources.nix ./xsession.nix ./misc/nix.nix diff --git a/modules/wayland.nix b/modules/wayland.nix new file mode 100644 index 00000000..9a485c56 --- /dev/null +++ b/modules/wayland.nix @@ -0,0 +1,24 @@ +{ lib, ... }: + +{ + meta.maintainers = [ lib.maintainers.thiagokokada ]; + + options = { + wayland = { + systemd.target = lib.mkOption { + type = lib.types.str; + default = "graphical-session.target"; + example = "sway-session.target"; + description = '' + The systemd target that will automatically start the graphical Wayland services. + This option is a generalization of individual `systemd.target` or `systemdTarget`, + and affect all Wayland services by default. + + When setting this value to `"sway-session.target"`, + make sure to also enable {option}`wayland.windowManager.sway.systemd.enable`, + otherwise the service may never be started. + ''; + }; + }; + }; +} From 89fe48b1c1c51d5616343b71822a45f894b16dcf Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 09:57:06 +0000 Subject: [PATCH 02/12] swayidle: use config.wayland.systemd.target Also add `Unit.After`. --- modules/services/swayidle.nix | 6 ++++-- tests/modules/services/swayidle/basic-configuration.nix | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/services/swayidle.nix b/modules/services/swayidle.nix index 7f3376a1..fbb91db5 100644 --- a/modules/services/swayidle.nix +++ b/modules/services/swayidle.nix @@ -88,7 +88,8 @@ in { systemdTarget = mkOption { type = types.str; - default = "graphical-session.target"; + default = config.wayland.systemd.target; + defaultText = literalExpression "config.wayland.systemd.target"; example = "sway-session.target"; description = '' Systemd target to bind to. @@ -107,7 +108,8 @@ in { Description = "Idle manager for Wayland"; Documentation = "man:swayidle(1)"; ConditionEnvironment = "WAYLAND_DISPLAY"; - PartOf = [ "graphical-session.target" ]; + PartOf = [ cfg.systemdTarget ]; + After = [ cfg.systemdTarget ]; }; Service = { diff --git a/tests/modules/services/swayidle/basic-configuration.nix b/tests/modules/services/swayidle/basic-configuration.nix index c38f4d67..c863883b 100644 --- a/tests/modules/services/swayidle/basic-configuration.nix +++ b/tests/modules/services/swayidle/basic-configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, ... }: +{ config, ... }: { services.swayidle = { @@ -50,6 +50,7 @@ Type=simple [Unit] + After=graphical-session.target ConditionEnvironment=WAYLAND_DISPLAY Description=Idle manager for Wayland Documentation=man:swayidle(1) From 8587c2ff0ea82a93a265dbcbad7df88c80de1b9c Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 10:00:57 +0000 Subject: [PATCH 03/12] waybar: use config.wayland.systemd.target Also add `ConditionEnvironment`. --- modules/programs/waybar.nix | 8 +++++--- .../modules/programs/waybar/deprecated-modules-option.nix | 4 +--- tests/modules/programs/waybar/settings-complex.nix | 4 +--- tests/modules/programs/waybar/settings-with-attrs.nix | 2 -- tests/modules/programs/waybar/styling.nix | 4 +--- .../waybar/systemd-with-graphical-session-target.nix | 4 +--- .../waybar/systemd-with-graphical-session-target.service | 5 +++-- 7 files changed, 12 insertions(+), 19 deletions(-) diff --git a/modules/programs/waybar.nix b/modules/programs/waybar.nix index 8150223c..dbbe89c3 100644 --- a/modules/programs/waybar.nix +++ b/modules/programs/waybar.nix @@ -199,7 +199,8 @@ in { systemd.target = mkOption { type = str; - default = "graphical-session.target"; + default = config.wayland.systemd.target; + defaultText = literalExpression "config.wayland.systemd.target"; example = "sway-session.target"; description = '' The systemd target that will automatically start the Waybar service. @@ -309,8 +310,9 @@ in { Description = "Highly customizable Wayland bar for Sway and Wlroots based compositors."; Documentation = "https://github.com/Alexays/Waybar/wiki"; - PartOf = [ "graphical-session.target" ]; - After = [ "graphical-session-pre.target" ]; + PartOf = [ cfg.systemd.target ]; + After = [ cfg.systemd.target ]; + ConditionEnvironment = "WAYLAND_DISPLAY"; X-Restart-Triggers = optional (settings != [ ]) "${config.xdg.configFile."waybar/config".source}" ++ optional (cfg.style != null) diff --git a/tests/modules/programs/waybar/deprecated-modules-option.nix b/tests/modules/programs/waybar/deprecated-modules-option.nix index 09f163b0..2c677aac 100644 --- a/tests/modules/programs/waybar/deprecated-modules-option.nix +++ b/tests/modules/programs/waybar/deprecated-modules-option.nix @@ -1,6 +1,4 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ config, ... }: { config = { diff --git a/tests/modules/programs/waybar/settings-complex.nix b/tests/modules/programs/waybar/settings-complex.nix index 2e205a7d..a5413193 100644 --- a/tests/modules/programs/waybar/settings-complex.nix +++ b/tests/modules/programs/waybar/settings-complex.nix @@ -1,6 +1,4 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ config, ... }: { config = { diff --git a/tests/modules/programs/waybar/settings-with-attrs.nix b/tests/modules/programs/waybar/settings-with-attrs.nix index ac7e20fa..992e42c6 100644 --- a/tests/modules/programs/waybar/settings-with-attrs.nix +++ b/tests/modules/programs/waybar/settings-with-attrs.nix @@ -1,7 +1,5 @@ { config, lib, pkgs, ... }: -with lib; - { config = { home.stateVersion = "21.11"; diff --git a/tests/modules/programs/waybar/styling.nix b/tests/modules/programs/waybar/styling.nix index 1952c4fb..0025acd5 100644 --- a/tests/modules/programs/waybar/styling.nix +++ b/tests/modules/programs/waybar/styling.nix @@ -1,6 +1,4 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ config, ... }: { config = { diff --git a/tests/modules/programs/waybar/systemd-with-graphical-session-target.nix b/tests/modules/programs/waybar/systemd-with-graphical-session-target.nix index dc7a620f..e9694e53 100644 --- a/tests/modules/programs/waybar/systemd-with-graphical-session-target.nix +++ b/tests/modules/programs/waybar/systemd-with-graphical-session-target.nix @@ -1,6 +1,4 @@ -{ config, lib, pkgs, ... }: - -with lib; +{ config, ... }: { config = { diff --git a/tests/modules/programs/waybar/systemd-with-graphical-session-target.service b/tests/modules/programs/waybar/systemd-with-graphical-session-target.service index c99c8c13..f3e3b24a 100644 --- a/tests/modules/programs/waybar/systemd-with-graphical-session-target.service +++ b/tests/modules/programs/waybar/systemd-with-graphical-session-target.service @@ -8,7 +8,8 @@ KillMode=mixed Restart=on-failure [Unit] -After=graphical-session-pre.target +After=sway-session.target +ConditionEnvironment=WAYLAND_DISPLAY Description=Highly customizable Wayland bar for Sway and Wlroots based compositors. Documentation=https://github.com/Alexays/Waybar/wiki -PartOf=graphical-session.target +PartOf=sway-session.target From d3c500a8f8f88587c0867ba13ae6dba6e3c58cec Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 10:01:57 +0000 Subject: [PATCH 04/12] kanshi: use config.wayland.systemd.target Also add `ConditionEnvironment`. --- modules/services/kanshi.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/services/kanshi.nix b/modules/services/kanshi.nix index 80896628..45394498 100644 --- a/modules/services/kanshi.nix +++ b/modules/services/kanshi.nix @@ -286,7 +286,8 @@ in { systemdTarget = mkOption { type = types.str; - default = "sway-session.target"; + default = config.wayland.systemd.target; + defaultText = literalExpression "config.wayland.systemd.target"; description = '' Systemd target to bind to. ''; @@ -342,6 +343,7 @@ in { Unit = { Description = "Dynamic output configuration"; Documentation = "man:kanshi(1)"; + ConditionEnvironment = "WAYLAND_DISPLAY"; PartOf = cfg.systemdTarget; Requires = cfg.systemdTarget; After = cfg.systemdTarget; From 4cbc8a58ab94e5eea5fe3185837d6489579a7f68 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 10:04:04 +0000 Subject: [PATCH 05/12] swaync: use config.wayland.systemd.target --- modules/services/swaync.nix | 6 +++--- tests/modules/services/swaync/swaync.nix | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/services/swaync.nix b/modules/services/swaync.nix index 5f813af3..b8bb912b 100644 --- a/modules/services/swaync.nix +++ b/modules/services/swaync.nix @@ -95,8 +95,8 @@ in { Unit = { Description = "Swaync notification daemon"; Documentation = "https://github.com/ErikReider/SwayNotificationCenter"; - PartOf = [ "graphical-session.target" ]; - After = [ "graphical-session-pre.target" ]; + PartOf = [ config.wayland.systemd.target ]; + After = [ config.wayland.systemd.target ]; ConditionEnvironment = "WAYLAND_DISPLAY"; }; @@ -107,7 +107,7 @@ in { Restart = "on-failure"; }; - Install.WantedBy = [ "graphical-session.target" ]; + Install.WantedBy = [ config.wayland.systemd.target ]; }; }; } diff --git a/tests/modules/services/swaync/swaync.nix b/tests/modules/services/swaync/swaync.nix index ceb3bf06..550e5fed 100644 --- a/tests/modules/services/swaync/swaync.nix +++ b/tests/modules/services/swaync/swaync.nix @@ -24,7 +24,7 @@ Type=dbus [Unit] - After=graphical-session-pre.target + After=graphical-session.target ConditionEnvironment=WAYLAND_DISPLAY Description=Swaync notification daemon Documentation=https://github.com/ErikReider/SwayNotificationCenter From 51ba4aacec867a1ecc2b92bf5ecdc66dbf9eb6c2 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 10:04:57 +0000 Subject: [PATCH 06/12] swayosd: use config.wayland.systemd.target --- modules/services/swayosd.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/services/swayosd.nix b/modules/services/swayosd.nix index 869b4872..f0eb1cf2 100644 --- a/modules/services/swayosd.nix +++ b/modules/services/swayosd.nix @@ -56,8 +56,8 @@ in { services.swayosd = { Unit = { Description = "Volume/backlight OSD indicator"; - PartOf = [ "graphical-session.target" ]; - After = [ "graphical-session.target" ]; + PartOf = [ config.wayland.systemd.target ]; + After = [ config.wayland.systemd.target ]; ConditionEnvironment = "WAYLAND_DISPLAY"; Documentation = "man:swayosd(1)"; StartLimitBurst = 5; @@ -76,7 +76,7 @@ in { RestartSec = "2s"; }; - Install = { WantedBy = [ "graphical-session.target" ]; }; + Install = { WantedBy = [ config.wayland.systemd.target ]; }; }; }; }; From adcf0b6281f4d8c00ea263c49f52a71130ee875f Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 10:11:34 +0000 Subject: [PATCH 07/12] wob: use config.wayland.systemd.target --- modules/services/dunst.nix | 4 ++-- modules/services/wob.nix | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/services/dunst.nix b/modules/services/dunst.nix index 6b2727b3..696783c1 100644 --- a/modules/services/dunst.nix +++ b/modules/services/dunst.nix @@ -180,8 +180,8 @@ in { systemd.user.services.dunst = { Unit = { Description = "Dunst notification daemon"; - After = [ "graphical-session-pre.target" ]; - PartOf = [ "graphical-session.target" ]; + After = [ config.wayland.systemd.target ]; + PartOf = [ config.wayland.systemd.target ]; }; Service = { diff --git a/modules/services/wob.nix b/modules/services/wob.nix index 8ca1befa..d36565a0 100644 --- a/modules/services/wob.nix +++ b/modules/services/wob.nix @@ -50,8 +50,8 @@ in { Description = "A lightweight overlay volume/backlight/progress/anything bar for Wayland"; Documentation = "man:wob(1)"; - PartOf = "graphical-session.target"; - After = "graphical-session.target"; + PartOf = [ config.wayland.systemd.target ]; + After = [ config.wayland.systemd.target ]; ConditionEnvironment = "WAYLAND_DISPLAY"; }; Service = { @@ -59,7 +59,7 @@ in { ExecStart = builtins.concatStringsSep " " ([ (getExe cfg.package) ] ++ optional (cfg.settings != { }) "--config ${configFile}"); }; - Install.WantedBy = [ "graphical-session.target" ]; + Install.WantedBy = [ config.wayland.systemd.target ]; }; sockets.wob = { From 8f48fea0f8a8392f4b81da07333342824fdb35c9 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 10:12:21 +0000 Subject: [PATCH 08/12] avizo: use config.wayland.systemd.target --- modules/services/avizo.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/services/avizo.nix b/modules/services/avizo.nix index 1bf1c1e6..4efefaa1 100644 --- a/modules/services/avizo.nix +++ b/modules/services/avizo.nix @@ -57,8 +57,8 @@ in { services.avizo = { Unit = { Description = "Volume/backlight OSD indicator"; - PartOf = [ "graphical-session.target" ]; - After = [ "graphical-session.target" ]; + PartOf = [ config.wayland.systemd.target ]; + After = [ config.wayland.systemd.target ]; ConditionEnvironment = "WAYLAND_DISPLAY"; Documentation = "man:avizo(1)"; }; @@ -69,7 +69,7 @@ in { Restart = "always"; }; - Install = { WantedBy = [ "graphical-session.target" ]; }; + Install = { WantedBy = [ config.wayland.systemd.target ]; }; }; }; }; From da12f0b143558490efc52b7f550e19d9fcf27909 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 10:13:24 +0000 Subject: [PATCH 09/12] hyprpaper: use config.wayland.systemd.target --- modules/services/hyprpaper.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/services/hyprpaper.nix b/modules/services/hyprpaper.nix index 6c9ddb2c..39ff9a05 100644 --- a/modules/services/hyprpaper.nix +++ b/modules/services/hyprpaper.nix @@ -68,13 +68,13 @@ in { }; systemd.user.services.hyprpaper = { - Install = { WantedBy = [ "graphical-session.target" ]; }; + Install = { WantedBy = [ config.wayland.systemd.target ]; }; Unit = { ConditionEnvironment = "WAYLAND_DISPLAY"; Description = "hyprpaper"; - After = [ "graphical-session-pre.target" ]; - PartOf = [ "graphical-session.target" ]; + After = [ config.wayland.systemd.target ]; + PartOf = [ config.wayland.systemd.target ]; X-Restart-Triggers = mkIf (cfg.settings != { }) [ "${config.xdg.configFile."hypr/hyprpaper.conf".source}" ]; }; From a6db8c8f6c201df0cfb5482241368ac02a5b17f3 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 10:14:30 +0000 Subject: [PATCH 10/12] hypridle: use config.wayland.systemd.target --- modules/services/hypridle.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/services/hypridle.nix b/modules/services/hypridle.nix index 0d8a337b..c2165e5b 100644 --- a/modules/services/hypridle.nix +++ b/modules/services/hypridle.nix @@ -74,13 +74,13 @@ in { }; systemd.user.services.hypridle = { - Install = { WantedBy = [ "graphical-session.target" ]; }; + Install = { WantedBy = [ config.wayland.systemd.target ]; }; Unit = { ConditionEnvironment = "WAYLAND_DISPLAY"; Description = "hypridle"; - After = [ "graphical-session-pre.target" ]; - PartOf = [ "graphical-session.target" ]; + After = [ config.wayland.systemd.target ]; + PartOf = [ config.wayland.systemd.target ]; X-Restart-Triggers = mkIf (cfg.settings != { }) [ "${config.xdg.configFile."hypr/hypridle.conf".source}" ]; }; From 656ae5aba2d48adfe5bb3aa8d433b9a50cfb2a11 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 10:16:58 +0000 Subject: [PATCH 11/12] clipman: use config.wayland.systemd.target Also add `ConditionEnvironment`. --- modules/services/clipman.nix | 8 +++++--- .../services/clipman/clipman-sway-session-target.service | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/services/clipman.nix b/modules/services/clipman.nix index 4616c298..3a93773f 100644 --- a/modules/services/clipman.nix +++ b/modules/services/clipman.nix @@ -11,7 +11,8 @@ in { systemdTarget = mkOption { type = types.str; - default = "graphical-session.target"; + default = config.wayland.systemd.target; + defaultText = literalExpression "config.wayland.systemd.target"; example = "sway-session.target"; description = '' The systemd target that will automatically start the clipman service. @@ -34,8 +35,9 @@ in { systemd.user.services.clipman = { Unit = { Description = "Clipboard management daemon"; - PartOf = [ "graphical-session.target" ]; - After = [ "graphical-session.target" ]; + PartOf = [ cfg.systemdTarget ]; + After = [ cfg.systemdTarget ]; + ConditionEnvironment = "WAYLAND_DISPLAY"; }; Service = { diff --git a/tests/modules/services/clipman/clipman-sway-session-target.service b/tests/modules/services/clipman/clipman-sway-session-target.service index 0d0478cc..49de2ee3 100644 --- a/tests/modules/services/clipman/clipman-sway-session-target.service +++ b/tests/modules/services/clipman/clipman-sway-session-target.service @@ -8,6 +8,7 @@ KillMode=mixed Restart=on-failure [Unit] -After=graphical-session.target +After=sway-session.target +ConditionEnvironment=WAYLAND_DISPLAY Description=Clipboard management daemon -PartOf=graphical-session.target +PartOf=sway-session.target From 14cb0c8cfaa28d62a0e0cb4829e921635cd2b296 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 31 Dec 2024 10:27:09 +0000 Subject: [PATCH 12/12] fnott: use config.wayland.systemd.target Also add missing `ConditionEnvironment`. --- modules/services/fnott.nix | 5 +++-- .../services/fnott/systemd-user-service-expected.service | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/services/fnott.nix b/modules/services/fnott.nix index ecbd0fd1..e63cb571 100644 --- a/modules/services/fnott.nix +++ b/modules/services/fnott.nix @@ -88,8 +88,9 @@ in { Unit = { Description = "Fnott notification daemon"; Documentation = "man:fnott(1)"; - After = [ "graphical-session-pre.target" ]; - PartOf = [ "graphical-session.target" ]; + After = [ config.wayland.systemd.target ]; + PartOf = [ config.wayland.systemd.target ]; + ConditionEnvironment = "WAYLAND_DISPLAY"; }; Service = { diff --git a/tests/modules/services/fnott/systemd-user-service-expected.service b/tests/modules/services/fnott/systemd-user-service-expected.service index c39a7b19..f6546df4 100644 --- a/tests/modules/services/fnott/systemd-user-service-expected.service +++ b/tests/modules/services/fnott/systemd-user-service-expected.service @@ -4,7 +4,8 @@ ExecStart=@fnott@/bin/fnott -c /home/hm-user/.config/fnott/fnott.ini Type=dbus [Unit] -After=graphical-session-pre.target +After=graphical-session.target +ConditionEnvironment=WAYLAND_DISPLAY Description=Fnott notification daemon Documentation=man:fnott(1) PartOf=graphical-session.target