Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treewide: standardize Wayland graphical services #6239

5 changes: 3 additions & 2 deletions modules/programs/waybar.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 16 additions & 3 deletions modules/services/avizo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)";
};
Expand All @@ -69,7 +82,7 @@ in {
Restart = "always";
};

Install = { WantedBy = [ "graphical-session.target" ]; };
Install = { WantedBy = [ cfg.systemd.target ]; };
};
};
};
Expand Down
19 changes: 17 additions & 2 deletions modules/services/dunst.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
'';
};
};
};

Expand Down Expand Up @@ -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 = {
Expand Down
17 changes: 15 additions & 2 deletions modules/services/hypridle.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}" ];
};
Expand Down
19 changes: 16 additions & 3 deletions modules/services/hyprpaper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}" ];
};
Expand Down
1 change: 1 addition & 0 deletions modules/services/kanshi.nix
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ in {

systemd.user.services.kanshi = {
Unit = {
ConditionEnvironment = "WAYLAND_DISPLAY";
Description = "Dynamic output configuration";
Documentation = "man:kanshi(1)";
PartOf = cfg.systemdTarget;
Expand Down
3 changes: 2 additions & 1 deletion modules/services/swayidle.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
19 changes: 16 additions & 3 deletions modules/services/swaync.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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";
};

Expand All @@ -107,7 +120,7 @@ in {
Restart = "on-failure";
};

Install.WantedBy = [ "graphical-session.target" ];
Install.WantedBy = [ cfg.systemd.target ];
};
};
}
19 changes: 16 additions & 3 deletions modules/services/swayosd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -76,7 +89,7 @@ in {
RestartSec = "2s";
};

Install = { WantedBy = [ "graphical-session.target" ]; };
Install = { WantedBy = [ cfg.systemd.target ]; };
};
};
};
Expand Down
19 changes: 16 additions & 3 deletions modules/services/wob.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ in {

systemd = mkEnableOption "systemd service and socket for wob"
// mkOption { default = true; };

systemdTarget = mkOption {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

systemd is sadly already used to enable the service above, so using systemdTarget instead to avoid breaking changes.

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 {
Expand All @@ -50,16 +63,16 @@ 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 = {
StandardInput = "socket";
ExecStart = builtins.concatStringsSep " " ([ (getExe cfg.package) ]
++ optional (cfg.settings != { }) "--config ${configFile}");
};
Install.WantedBy = [ "graphical-session.target" ];
Install.WantedBy = [ cfg.systemdTarget ];
};

sockets.wob = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{ config, lib, pkgs, ... }:

with lib;
{ config, ... }:

{
config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion tests/modules/services/swayidle/basic-configuration.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }:
{ config, ... }:

{
services.swayidle = {
Expand Down Expand Up @@ -50,6 +50,7 @@
Type=simple

[Unit]
After=graphical-session.target
ConditionEnvironment=WAYLAND_DISPLAY
Description=Idle manager for Wayland
Documentation=man:swayidle(1)
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/services/swaync/swaync.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading