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 type = lib.types.bool;
17 default = false;
18 description = ''
19 Enable the logrotate cron job
20 '';
21 };
22
23 config = mkOption {
24 default = "";
25 type = types.lines;
26 description = ''
27 The contents of the logrotate config file
28 '';
29 };
30 };
31 };
32
33 config = mkIf cfg.enable {
34 systemd.services.logrotate = {
35 description = "Logrotate Service";
36 wantedBy = [ "multi-user.target" ];
37 startAt = "*-*-* *:05:00";
38
39 serviceConfig.Restart = "no";
40 serviceConfig.User = "root";
41 script = ''
42 exec ${pkgs.logrotate}/sbin/logrotate ${configFile}
43 '';
44 };
45 };
46}