summary refs log tree commit diff
path: root/nixos/modules/services
diff options
context:
space:
mode:
authorJanne Heß <janne@hess.ooo>2022-02-23 11:24:17 +0100
committerGitHub <noreply@github.com>2022-02-23 11:24:17 +0100
commite5823f77b3c8c4058bcea9634156769635f8b61e (patch)
tree5797cb6c02cd88b22a644e37443f1c4635ac120d /nixos/modules/services
parent14780ccf6a68cd4178c21e0a3dfed63ddd9b020a (diff)
parenta05f1c9f9357d3c3c39b99a5aa020399ee28bb99 (diff)
downloadnixpkgs-e5823f77b3c8c4058bcea9634156769635f8b61e.tar
nixpkgs-e5823f77b3c8c4058bcea9634156769635f8b61e.tar.gz
nixpkgs-e5823f77b3c8c4058bcea9634156769635f8b61e.tar.bz2
nixpkgs-e5823f77b3c8c4058bcea9634156769635f8b61e.tar.lz
nixpkgs-e5823f77b3c8c4058bcea9634156769635f8b61e.tar.xz
nixpkgs-e5823f77b3c8c4058bcea9634156769635f8b61e.tar.zst
nixpkgs-e5823f77b3c8c4058bcea9634156769635f8b61e.zip
Merge pull request #159187 from martinetd/logrotate
logrotate service enhancements
Diffstat (limited to 'nixos/modules/services')
-rw-r--r--nixos/modules/services/logging/logrotate.nix35
-rw-r--r--nixos/modules/services/web-servers/nginx/default.nix12
2 files changed, 21 insertions, 26 deletions
diff --git a/nixos/modules/services/logging/logrotate.nix b/nixos/modules/services/logging/logrotate.nix
index 8cef4e8c083..77e4fc39598 100644
--- a/nixos/modules/services/logging/logrotate.nix
+++ b/nixos/modules/services/logging/logrotate.nix
@@ -4,7 +4,6 @@ with lib;
 
 let
   cfg = config.services.logrotate;
-  inherit (config.users) groups;
 
   pathOpts = { name, ... }:  {
     options = {
@@ -85,10 +84,6 @@ let
     };
 
     config.name = name;
-    config.extraConfig = ''
-      missingok
-      notifempty
-    '';
   };
 
   mkConf = pathOpts: ''
@@ -102,7 +97,11 @@ let
   '';
 
   paths = sortProperties (attrValues (filterAttrs (_: pathOpts: pathOpts.enable) cfg.paths));
-  configFile = pkgs.writeText "logrotate.conf" (concatStringsSep "\n" ((map mkConf paths) ++ [ cfg.extraConfig ]));
+  configFile = pkgs.writeText "logrotate.conf" (
+    concatStringsSep "\n" (
+      [ "missingok" "notifempty" cfg.extraConfig ] ++ (map mkConf paths)
+    )
+  );
 
 in
 {
@@ -112,7 +111,10 @@ in
 
   options = {
     services.logrotate = {
-      enable = mkEnableOption "the logrotate systemd service";
+      enable = mkEnableOption "the logrotate systemd service" // {
+        default = foldr (n: a: a || n.enable) false (attrValues cfg.paths);
+        defaultText = literalExpression "cfg.paths != {}";
+      };
 
       paths = mkOption {
         type = with types; attrsOf (submodule pathOpts);
@@ -163,25 +165,6 @@ 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" ];
diff --git a/nixos/modules/services/web-servers/nginx/default.nix b/nixos/modules/services/web-servers/nginx/default.nix
index 6876dbf39d8..7daf0f158b3 100644
--- a/nixos/modules/services/web-servers/nginx/default.nix
+++ b/nixos/modules/services/web-servers/nginx/default.nix
@@ -988,5 +988,17 @@ in
       nginx.gid = config.ids.gids.nginx;
     };
 
+    services.logrotate.paths.nginx = mapAttrs (_: mkDefault) {
+      path = "/var/log/nginx/*.log";
+      frequency = "weekly";
+      keep = 26;
+      extraConfig = ''
+        compress
+        delaycompress
+        postrotate
+          [ ! -f /var/run/nginx/nginx.pid ] || kill -USR1 `cat /var/run/nginx/nginx.pid`
+        endscript
+      '';
+    };
   };
 }