diff options
author | Julien Moutinho <julm+nixpkgs@sourcephile.fr> | 2021-12-26 12:41:43 +0100 |
---|---|---|
committer | Julien Moutinho <julm+nixpkgs@sourcephile.fr> | 2021-12-28 21:23:46 +0100 |
commit | c2fd94a61cbcf7133dc3e6f8d915c172062865c2 (patch) | |
tree | a05a70d6200651b97a36d84d2a487b294cc13009 /nixos/modules/services/logging | |
parent | aa13f192a6e6c4e86c2e474fc2443254c9e29dfe (diff) | |
download | nixpkgs-c2fd94a61cbcf7133dc3e6f8d915c172062865c2.tar nixpkgs-c2fd94a61cbcf7133dc3e6f8d915c172062865c2.tar.gz nixpkgs-c2fd94a61cbcf7133dc3e6f8d915c172062865c2.tar.bz2 nixpkgs-c2fd94a61cbcf7133dc3e6f8d915c172062865c2.tar.lz nixpkgs-c2fd94a61cbcf7133dc3e6f8d915c172062865c2.tar.xz nixpkgs-c2fd94a61cbcf7133dc3e6f8d915c172062865c2.tar.zst nixpkgs-c2fd94a61cbcf7133dc3e6f8d915c172062865c2.zip |
nixos/logrotate: enable multiple paths per entry
Diffstat (limited to 'nixos/modules/services/logging')
-rw-r--r-- | nixos/modules/services/logging/logrotate.nix | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/nixos/modules/services/logging/logrotate.nix b/nixos/modules/services/logging/logrotate.nix index ba5d6e29d0b..3467cdf5abf 100644 --- a/nixos/modules/services/logging/logrotate.nix +++ b/nixos/modules/services/logging/logrotate.nix @@ -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}"; }; }; }; |