about summary refs log tree commit diff stats
path: root/modules/nixos
diff options
context:
space:
mode:
authorAlan Pearce2025-03-09 12:35:49 +0100
committerAlan Pearce2025-03-09 12:35:49 +0100
commit7d98b3c0cabcb5fd697225bda690b75542c93afe (patch)
treead4b678557dbcf1cf00ce309ddc039e3b0ee58d8 /modules/nixos
parent143ab69e6fd4adecd5a579d6fd79ca93980ad154 (diff)
downloadnix-packages-7d98b3c0cabcb5fd697225bda690b75542c93afe.tar.lz
nix-packages-7d98b3c0cabcb5fd697225bda690b75542c93afe.tar.zst
nix-packages-7d98b3c0cabcb5fd697225bda690b75542c93afe.zip
laminar: add support for declarative job timers
Diffstat (limited to 'modules/nixos')
-rw-r--r--modules/nixos/laminar.nix130
1 files changed, 99 insertions, 31 deletions
diff --git a/modules/nixos/laminar.nix b/modules/nixos/laminar.nix
index f20457d..3e50033 100644
--- a/modules/nixos/laminar.nix
+++ b/modules/nixos/laminar.nix
@@ -9,6 +9,7 @@ let
   inherit (lib)
     literalExpression
     optionalAttrs
+    mapAttrs'
     mkEnableOption
     mkPackageOption
     mkOption
@@ -53,6 +54,40 @@ in
       description = "Packages added to service PATH environment variable.";
     };
 
+    timers = mkOption {
+      default = { };
+
+      description = ''
+        Nightly jobs to run
+      '';
+
+      type = with types; attrsOf (submodule {
+        options = {
+          name = mkOption {
+            type = types.str;
+            default = name;
+            description = "Name of the timer.";
+          };
+
+          startAt = mkOption {
+            type = with types; either str (listOf str);
+            default = "daily";
+            description = ''
+              How often this job is started. See {manpage}`systemd.time(7)` for more information about the format.
+            '';
+          };
+
+          accuracy = mkOption {
+            type = types.str;
+            default = "10 min";
+            description = ''
+              How close to `startAt` time the job is actually run. See {manpage}`systemd.time(7)` for more information about the format.
+            '';
+          };
+        };
+      });
+    };
+
     settings = mkOption {
       default = { };
 
@@ -101,38 +136,71 @@ in
   };
 
   config = mkIf cfg.enable {
-    systemd.services.laminar = {
-      description = "Laminar continuous integration service";
-      wantedBy = [ "multi-user.target" ];
-      after = [ "network.target" ];
-      inherit (cfg) path;
-      environment = {
-        XDG_RUNTIME_DIR = "%t/laminar";
-      };
-      serviceConfig = {
-        User = cfg.user;
-        Group = cfg.group;
-        ExecStart = "${cfg.package}/bin/laminard -v";
-        RuntimeDirectory = "laminar";
-        EnvironmentFile = pkgs.writeText "laminar.conf" ''
-          LAMINAR_HOME=${cfg.homeDir}
-          LAMINAR_BIND_HTTP=${cfg.settings.bindHTTP}
-          LAMINAR_BIND_RPC=${cfg.settings.bindRPC}
-          LAMINAR_TITLE=${cfg.settings.title}
-          LAMINAR_KEEP_RUNDIRS=${toString cfg.settings.keepRundirs}
-          LAMINAR_BASE_URL=${cfg.settings.baseURL}
-          ${lib.optionalString (cfg.settings.archiveURL != null)
-            "LAMINAR_ARCHIVE_URL=${cfg.settings.archiveURL}"
-          }
-        '';
-      };
-      unitConfig = {
-        Documentation = [
-          "man:laminard(8)"
-          "https://laminar.ohwg.net/docs.html"
-        ];
+    systemd.services = {
+      laminar = {
+        description = "Laminar continuous integration service";
+        wantedBy = [ "multi-user.target" ];
+        after = [ "network.target" ];
+        inherit (cfg) path;
+        environment = {
+          XDG_RUNTIME_DIR = "%t/laminar";
+        };
+        serviceConfig = {
+          User = cfg.user;
+          Group = cfg.group;
+          ExecStart = "${cfg.package}/bin/laminard -v";
+          RuntimeDirectory = "laminar";
+          EnvironmentFile = pkgs.writeText "laminar.conf" ''
+            LAMINAR_HOME=${cfg.homeDir}
+            LAMINAR_BIND_HTTP=${cfg.settings.bindHTTP}
+            LAMINAR_BIND_RPC=${cfg.settings.bindRPC}
+            LAMINAR_TITLE=${cfg.settings.title}
+            LAMINAR_KEEP_RUNDIRS=${toString cfg.settings.keepRundirs}
+            LAMINAR_BASE_URL=${cfg.settings.baseURL}
+            ${lib.optionalString (cfg.settings.archiveURL != null)
+              "LAMINAR_ARCHIVE_URL=${cfg.settings.archiveURL}"
+            }
+          '';
+        };
+        unitConfig = {
+          Documentation = [
+            "man:laminard(8)"
+            "https://laminar.ohwg.net/docs.html"
+          ];
+        };
       };
-    };
+    } // (mapAttrs'
+      (name: job: {
+        name = "laminar-job-${name}";
+        value = {
+          description = "Runs laminar CI job.";
+          path = [
+            cfg.package
+            "/run/wrappers"
+          ]
+          ++ cfg.path;
+          serviceConfig = {
+            User = cfg.user;
+            Group = cfg.group;
+            Type = "oneshot";
+            ExecStart = "${cfg.package}/bin/laminarc run ${name}";
+          };
+        };
+      })
+      cfg.timers);
+    systemd.timers = (mapAttrs'
+      (name: job: {
+        name = "laminar-job-${name}";
+        value = {
+          wantedBy = [ "timers.target" ];
+          timerConfig = {
+            OnCalendar = job.startAt;
+            AccuracySec = job.accuracy;
+            Persistent = true;
+          };
+        };
+      })
+      cfg.timers);
 
     environment.systemPackages = [
       pkgs.laminar