diff options
author | Alyssa Ross <hi@alyssa.is> | 2022-02-22 10:43:06 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2022-03-11 16:17:56 +0000 |
commit | ca1aada113c0ebda1ab8667199f6453f8e01c4fc (patch) | |
tree | 55e402280096f62eb0bc8bcad5ce6050c5a0aec7 /nixpkgs/nixos/modules/services/logging/logrotate.nix | |
parent | e4df5a52a6a6531f32626f57205356a773ac2975 (diff) | |
parent | 93883402a445ad467320925a0a5dbe43a949f25b (diff) | |
download | nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar.gz nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar.bz2 nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar.lz nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar.xz nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.tar.zst nixlib-ca1aada113c0ebda1ab8667199f6453f8e01c4fc.zip |
Merge commit '93883402a445ad467320925a0a5dbe43a949f25b'
Conflicts: nixpkgs/nixos/modules/programs/ssh.nix nixpkgs/pkgs/applications/networking/browsers/firefox/packages.nix nixpkgs/pkgs/data/fonts/noto-fonts/default.nix nixpkgs/pkgs/development/go-modules/generic/default.nix nixpkgs/pkgs/development/interpreters/ruby/default.nix nixpkgs/pkgs/development/libraries/mesa/default.nix
Diffstat (limited to 'nixpkgs/nixos/modules/services/logging/logrotate.nix')
-rw-r--r-- | nixpkgs/nixos/modules/services/logging/logrotate.nix | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/nixpkgs/nixos/modules/services/logging/logrotate.nix b/nixpkgs/nixos/modules/services/logging/logrotate.nix index ba5d6e29d0bd..8cef4e8c083a 100644 --- a/nixpkgs/nixos/modules/services/logging/logrotate.nix +++ b/nixpkgs/nixos/modules/services/logging/logrotate.nix @@ -4,8 +4,9 @@ with lib; let cfg = config.services.logrotate; + inherit (config.users) groups; - pathOpts = { + pathOpts = { name, ... }: { options = { enable = mkOption { type = types.bool; @@ -16,10 +17,19 @@ let ''; }; - path = mkOption { + name = mkOption { type = types.str; + internal = true; + }; + + path = mkOption { + type = with types; either str (listOf str); + default = name; + defaultText = "attribute name"; description = '' The path to log files to be rotated. + Spaces are allowed and normal shell quoting rules apply, + with ', ", and \ characters supported. ''; }; @@ -74,6 +84,7 @@ let }; }; + config.name = name; config.extraConfig = '' missingok notifempty @@ -82,7 +93,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 +101,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 @@ -152,17 +163,34 @@ in } ) cfg.paths; + services.logrotate = { + paths = { + "/var/log/btmp" = { + frequency = mkDefault "monthly"; + keep = mkDefault 1; + extraConfig = '' + create 0660 root ${groups.utmp.name} + ''; + }; + "/var/log/wtmp" = { + frequency = mkDefault "monthly"; + keep = mkDefault 1; + extraConfig = '' + create 0664 root ${groups.utmp.name} + ''; + }; + }; + }; + systemd.services.logrotate = { 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}"; }; }; }; |