Commit 13dc1efb3a9b

Vincent Demeester <vincent@sbr.pm>
2025-12-16 16:32:11
refactor(modules): Standardize timer scheduling across service modules
- Unify scheduling configuration for easier maintenance - Eliminate confusion with consistent interval+override pattern - Improve type safety using enum constraints over freeform strings Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent f7fed6a
modules/audible-sync.nix
@@ -52,22 +52,22 @@ in
       description = "Output format for converted audiobooks";
     };
 
-    schedule = mkOption {
-      type = types.str;
+    interval = mkOption {
+      type = types.enum [
+        "hourly"
+        "daily"
+        "weekly"
+        "monthly"
+      ];
       default = "daily";
-      description = "Systemd timer schedule (daily, weekly, etc.)";
-    };
-
-    time = mkOption {
-      type = types.str;
-      default = "03:00";
-      description = "Time of day to run sync (24-hour format)";
+      description = "How often to run the sync";
     };
 
     onCalendar = mkOption {
-      type = types.str;
-      default = "*-*-* 03:00:00";
-      description = "Full OnCalendar specification for systemd timer";
+      type = types.nullOr types.str;
+      default = null;
+      description = "Custom OnCalendar specification for systemd timer (overrides interval)";
+      example = "*-*-* 04:00:00";
     };
 
     notification = {
@@ -97,7 +97,19 @@ in
     systemd.timers.audible-sync = {
       wantedBy = [ "timers.target" ];
       timerConfig = {
-        OnCalendar = cfg.onCalendar;
+        OnCalendar =
+          if cfg.onCalendar != null then
+            cfg.onCalendar
+          else
+            (
+              {
+                hourly = "*-*-* *:00:00";
+                daily = "*-*-* 03:00:00";
+                weekly = "Sun *-*-* 03:00:00";
+                monthly = "*-*-01 03:00:00";
+              }
+              .${cfg.interval}
+            );
         Persistent = true;
         RandomizedDelaySec = "10m";
       };
modules/jellyfin-auto-collections.nix
@@ -72,12 +72,21 @@ in
     };
 
     interval = mkOption {
-      type = types.str;
+      type = types.enum [
+        "hourly"
+        "daily"
+        "weekly"
+        "monthly"
+      ];
       default = "daily";
-      description = ''
-        How often to run the collection update.
-        Uses systemd.time format (e.g., "hourly", "daily", "weekly", "*:0/30" for every 30 minutes).
-      '';
+      description = "How often to run the collection update";
+    };
+
+    onCalendar = mkOption {
+      type = types.nullOr types.str;
+      default = null;
+      description = "Custom OnCalendar specification for systemd timer (overrides interval)";
+      example = "*-*-* 04:00:00";
     };
 
     jellyfinUrl = mkOption {
@@ -225,7 +234,19 @@ in
       wantedBy = [ "timers.target" ];
 
       timerConfig = {
-        OnCalendar = cfg.interval;
+        OnCalendar =
+          if cfg.onCalendar != null then
+            cfg.onCalendar
+          else
+            (
+              {
+                hourly = "*-*-* *:00:00";
+                daily = "*-*-* 00:00:00";
+                weekly = "Sun *-*-* 00:00:00";
+                monthly = "*-*-01 00:00:00";
+              }
+              .${cfg.interval}
+            );
         Persistent = true;
         RandomizedDelaySec = "5m";
       };
systems/rhea/extra.nix
@@ -434,7 +434,7 @@ in
       tempDir = "/neo/audiobooks/zz_import"; # Keep AAX files for reuse
       quality = "best";
       format = "m4b";
-      onCalendar = "*-*-* 03:00:00"; # Daily at 3 AM
+      interval = "daily"; # Run daily at 3 AM
       notification = {
         enable = true;
         ntfyUrl = "https://ntfy.sbr.pm";
@@ -542,8 +542,7 @@ in
       user = "vincent";
       configFile = "/neo/music/music-playlist-dl.yaml";
       baseDir = "/neo/music";
-      interval = "weekly"; # Run weekly on Sundays
-      onCalendar = "Sun *-*-* 02:00:00"; # Sunday at 2 AM
+      interval = "weekly"; # Run weekly on Sundays at 2 AM
       notification = {
         enable = true;
         ntfyUrl = "https://ntfy.sbr.pm";