From c9cc7c0a7ebaaf9209a35ed6835001e8b258d301 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Fri, 3 Jan 2025 18:52:15 +0000 Subject: [PATCH] home-manager/desktop: init systemd.service --- modules/home-manager/desktop/default.nix | 19 +++++++++++++++++++ modules/home-manager/desktop/theme/fonts.nix | 4 +--- .../desktop/wayland/kanshi/default.nix | 6 +----- .../home-manager/desktop/wayland/swayidle.nix | 6 +----- .../home-manager/desktop/wayland/waybar.nix | 6 +----- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/modules/home-manager/desktop/default.nix b/modules/home-manager/desktop/default.nix index 038ef12e..02fe4578 100644 --- a/modules/home-manager/desktop/default.nix +++ b/modules/home-manager/desktop/default.nix @@ -29,6 +29,25 @@ in enable = lib.mkEnableOption "desktop config" // { default = osConfig.nixos.desktop.enable or false; }; + systemd.service = { + # Use exponential restart + # https://enotty.pipebreaker.pl/posts/2024/01/how-systemd-exponential-restart-delay-works/ + RestartSec = lib.mkOption { + type = lib.types.str; + description = "How long to wait between restarts."; + default = "250ms"; + }; + RestartSteps = lib.mkOption { + type = lib.types.int; + description = "Number of steps to take to increase the interval of auto-restarts."; + default = 5; + }; + RestartMaxDelaySec = lib.mkOption { + type = lib.types.str; + description = "Longest time to sleep before restarting a service as the interval goes up."; + default = "5s"; + }; + }; default = { browser = lib.mkOption { type = lib.types.str; diff --git a/modules/home-manager/desktop/theme/fonts.nix b/modules/home-manager/desktop/theme/fonts.nix index 856e2d62..a413a2f0 100644 --- a/modules/home-manager/desktop/theme/fonts.nix +++ b/modules/home-manager/desktop/theme/fonts.nix @@ -157,9 +157,7 @@ in systemd.user.services.xsettingsd = { Service = { - # Exponential restart - RestartSteps = 5; - RestartMaxDelaySec = 10; + inherit (config.home-manager.desktop.systemd.service) RestartSec RestartSteps RestartMaxDelaySec; Restart = lib.mkForce "on-failure"; }; }; diff --git a/modules/home-manager/desktop/wayland/kanshi/default.nix b/modules/home-manager/desktop/wayland/kanshi/default.nix index 11e6c9bf..afd3cb16 100644 --- a/modules/home-manager/desktop/wayland/kanshi/default.nix +++ b/modules/home-manager/desktop/wayland/kanshi/default.nix @@ -22,11 +22,7 @@ in systemd.user.services.kanshi = { Service = { - # Use exponential restart - # https://enotty.pipebreaker.pl/posts/2024/01/how-systemd-exponential-restart-delay-works/ - RestartSec = "250ms"; - RestartSteps = 5; - RestartMaxDelaySec = 5; + inherit (config.home-manager.desktop.systemd.service) RestartSec RestartSteps RestartMaxDelaySec; }; }; }; diff --git a/modules/home-manager/desktop/wayland/swayidle.nix b/modules/home-manager/desktop/wayland/swayidle.nix index 5ad00e39..a0d33179 100644 --- a/modules/home-manager/desktop/wayland/swayidle.nix +++ b/modules/home-manager/desktop/wayland/swayidle.nix @@ -76,13 +76,9 @@ in ]; }; - # Add some time before restart, to avoid the following error: - # swayidle.service: Start request repeated too quickly. systemd.user.services.swayidle = { Service = { - # Use exponential restart - RestartSteps = 5; - RestartMaxDelaySec = 10; + inherit (config.home-manager.desktop.systemd.service) RestartSec RestartSteps RestartMaxDelaySec; }; }; }; diff --git a/modules/home-manager/desktop/wayland/waybar.nix b/modules/home-manager/desktop/wayland/waybar.nix index 7a290d55..47f87990 100644 --- a/modules/home-manager/desktop/wayland/waybar.nix +++ b/modules/home-manager/desktop/wayland/waybar.nix @@ -420,11 +420,7 @@ in systemd.user.services.waybar = { Service = { - # Use exponential restart - # https://enotty.pipebreaker.pl/posts/2024/01/how-systemd-exponential-restart-delay-works/ - RestartSec = "250ms"; - RestartSteps = 5; - RestartMaxDelaySec = 5; + inherit (config.home-manager.desktop.systemd.service) RestartSec RestartSteps RestartMaxDelaySec; }; }; };