losurdo: zfs: fix load-key
[sourcephile-nix.git] / nixos / profiles / services / nginx.nix
index 9cbfedb6b49ae9addfd5587ab78a2ad29923403e..5e15a3ba7419d8cfdb61b27c6081bd8c8b5a5f5f 100644 (file)
@@ -1,4 +1,4 @@
-{ inputs, pkgs, lib, config, ... }:
+{ inputs, pkgs, lib, config, host, ... }:
 let
   inherit (lib) types;
   inherit (config) networking;
@@ -24,13 +24,34 @@ systemd.tmpfiles.rules = [
   "d '/dev/shm/nginx' '750' '${nginx.user}' '${nginx.group}' - -"
 ];
 systemd.services.nginx = {
+  requires = [ "systemd-tmpfiles-setup-dev.service" ];
   serviceConfig = {
     # FIXME: remove all the mkForce in LogsDirectory
     # whenever upstream uses a list instead of a string.
     LogsDirectory = lib.mkForce ["nginx"];
     StateDirectory = ["nginx"];
     StateDirectoryMode = "2770";
-    BindPaths = ["/dev/shm/nginx:/var/cache/nginx"];
+    #BindPaths = ["/dev/shm/nginx:/var/cache/nginx"];
+  };
+};
+services.logrotate = {
+  enable = true;
+  paths.nginx = {
+    path = [
+      "/var/log/nginx/*.log"
+      "/var/log/nginx/*/*.log"
+      "/var/log/nginx/*/*/*.log"
+      "/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
+    '';
   };
 };
 services.nginx = {
@@ -85,29 +106,37 @@ services.nginx = {
     log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';
-
-    log_format json escape=json
-      '{'
-        '"time_local":"$time_local",'
-        '"remote_addr":"$remote_addr",'
-        '"status": "$status",'
-        '"request":"$request",'
-        '"body_bytes_sent":"$body_bytes_sent",'
-        '"http_referrer":"$http_referer",'
-        '"http_user_agent":"$http_user_agent",'
-        '"remote_user":"$remote_user",'
-        '"request_time":"$request_time"'
-      '}';
+    log_format json escape=json '{'
+      '"time_local":"$time_local",'
+      '"host":"$host",'
+      '"request":"$request",'
+      '"status":"$status",'
+      '"http_referrer":"$http_referer",'
+      '"remote_addr":"$remote_addr",'
+      '"remote_user":"$remote_user",'
+      '"msec":"$msec",'
+      '"body_bytes_sent":"$body_bytes_sent",'
+      '"bytes_sent":"$bytes_sent",'
+      '"http_user_agent":"$http_user_agent",'
+      '"request_length":"$request_length",'
+      '"request_method":"$request_method",'
+      '"request_time":"$request_time",'
+      '"request_uri":"$request_uri",'
+      '"server_protocol":"$server_protocol",'
+      '"ssl_protocol":"$ssl_protocol",'
+      '"upstream_addr":"$upstream_addr",'
+      '"upstream_connect_time":"$upstream_connect_time",'
+      '"upstream_response_time":"$upstream_response_time"'
+    '}';
     charset UTF-8;
     types {
       text/html html5;
-      text/plain md;
       text/plain dump;
     }
     '' +
     lib.concatStringsSep "\n" (lib.attrValues {
       default = ''
-        default_type application/octet-stream;
+        #default_type application/octet-stream;
         root /var/lib/nginx;
       '';
       security = ''
@@ -119,7 +148,7 @@ services.nginx = {
         #proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
       '';
       log = ''
-        access_log /var/log/nginx/access.log main buffer=32k;
+        access_log /var/log/nginx/access.json json;
         error_log  /var/log/nginx/error.log warn;
         open_log_file_cache max=1000 inactive=20s min_uses=2 valid=1m;
       '';
@@ -156,7 +185,6 @@ services.nginx = {
         tcp_nodelay on;
         keepalive_timeout 20;
         reset_timedout_connection on;
-        types_hash_max_size 4096;
         server_names_hash_bucket_size 128;
       '';
       map = ''
@@ -202,7 +230,7 @@ services.nginx = {
       '';
     });
   appendConfig = ''
-    worker_processes ${toString config.nix.maxJobs};
+    worker_processes ${toString host.CPUs};
   '';
 };
 };