From e9c2c3d226720b54ab9846a76a36fd36677a1b6e Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Thu, 21 Jul 2022 09:54:00 +0800 Subject: [PATCH] services/yt-dlp: add job persistence --- modules/home-manager/services/yt-dlp.nix | 18 ++++++++++++++++-- modules/nixos/services/yt-dlp.nix | 22 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/modules/home-manager/services/yt-dlp.nix b/modules/home-manager/services/yt-dlp.nix index bda85ea6..bef1c6ec 100644 --- a/modules/home-manager/services/yt-dlp.nix +++ b/modules/home-manager/services/yt-dlp.nix @@ -23,7 +23,8 @@ let startAt = lib.mkOption { type = with lib.types; str; description = '' - Indicates how frequent the download will occur. The given schedule should follow the format as described from + Indicates how frequent the download will occur. The given schedule + should follow the format as described from systemd.time 5 @@ -33,6 +34,18 @@ let example = "*-*-3/4"; }; + persistent = lib.mkOption { + type = lib.types.bool; + description = '' + Indicates whether the service will start if timer has missed. + Defaults to true since this module mainly assumes + it is used on the desktop. + ''; + default = true; + defaultText = "true"; + example = "false"; + }; + extraArgs = lib.mkOption { type = with lib.types; listOf str; description = @@ -155,7 +168,8 @@ in { Timer = { OnCalendar = value.startAt; - Persistent = true; + RandomizedDelaySec = "2min"; + Persistent = value.persistent; }; Install.WantedBy = [ "timers.target" ]; diff --git a/modules/nixos/services/yt-dlp.nix b/modules/nixos/services/yt-dlp.nix index a56cf85b..39d84bd9 100644 --- a/modules/nixos/services/yt-dlp.nix +++ b/modules/nixos/services/yt-dlp.nix @@ -23,7 +23,8 @@ let startAt = lib.mkOption { type = with lib.types; str; description = '' - Indicates how frequent the download will occur. The given schedule should follow the format as described from + Indicates how frequent the download will occur. The given schedule + should follow the format as described from systemd.time 5 @@ -33,6 +34,17 @@ let example = "*-*-3/4"; }; + persistent = lib.mkOption { + type = lib.types.bool; + description = '' + Indicates whether the job should be persistent, starting the service + if missed. + ''; + default = false; + defaultText = "false"; + example = "true"; + }; + extraArgs = lib.mkOption { type = with lib.types; listOf str; description = @@ -145,5 +157,13 @@ in { SystemCallErrorNumber = "EPERM"; }; }) cfg.jobs; + + systemd.timers = lib.mapAttrs' (name: value: + lib.nameValuePair "yt-dlp-archive-service-${name}" { + timerConfig = { + Persistent = value.persistent; + RandomizedDelaySec = "2min"; + }; + }) cfg.jobs; }; }