30 cfg = config.services.zabbixWeb;
31 opt = options.services.zabbixWeb;
32 fpm = config.services.phpfpm.pools.zabbix;
36 stateDir = "/var/lib/zabbix";
38 zabbixConfig = pkgs.writeText "zabbix.conf.php" ''
40 // Zabbix GUI configuration file.
50 $DB['SERVER'] = '${cfg.database.host}';
51 $DB['PORT'] = '${toString cfg.database.port}';
52 $DB['DATABASE'] = '${cfg.database.name}';
53 $DB['USER'] = '${cfg.database.user}';
54 # NOTE: file_get_contents adds newline at the end of returned string
56 if cfg.database.passwordFile != null then
57 "trim(file_get_contents('${cfg.database.passwordFile}'), \"\\r\\n\")"
61 // Schema name. Used for IBM DB2 and PostgreSQL.
63 $ZBX_SERVER = '${cfg.server.address}';
64 $ZBX_SERVER_PORT = '${toString cfg.server.port}';
65 $ZBX_SERVER_NAME = ''';
66 $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
73 (mkRenamedOptionModule
91 enable = mkEnableOption "the Zabbix web interface";
93 package = mkPackageOption pkgs [
101 description = "The port of the Zabbix server to connect to.";
107 description = "The IP address or hostname of the Zabbix server to connect to.";
108 default = "localhost";
121 description = "Database engine to use.";
127 description = "Database host address.";
133 if cfg.database.type == "mysql" then
134 config.services.mysql.port
135 else if cfg.database.type == "pgsql" then
136 config.services.postgresql.settings.port
139 defaultText = literalExpression ''
140 if config.${opt.database.type} == "mysql" then config.${options.services.mysql.port}
141 else if config.${opt.database.type} == "pgsql" then config.services.postgresql.settings.port
144 description = "Database host port.";
150 description = "Database name.";
156 description = "Database user.";
159 passwordFile = mkOption {
160 type = types.nullOr types.path;
162 example = "/run/keys/zabbix-dbpassword";
164 A file containing the password corresponding to
165 {option}`database.user`.
170 type = types.nullOr types.path;
172 example = "/run/postgresql";
173 description = "Path to the unix socket file to use for authentication.";
177 frontend = mkOption {
184 description = "Frontend server to use.";
187 httpd.virtualHost = mkOption {
188 type = types.submodule (import ../web-servers/apache-httpd/vhost-options.nix);
189 example = literalExpression ''
191 hostName = "zabbix.example.org";
192 adminAddr = "webmaster@example.org";
199 Apache configuration can be done by adapting `services.httpd.virtualHosts.<name>`.
200 See [](#opt-services.httpd.virtualHosts) for further information.
204 hostname = mkOption {
206 default = "zabbix.local";
207 description = "Hostname for either nginx or httpd.";
210 nginx.virtualHost = mkOption {
211 type = types.submodule (import ../web-servers/nginx/vhost-options.nix);
212 example = literalExpression ''
215 sslCertificateKey = "/etc/ssl/zabbix.key";
216 sslCertificate = "/etc/ssl/zabbix.crt";
221 Nginx configuration can be done by adapting `services.nginx.virtualHosts.<name>`.
222 See [](#opt-services.nginx.virtualHosts) for further information.
226 poolConfig = mkOption {
236 "pm.max_children" = 32;
237 "pm.start_servers" = 2;
238 "pm.min_spare_servers" = 2;
239 "pm.max_spare_servers" = 4;
240 "pm.max_requests" = 500;
243 Options for the Zabbix PHP pool. See the documentation on `php-fpm.conf` for details on configuration directives.
247 extraConfig = mkOption {
251 Additional configuration to be copied verbatim into {file}`zabbix.conf.php`.
259 config = mkIf cfg.enable {
261 services.zabbixWeb.extraConfig =
264 (versionAtLeast config.system.stateVersion "20.09") && (versionAtLeast cfg.package.version "5.0.0")
267 $DB['DOUBLE_IEEE754'] = 'true';
270 systemd.tmpfiles.rules =
271 [ "d '${stateDir}' 0750 ${user} ${group} - -" ]
272 ++ optionals (cfg.frontend == "httpd") [
273 "d '${stateDir}/session' 0750 ${user} ${config.services.httpd.group} - -"
275 ++ optionals (cfg.frontend == "nginx") [
276 "d '${stateDir}/session' 0750 ${user} ${config.services.nginx.group} - -"
279 services.phpfpm.pools.zabbix = {
281 group = config.services.${cfg.frontend}.group;
284 # https://www.zabbix.com/documentation/current/manual/installation/install
287 upload_max_filesize = 2M
288 max_execution_time = 300
290 session.auto_start = 0
291 mbstring.func_overload = 0
292 always_populate_raw_post_data = -1
293 # https://bbs.archlinux.org/viewtopic.php?pid=1745214#p1745214
294 session.save_path = ${stateDir}/session
296 + optionalString (config.time.timeZone != null) ''
297 date.timezone = "${config.time.timeZone}"
299 + optionalString (cfg.database.type == "oracle") ''
300 extension=${pkgs.phpPackages.oci8}/lib/php/extensions/oci8.so
302 phpEnv.ZABBIX_CONFIG = "${zabbixConfig}";
305 if cfg.frontend == "httpd" then config.services.httpd.user else config.services.nginx.user;
307 if cfg.frontend == "httpd" then config.services.httpd.group else config.services.nginx.group;
311 services.httpd = mkIf (cfg.frontend == "httpd") {
313 adminAddr = mkDefault cfg.httpd.virtualHost.adminAddr;
314 extraModules = [ "proxy_fcgi" ];
315 virtualHosts.${cfg.hostname} = mkMerge [
316 cfg.httpd.virtualHost
318 documentRoot = mkForce "${cfg.package}/share/zabbix";
320 <Directory "${cfg.package}/share/zabbix">
321 <FilesMatch "\.php$">
322 <If "-f %{REQUEST_FILENAME}">
323 SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/"
328 DirectoryIndex index.php
335 services.nginx = mkIf (cfg.frontend == "nginx") {
337 virtualHosts.${cfg.hostname} = mkMerge [
338 cfg.nginx.virtualHost
340 root = mkForce "${cfg.package}/share/zabbix";
342 index = "index.html index.htm index.php";
343 tryFiles = "$uri $uri/ =404";
345 locations."~ \.php$".extraConfig = ''
346 fastcgi_pass unix:${fpm.socket};
347 fastcgi_index index.php;
353 users.users.${user} = mapAttrs (name: mkDefault) {
354 description = "Zabbix daemon user";
355 uid = config.ids.uids.zabbix;
359 users.groups.${group} = mapAttrs (name: mkDefault) { gid = config.ids.gids.zabbix; };