Commit c2fd94a6 authored by Julien Moutinho's avatar Julien Moutinho
Browse files

nixos/logrotate: enable multiple paths per entry

parent aa13f192
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ with lib;
let
  cfg = config.services.logrotate;

  pathOpts = {
  pathOpts = { name, ... }:  {
    options = {
      enable = mkOption {
        type = types.bool;
@@ -16,10 +16,17 @@ let
        '';
      };

      path = mkOption {
      name = mkOption {
        type = types.str;
        internal = true;
      };

      path = mkOption {
        type = with types; either str (listOf str);
        description = ''
          The path to log files to be rotated.
          Spaces are allowed and normal shell quoting rules apply,
          with ', ", and \ characters supported.
        '';
      };

@@ -74,6 +81,7 @@ let
      };
    };

    config.name = name;
    config.extraConfig = ''
      missingok
      notifempty
@@ -82,7 +90,7 @@ let

  mkConf = pathOpts: ''
    # generated by NixOS using the `services.logrotate.paths.${pathOpts.name}` attribute set
    "${pathOpts.path}" {
    ${concatMapStringsSep " " (path: ''"${path}"'') (toList pathOpts.path)} {
      ${optionalString (pathOpts.user != null || pathOpts.group != null) "su ${pathOpts.user} ${pathOpts.group}"}
      ${pathOpts.frequency}
      rotate ${toString pathOpts.keep}
@@ -90,7 +98,7 @@ let
    }
  '';

  paths = sortProperties (mapAttrsToList (name: pathOpts: pathOpts // { name = name; }) (filterAttrs (_: pathOpts: pathOpts.enable) cfg.paths));
  paths = sortProperties (attrValues (filterAttrs (_: pathOpts: pathOpts.enable) cfg.paths));
  configFile = pkgs.writeText "logrotate.conf" (concatStringsSep "\n" ((map mkConf paths) ++ [ cfg.extraConfig ]));

in
@@ -156,13 +164,11 @@ in
      description = "Logrotate Service";
      wantedBy = [ "multi-user.target" ];
      startAt = "hourly";
      script = ''
        exec ${pkgs.logrotate}/sbin/logrotate ${configFile}
      '';

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