summary refs log tree commit diff
path: root/nixos/modules/services/logging/logrotate.nix
blob: fdd9f0f3e5c29a3d5105956801906c23e9573a7d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.logrotate;

  configFile = pkgs.writeText "logrotate.conf"
    cfg.config;

in
{
  options = {
    services.logrotate = {
      enable = mkOption {
        type = lib.types.bool;
        default = false;
        description = ''
          Enable the logrotate cron job
        '';
      };

      config = mkOption {
        default = "";
        type = types.lines;
        description = ''
          The contents of the logrotate config file
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.logrotate = {
      description   = "Logrotate Service";
      wantedBy      = [ "multi-user.target" ];
      startAt       = "*-*-* *:05:00";

      serviceConfig.Restart = "no";
      serviceConfig.User    = "root";
      script = ''
        exec ${pkgs.logrotate}/sbin/logrotate ${configFile}
      '';
    };
  };
}