summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--modules/module-list.nix1
-rw-r--r--modules/services/logging/logrotate.nix38
2 files changed, 39 insertions, 0 deletions
diff --git a/modules/module-list.nix b/modules/module-list.nix
index aa6c5347e88..fbea5e66fe6 100644
--- a/modules/module-list.nix
+++ b/modules/module-list.nix
@@ -53,6 +53,7 @@
   ./services/hardware/pcscd.nix
   ./services/hardware/udev.nix
   ./services/logging/klogd.nix
+  ./services/logging/logrotate.nix
   ./services/logging/syslogd.nix
   ./services/mail/dovecot.nix
   ./services/mail/postfix.nix
diff --git a/modules/services/logging/logrotate.nix b/modules/services/logging/logrotate.nix
new file mode 100644
index 00000000000..59091cc2473
--- /dev/null
+++ b/modules/services/logging/logrotate.nix
@@ -0,0 +1,38 @@
+{config, pkgs, ...}:
+
+with pkgs.lib;
+
+let
+  cfg = config.services.logrotate;
+
+  configFile = pkgs.writeText "logrotate.conf"
+    cfg.config;
+
+  cronJob = ''
+    5 * * * * ${pkgs.logrotate}/sbin/logrotate ${configFile}
+  '';
+
+in
+{
+  options = {
+    services.logrotate = {
+      enable = mkOption {
+        default = false;
+        description = ''
+          Enable the logrotate cron job
+        '';
+      };
+
+      config = mkOption {
+        default = "";
+        description = ''
+          The contents of the logrotate config file
+        '';
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    services.cron.systemCronJobs = [ cronJob ];
+  };
+}