1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-01 08:49:44 +01:00
home-manager/modules/services/swayosd.nix
Donovan Glover 465ea1f994
swayosd: avoid restarting too quickly
Should fix an issue where swayosd.service would stop without starting
again after restarting too quickly.

Triggered by ending a Hyprland session and logging in with tuigreet.

Related: https://github.com/nix-community/home-manager/pull/4316
2024-07-24 07:37:28 +02:00

83 lines
2.2 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.swayosd;
in {
meta.maintainers = [ hm.maintainers.pltanton ];
options.services.swayosd = {
enable = mkEnableOption ''
swayosd, a GTK based on screen display for keyboard shortcuts like
caps-lock and volume'';
package = mkPackageOption pkgs "swayosd" { };
topMargin = mkOption {
type = types.nullOr (types.addCheck types.float (f: f >= 0.0 && f <= 1.0)
// {
description = "float between 0.0 and 1.0 (inclusive)";
});
default = null;
example = 1.0;
description = "OSD margin from top edge (0.5 would be screen center).";
};
stylePath = mkOption {
type = types.nullOr types.path;
default = null;
example = "/etc/xdg/swayosd/style.css";
description = ''
Use a custom Stylesheet file instead of looking for one.
'';
};
display = mkOption {
type = types.nullOr types.str;
default = null;
example = "eDP-1";
description = ''
X display to use.
'';
};
};
config = mkIf cfg.enable {
assertions = [
(hm.assertions.assertPlatform "services.swayosd" pkgs platforms.linux)
];
home.packages = [ cfg.package ];
systemd.user = {
services.swayosd = {
Unit = {
Description = "Volume/backlight OSD indicator";
PartOf = [ "graphical-session.target" ];
After = [ "graphical-session.target" ];
ConditionEnvironment = "WAYLAND_DISPLAY";
Documentation = "man:swayosd(1)";
StartLimitBurst = 5;
StartLimitIntervalSec = 10;
};
Service = {
Type = "simple";
ExecStart = "${cfg.package}/bin/swayosd-server"
+ (optionalString (cfg.display != null) " --display ${cfg.display}")
+ (optionalString (cfg.stylePath != null)
" --style ${escapeShellArg cfg.stylePath}")
+ (optionalString (cfg.topMargin != null)
" --top-margin ${toString cfg.topMargin}");
Restart = "always";
RestartSec = "2s";
};
Install = { WantedBy = [ "graphical-session.target" ]; };
};
};
};
}