Skip to content

Commit

Permalink
treewide: standardize wayland graphical services
Browse files Browse the repository at this point in the history
  • Loading branch information
rycee committed Jan 3, 2025
2 parents 1c8d4c8 + 14cb0c8 commit ef64efd
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 52 deletions.
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ let
./systemd.nix
./targets/darwin
./targets/generic-linux.nix
./wayland.nix
./xresources.nix
./xsession.nix
./misc/nix.nix
Expand Down
8 changes: 5 additions & 3 deletions modules/programs/waybar.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions modules/services/avizo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
};
Expand All @@ -69,7 +69,7 @@ in {
Restart = "always";
};

Install = { WantedBy = [ "graphical-session.target" ]; };
Install = { WantedBy = [ config.wayland.systemd.target ]; };
};
};
};
Expand Down
8 changes: 5 additions & 3 deletions modules/services/clipman.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions modules/services/dunst.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
5 changes: 3 additions & 2 deletions modules/services/fnott.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions modules/services/hypridle.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}" ];
};
Expand Down
6 changes: 3 additions & 3 deletions modules/services/hyprpaper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}" ];
};
Expand Down
4 changes: 3 additions & 1 deletion modules/services/kanshi.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
'';
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions modules/services/swayidle.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions modules/services/swaync.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};

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

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

Install = { WantedBy = [ "graphical-session.target" ]; };
Install = { WantedBy = [ config.wayland.systemd.target ]; };
};
};
};
Expand Down
6 changes: 3 additions & 3 deletions modules/services/wob.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,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 = [ config.wayland.systemd.target ];
After = [ config.wayland.systemd.target ];
ConditionEnvironment = "WAYLAND_DISPLAY";
};
Service = {
StandardInput = "socket";
ExecStart = builtins.concatStringsSep " " ([ (getExe cfg.package) ]
++ optional (cfg.settings != { }) "--config ${configFile}");
};
Install.WantedBy = [ "graphical-session.target" ];
Install.WantedBy = [ config.wayland.systemd.target ];
};

sockets.wob = {
Expand Down
24 changes: 24 additions & 0 deletions modules/wayland.nix
Original file line number Diff line number Diff line change
@@ -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.
'';
};
};
};
}
4 changes: 1 addition & 3 deletions tests/modules/programs/waybar/deprecated-modules-option.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{ config, lib, pkgs, ... }:

with lib;
{ config, ... }:

{
config = {
Expand Down
4 changes: 1 addition & 3 deletions tests/modules/programs/waybar/settings-complex.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{ config, lib, pkgs, ... }:

with lib;
{ config, ... }:

{
config = {
Expand Down
2 changes: 0 additions & 2 deletions tests/modules/programs/waybar/settings-with-attrs.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{ config, lib, pkgs, ... }:

with lib;

{
config = {
home.stateVersion = "21.11";
Expand Down
4 changes: 1 addition & 3 deletions tests/modules/programs/waybar/styling.nix
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
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit ef64efd

Please sign in to comment.