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/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/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 ]; }; }; }; }; 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/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/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/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}" ]; }; 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}" ]; }; 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; 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/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/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 ]; }; }; }; }; 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 = { 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. + ''; + }; + }; + }; +} 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 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 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 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) 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