diff --git a/modules/programs/waybar.nix b/modules/programs/waybar.nix index 8150223c1489..110c8f247bc0 100644 --- a/modules/programs/waybar.nix +++ b/modules/programs/waybar.nix @@ -309,8 +309,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 1bf1c1e680e4..569e2bd88966 100644 --- a/modules/services/avizo.nix +++ b/modules/services/avizo.nix @@ -41,6 +41,19 @@ in { ''; description = "The `avizo` package to use."; }; + + systemd.target = mkOption { + type = types.str; + default = "graphical-session.target"; + example = "sway-session.target"; + description = '' + The systemd target that will automatically start the Waybar service. + + 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. + ''; + }; }; config = mkIf cfg.enable { @@ -57,8 +70,8 @@ in { services.avizo = { Unit = { Description = "Volume/backlight OSD indicator"; - PartOf = [ "graphical-session.target" ]; - After = [ "graphical-session.target" ]; + PartOf = [ cfg.systemd.target ]; + After = [ cfg.systemd.target ]; ConditionEnvironment = "WAYLAND_DISPLAY"; Documentation = "man:avizo(1)"; }; @@ -69,7 +82,7 @@ in { Restart = "always"; }; - Install = { WantedBy = [ "graphical-session.target" ]; }; + Install = { WantedBy = [ cfg.systemd.target ]; }; }; }; }; diff --git a/modules/services/dunst.nix b/modules/services/dunst.nix index 6b2727b3fee2..0e5126d7f3f1 100644 --- a/modules/services/dunst.nix +++ b/modules/services/dunst.nix @@ -124,6 +124,19 @@ in { }; ''; }; + + systemd.target = mkOption { + type = types.str; + default = "graphical-session.target"; + example = "sway-session.target"; + description = '' + The systemd target that will automatically start the Waybar service. + + 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. + ''; + }; }; }; @@ -180,8 +193,10 @@ in { systemd.user.services.dunst = { Unit = { Description = "Dunst notification daemon"; - After = [ "graphical-session-pre.target" ]; - PartOf = [ "graphical-session.target" ]; + PartOf = [ cfg.systemd.target ]; + After = [ cfg.systemd.target ]; + ConditionEnvironment = + lib.mkIf (cfg.waylandDisplay != "") "WAYLAND_DISPLAY"; }; Service = { diff --git a/modules/services/hypridle.nix b/modules/services/hypridle.nix index 0d8a337b43db..f42b45984e8e 100644 --- a/modules/services/hypridle.nix +++ b/modules/services/hypridle.nix @@ -63,6 +63,19 @@ in { List of prefix of attributes to source at the top of the config. ''; }; + + systemd.target = mkOption { + type = types.str; + default = "graphical-session.target"; + example = "sway-session.target"; + description = '' + The systemd target that will automatically start the Waybar service. + + 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. + ''; + }; }; config = mkIf cfg.enable { @@ -79,8 +92,8 @@ in { Unit = { ConditionEnvironment = "WAYLAND_DISPLAY"; Description = "hypridle"; - After = [ "graphical-session-pre.target" ]; - PartOf = [ "graphical-session.target" ]; + After = [ cfg.systemd.target ]; + PartOf = [ cfg.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 6c9ddb2cfa07..91e92f493012 100644 --- a/modules/services/hyprpaper.nix +++ b/modules/services/hyprpaper.nix @@ -57,6 +57,19 @@ in { List of prefix of attributes to source at the top of the config. ''; }; + + systemd.target = mkOption { + type = types.str; + default = "graphical-session.target"; + example = "sway-session.target"; + description = '' + The systemd target that will automatically start the Waybar service. + + 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. + ''; + }; }; config = mkIf cfg.enable { @@ -68,13 +81,13 @@ in { }; systemd.user.services.hyprpaper = { - Install = { WantedBy = [ "graphical-session.target" ]; }; + Install = { WantedBy = [ cfg.systemd.target ]; }; Unit = { ConditionEnvironment = "WAYLAND_DISPLAY"; Description = "hyprpaper"; - After = [ "graphical-session-pre.target" ]; - PartOf = [ "graphical-session.target" ]; + PartOf = [ cfg.systemd.target ]; + After = [ cfg.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 808966282f5f..989b48eafbe2 100644 --- a/modules/services/kanshi.nix +++ b/modules/services/kanshi.nix @@ -340,6 +340,7 @@ in { systemd.user.services.kanshi = { Unit = { + ConditionEnvironment = "WAYLAND_DISPLAY"; Description = "Dynamic output configuration"; Documentation = "man:kanshi(1)"; PartOf = cfg.systemdTarget; diff --git a/modules/services/swayidle.nix b/modules/services/swayidle.nix index 7f3376a1ce42..e6b3775e421a 100644 --- a/modules/services/swayidle.nix +++ b/modules/services/swayidle.nix @@ -107,7 +107,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 5f813af30ab6..18ae2cf15505 100644 --- a/modules/services/swaync.nix +++ b/modules/services/swaync.nix @@ -73,6 +73,19 @@ in { for the documentation. ''; }; + + 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 Waybar service. + + 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. + ''; + }; }; config = lib.mkIf cfg.enable { @@ -95,8 +108,8 @@ in { Unit = { Description = "Swaync notification daemon"; Documentation = "https://github.com/ErikReider/SwayNotificationCenter"; - PartOf = [ "graphical-session.target" ]; - After = [ "graphical-session-pre.target" ]; + PartOf = [ cfg.systemd.target ]; + After = [ cfg.systemd.target ]; ConditionEnvironment = "WAYLAND_DISPLAY"; }; @@ -107,7 +120,7 @@ in { Restart = "on-failure"; }; - Install.WantedBy = [ "graphical-session.target" ]; + Install.WantedBy = [ cfg.systemd.target ]; }; }; } diff --git a/modules/services/swayosd.nix b/modules/services/swayosd.nix index 869b48729364..896310ce88e3 100644 --- a/modules/services/swayosd.nix +++ b/modules/services/swayosd.nix @@ -43,6 +43,19 @@ in { X display to use. ''; }; + + systemd.target = mkOption { + type = types.str; + default = "graphical-session.target"; + example = "sway-session.target"; + description = '' + The systemd target that will automatically start the Waybar service. + + 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. + ''; + }; }; config = mkIf cfg.enable { @@ -56,8 +69,8 @@ in { services.swayosd = { Unit = { Description = "Volume/backlight OSD indicator"; - PartOf = [ "graphical-session.target" ]; - After = [ "graphical-session.target" ]; + PartOf = [ cfg.systemd.target ]; + After = [ cfg.systemd.target ]; ConditionEnvironment = "WAYLAND_DISPLAY"; Documentation = "man:swayosd(1)"; StartLimitBurst = 5; @@ -76,7 +89,7 @@ in { RestartSec = "2s"; }; - Install = { WantedBy = [ "graphical-session.target" ]; }; + Install = { WantedBy = [ cfg.systemd.target ]; }; }; }; }; diff --git a/modules/services/wob.nix b/modules/services/wob.nix index 8ca1befa84da..14f94c1c98ba 100644 --- a/modules/services/wob.nix +++ b/modules/services/wob.nix @@ -37,6 +37,19 @@ in { systemd = mkEnableOption "systemd service and socket for wob" // mkOption { default = true; }; + + systemdTarget = mkOption { + type = lib.types.str; + default = "graphical-session.target"; + example = "sway-session.target"; + description = '' + The systemd target that will automatically start the Waybar service. + + 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. + ''; + }; }; config = mkIf cfg.enable { @@ -50,8 +63,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 = [ cfg.systemdTarget ]; + After = [ cfg.systemdTarget ]; ConditionEnvironment = "WAYLAND_DISPLAY"; }; Service = { @@ -59,7 +72,7 @@ in { ExecStart = builtins.concatStringsSep " " ([ (getExe cfg.package) ] ++ optional (cfg.settings != { }) "--config ${configFile}"); }; - Install.WantedBy = [ "graphical-session.target" ]; + Install.WantedBy = [ cfg.systemdTarget ]; }; sockets.wob = { 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 dc7a620fab39..e9694e533c5c 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 c99c8c13ac17..f3e3b24a3c3d 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/swayidle/basic-configuration.nix b/tests/modules/services/swayidle/basic-configuration.nix index c38f4d67d86e..c863883bb445 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 ceb3bf065017..550e5fed4949 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