1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.logrotate;
7
8 configFile = pkgs.writeText "logrotate.conf"
9 cfg.config;
10
11in
12{
13 options = {
14 services.logrotate = {
15 enable = mkOption {
16 default = false;
17 description = ''
18 Enable the logrotate cron job
19 '';
20 };
21
22 config = mkOption {
23 default = "";
24 type = types.lines;
25 description = ''
26 The contents of the logrotate config file
27 '';
28 };
29 };
30 };
31
32 config = mkIf cfg.enable {
33 systemd.services.logrotate = {
34 description = "Logrotate Service";
35 wantedBy = [ "multi-user.target" ];
36 startAt = "*-*-* *:05:00";
37
38 serviceConfig.Restart = "no";
39 serviceConfig.User = "root";
40 script = ''
41 exec ${pkgs.logrotate}/sbin/logrotate ${configFile}
42 '';
43 };
44 };
45}