Merge pull request #87702 from jslight90/logrotate
nixos/logrotate: Add options for basic paths
This commit is contained in:
commit
646667831f
1 changed files with 69 additions and 10 deletions
|
@ -5,26 +5,85 @@ with lib;
|
||||||
let
|
let
|
||||||
cfg = config.services.logrotate;
|
cfg = config.services.logrotate;
|
||||||
|
|
||||||
configFile = pkgs.writeText "logrotate.conf"
|
pathOptions = {
|
||||||
cfg.config;
|
options = {
|
||||||
|
path = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "The path to log files to be rotated";
|
||||||
|
};
|
||||||
|
user = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "The user account to use for rotation";
|
||||||
|
};
|
||||||
|
group = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "The group to use for rotation";
|
||||||
|
};
|
||||||
|
frequency = mkOption {
|
||||||
|
type = types.enum [
|
||||||
|
"daily" "weekly" "monthly" "yearly"
|
||||||
|
];
|
||||||
|
default = "daily";
|
||||||
|
description = "How often to rotate the logs";
|
||||||
|
};
|
||||||
|
keep = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
default = 20;
|
||||||
|
description = "How many rotations to keep";
|
||||||
|
};
|
||||||
|
extraConfig = mkOption {
|
||||||
|
type = types.lines;
|
||||||
|
default = "";
|
||||||
|
description = "Extra logrotate config options for this path";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
pathConfig = options: ''
|
||||||
|
"${options.path}" {
|
||||||
|
su ${options.user} ${options.group}
|
||||||
|
${options.frequency}
|
||||||
|
missingok
|
||||||
|
notifempty
|
||||||
|
rotate ${toString options.keep}
|
||||||
|
${options.extraConfig}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
|
||||||
|
configFile = pkgs.writeText "logrotate.conf" (
|
||||||
|
(concatStringsSep "\n" ((map pathConfig cfg.paths) ++ [cfg.extraConfig]))
|
||||||
|
);
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
imports = [
|
||||||
|
(mkRenamedOptionModule [ "services" "logrotate" "config" ] [ "services" "logrotate" "extraConfig" ])
|
||||||
|
];
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
services.logrotate = {
|
services.logrotate = {
|
||||||
enable = mkOption {
|
enable = mkEnableOption "the logrotate systemd service";
|
||||||
type = lib.types.bool;
|
|
||||||
default = false;
|
paths = mkOption {
|
||||||
description = ''
|
type = types.listOf (types.submodule pathOptions);
|
||||||
Enable the logrotate cron job
|
default = [];
|
||||||
'';
|
description = "List of attribute sets with paths to rotate";
|
||||||
|
example = {
|
||||||
|
"/var/log/myapp/*.log" = {
|
||||||
|
user = "myuser";
|
||||||
|
group = "mygroup";
|
||||||
|
rotate = "weekly";
|
||||||
|
keep = 5;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkOption {
|
extraConfig = mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
description = ''
|
description = ''
|
||||||
The contents of the logrotate config file
|
Extra contents to add to the logrotate config file.
|
||||||
|
See https://linux.die.net/man/8/logrotate
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue