From 9ca5b84e27db0f8d817d81af82f1ad49696d9c49 Mon Sep 17 00:00:00 2001 From: Florian Brandes Date: Wed, 17 Jul 2024 22:31:50 +0200 Subject: [PATCH 1/3] nixos/zabbixWeb: add nginx config Co-authored-by: Aaron Andersen Signed-off-by: Florian Brandes --- nixos/modules/services/web-apps/zabbix.nix | 140 +++++++++++++++------ 1 file changed, 100 insertions(+), 40 deletions(-) diff --git a/nixos/modules/services/web-apps/zabbix.nix b/nixos/modules/services/web-apps/zabbix.nix index 2455e676e583..cffec617c73f 100644 --- a/nixos/modules/services/web-apps/zabbix.nix +++ b/nixos/modules/services/web-apps/zabbix.nix @@ -2,8 +2,8 @@ let - inherit (lib) mkDefault mkEnableOption mkPackageOption mkForce mkIf mkMerge mkOption types; - inherit (lib) literalExpression mapAttrs optionalString versionAtLeast; + inherit (lib) mkDefault mkEnableOption mkPackageOption mkRenamedOptionModule mkForce mkIf mkMerge mkOption types; + inherit (lib) literalExpression mapAttrs optionalString optionals versionAtLeast; cfg = config.services.zabbixWeb; opt = options.services.zabbixWeb; @@ -36,6 +36,10 @@ let in { + imports = [ + (mkRenamedOptionModule + [ "services" "zabbixWeb" "virtualHost" ] [ "services" "zabbixWeb" "httpd" "virtualHost" ]) + ]; # interface options.services = { @@ -116,7 +120,17 @@ in }; }; - virtualHost = mkOption { + frontend = mkOption { + type = types.enum [ + "nginx" + "httpd" + ]; + example = "nginx"; + default = "httpd"; + description = "Frontend server to use."; + }; + + httpd.virtualHost = mkOption { type = types.submodule (import ../web-servers/apache-httpd/vhost-options.nix); example = literalExpression '' { @@ -126,12 +140,35 @@ in enableACME = true; } ''; + default = { }; description = '' Apache configuration can be done by adapting `services.httpd.virtualHosts.`. See [](#opt-services.httpd.virtualHosts) for further information. ''; }; + hostname = mkOption { + type = types.str; + default = "zabbix.local"; + description = "Hostname for either nginx or httpd."; + }; + + nginx.virtualHost = mkOption { + type = types.submodule (import ../web-servers/nginx/vhost-options.nix); + example = literalExpression '' + { + forceSSL = true; + sslCertificateKey = "/etc/ssl/zabbix.key"; + sslCertificate = "/etc/ssl/zabbix.crt"; + } + ''; + default = { }; + description = '' + Nginx configuration can be done by adapting `services.nginx.virtualHosts.`. + See [](#opt-services.nginx.virtualHosts) for further information. + ''; + }; + poolConfig = mkOption { type = with types; attrsOf (oneOf [ str int bool ]); default = { @@ -167,58 +204,81 @@ in ''; systemd.tmpfiles.rules = [ - "d '${stateDir}' 0750 ${user} ${group} - -" + "d '${stateDir}' 0750 ${user} ${group} - -" ] ++ optionals (cfg.frontend == "httpd") [ "d '${stateDir}/session' 0750 ${user} ${config.services.httpd.group} - -" + ] ++ optionals (cfg.frontend == "nginx") [ + "d '${stateDir}/session' 0750 ${user} ${config.services.nginx.group} - -" ]; services.phpfpm.pools.zabbix = { inherit user; - group = config.services.httpd.group; - phpOptions = '' - # https://www.zabbix.com/documentation/current/manual/installation/install - memory_limit = 128M - post_max_size = 16M - upload_max_filesize = 2M - max_execution_time = 300 - max_input_time = 300 - session.auto_start = 0 - mbstring.func_overload = 0 - always_populate_raw_post_data = -1 - # https://bbs.archlinux.org/viewtopic.php?pid=1745214#p1745214 - session.save_path = ${stateDir}/session - '' + optionalString (config.time.timeZone != null) '' - date.timezone = "${config.time.timeZone}" - '' + optionalString (cfg.database.type == "oracle") '' - extension=${pkgs.phpPackages.oci8}/lib/php/extensions/oci8.so - ''; + group = config.services.${cfg.frontend}.group; + phpOptions = + '' + # https://www.zabbix.com/documentation/current/manual/installation/install + memory_limit = 128M + post_max_size = 16M + upload_max_filesize = 2M + max_execution_time = 300 + max_input_time = 300 + session.auto_start = 0 + mbstring.func_overload = 0 + always_populate_raw_post_data = -1 + # https://bbs.archlinux.org/viewtopic.php?pid=1745214#p1745214 + session.save_path = ${stateDir}/session + '' + optionalString (config.time.timeZone != null) '' + date.timezone = "${config.time.timeZone}" + '' + optionalString (cfg.database.type == "oracle") '' + extension=${pkgs.phpPackages.oci8}/lib/php/extensions/oci8.so + ''; phpEnv.ZABBIX_CONFIG = "${zabbixConfig}"; settings = { - "listen.owner" = config.services.httpd.user; - "listen.group" = config.services.httpd.group; + "listen.owner" = if cfg.frontend == "httpd" then config.services.httpd.user else config.services.nginx.user; + "listen.group" = if cfg.frontend == "httpd" then config.services.httpd.group else config.services.nginx.group; } // cfg.poolConfig; }; - services.httpd = { + services.httpd = mkIf (cfg.frontend == "httpd") { enable = true; - adminAddr = mkDefault cfg.virtualHost.adminAddr; + adminAddr = mkDefault cfg.httpd.virtualHost.adminAddr; extraModules = [ "proxy_fcgi" ]; - virtualHosts.${cfg.virtualHost.hostName} = mkMerge [ cfg.virtualHost { - documentRoot = mkForce "${cfg.package}/share/zabbix"; - extraConfig = '' - - - - SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/" - - - AllowOverride all - Options -Indexes - DirectoryIndex index.php - - ''; + virtualHosts.${cfg.hostname} = mkMerge [ + cfg.httpd.virtualHost + { + documentRoot = mkForce "${cfg.package}/share/zabbix"; + extraConfig = '' + + + + SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/" + + + AllowOverride all + Options -Indexes + DirectoryIndex index.php + + ''; } ]; }; + services.nginx = mkIf (cfg.frontend == "nginx") { + enable = true; + virtualHosts.${cfg.hostname} = mkMerge [ + cfg.nginx.virtualHost + { + root = mkForce "${cfg.package}/share/zabbix"; + locations."/" = { + index = "index.html index.htm index.php"; + tryFiles = "$uri $uri/ =404"; + }; + locations."~ \.php$".extraConfig = '' + fastcgi_pass unix:${fpm.socket}; + fastcgi_index index.php; + ''; + } + ]; + }; + users.users.${user} = mapAttrs (name: mkDefault) { description = "Zabbix daemon user"; uid = config.ids.uids.zabbix; From 7d3b77d66f63084df00eec1a33b05046d8c18aa6 Mon Sep 17 00:00:00 2001 From: Florian Brandes Date: Wed, 17 Jul 2024 22:16:32 +0200 Subject: [PATCH 2/3] nixos/zabbixWeb: format Signed-off-by: Florian Brandes --- nixos/modules/services/web-apps/zabbix.nix | 162 +++++++++++++++------ 1 file changed, 115 insertions(+), 47 deletions(-) diff --git a/nixos/modules/services/web-apps/zabbix.nix b/nixos/modules/services/web-apps/zabbix.nix index cffec617c73f..3463148b30e0 100644 --- a/nixos/modules/services/web-apps/zabbix.nix +++ b/nixos/modules/services/web-apps/zabbix.nix @@ -1,9 +1,31 @@ -{ config, lib, options, pkgs, ... }: +{ + config, + lib, + options, + pkgs, + ... +}: let - inherit (lib) mkDefault mkEnableOption mkPackageOption mkRenamedOptionModule mkForce mkIf mkMerge mkOption types; - inherit (lib) literalExpression mapAttrs optionalString optionals versionAtLeast; + inherit (lib) + mkDefault + mkEnableOption + mkPackageOption + mkRenamedOptionModule + mkForce + mkIf + mkMerge + mkOption + types + ; + inherit (lib) + literalExpression + mapAttrs + optionalString + optionals + versionAtLeast + ; cfg = config.services.zabbixWeb; opt = options.services.zabbixWeb; @@ -17,13 +39,25 @@ let ''; - } ]; + } + ]; }; services.nginx = mkIf (cfg.frontend == "nginx") { @@ -266,17 +337,17 @@ in virtualHosts.${cfg.hostname} = mkMerge [ cfg.nginx.virtualHost { - root = mkForce "${cfg.package}/share/zabbix"; - locations."/" = { - index = "index.html index.htm index.php"; - tryFiles = "$uri $uri/ =404"; - }; - locations."~ \.php$".extraConfig = '' - fastcgi_pass unix:${fpm.socket}; - fastcgi_index index.php; - ''; - } - ]; + root = mkForce "${cfg.package}/share/zabbix"; + locations."/" = { + index = "index.html index.htm index.php"; + tryFiles = "$uri $uri/ =404"; + }; + locations."~ \.php$".extraConfig = '' + fastcgi_pass unix:${fpm.socket}; + fastcgi_index index.php; + ''; + } + ]; }; users.users.${user} = mapAttrs (name: mkDefault) { @@ -285,9 +356,6 @@ in inherit group; }; - users.groups.${group} = mapAttrs (name: mkDefault) { - gid = config.ids.gids.zabbix; - }; - + users.groups.${group} = mapAttrs (name: mkDefault) { gid = config.ids.gids.zabbix; }; }; } From bb8a4831e5576dc822ea4fcde849497dc0e8b025 Mon Sep 17 00:00:00 2001 From: Florian Brandes Date: Wed, 17 Jul 2024 22:32:33 +0200 Subject: [PATCH 3/3] zabbix: add version 6.4 Signed-off-by: Florian Brandes --- pkgs/servers/monitoring/zabbix/versions.nix | 5 +++++ pkgs/top-level/all-packages.nix | 1 + 2 files changed, 6 insertions(+) diff --git a/pkgs/servers/monitoring/zabbix/versions.nix b/pkgs/servers/monitoring/zabbix/versions.nix index 6fe89a17c357..5761d64e8c81 100644 --- a/pkgs/servers/monitoring/zabbix/versions.nix +++ b/pkgs/servers/monitoring/zabbix/versions.nix @@ -1,4 +1,9 @@ generic: { + v64 = generic { + version = "6.4.15"; + hash = "sha256-CtmNCuzDVchijinWcop3lGUTVGS2JbiQCbmusyXBQvY="; + vendorHash = null; + }; v60 = generic { version = "6.0.26"; hash = "sha256-MIOKe5hqfDecB1oWZKzbFmJCsQLuAGtp21l2WxxVG+g="; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 88755a012dab..6ce2c27462cc 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -26716,6 +26716,7 @@ with pkgs; }; zabbix60 = recurseIntoAttrs (zabbixFor "v60"); + zabbix64 = recurseIntoAttrs (zabbixFor "v64"); zabbix50 = recurseIntoAttrs (zabbixFor "v50"); zabbix = zabbix60;