nixos/zabbixWeb: format
Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
This commit is contained in:
parent
9ca5b84e27
commit
7d3b77d66f
@ -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
|
||||
<?php
|
||||
// Zabbix GUI configuration file.
|
||||
global $DB;
|
||||
$DB['TYPE'] = '${ { mysql = "MYSQL"; pgsql = "POSTGRESQL"; oracle = "ORACLE"; }.${cfg.database.type} }';
|
||||
$DB['TYPE'] = '${
|
||||
{
|
||||
mysql = "MYSQL";
|
||||
pgsql = "POSTGRESQL";
|
||||
oracle = "ORACLE";
|
||||
}
|
||||
.${cfg.database.type}
|
||||
}';
|
||||
$DB['SERVER'] = '${cfg.database.host}';
|
||||
$DB['PORT'] = '${toString cfg.database.port}';
|
||||
$DB['DATABASE'] = '${cfg.database.name}';
|
||||
$DB['USER'] = '${cfg.database.user}';
|
||||
# NOTE: file_get_contents adds newline at the end of returned string
|
||||
$DB['PASSWORD'] = ${if cfg.database.passwordFile != null then "trim(file_get_contents('${cfg.database.passwordFile}'), \"\\r\\n\")" else "''"};
|
||||
$DB['PASSWORD'] = ${
|
||||
if cfg.database.passwordFile != null then
|
||||
"trim(file_get_contents('${cfg.database.passwordFile}'), \"\\r\\n\")"
|
||||
else
|
||||
"''"
|
||||
};
|
||||
// Schema name. Used for IBM DB2 and PostgreSQL.
|
||||
$DB['SCHEMA'] = ''';
|
||||
$ZBX_SERVER = '${cfg.server.address}';
|
||||
@ -33,12 +67,22 @@ let
|
||||
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
(mkRenamedOptionModule
|
||||
[ "services" "zabbixWeb" "virtualHost" ] [ "services" "zabbixWeb" "httpd" "virtualHost" ])
|
||||
(mkRenamedOptionModule
|
||||
[
|
||||
"services"
|
||||
"zabbixWeb"
|
||||
"virtualHost"
|
||||
]
|
||||
[
|
||||
"services"
|
||||
"zabbixWeb"
|
||||
"httpd"
|
||||
"virtualHost"
|
||||
]
|
||||
)
|
||||
];
|
||||
# interface
|
||||
|
||||
@ -46,7 +90,10 @@ in
|
||||
zabbixWeb = {
|
||||
enable = mkEnableOption "the Zabbix web interface";
|
||||
|
||||
package = mkPackageOption pkgs [ "zabbix" "web" ] { };
|
||||
package = mkPackageOption pkgs [
|
||||
"zabbix"
|
||||
"web"
|
||||
] { };
|
||||
|
||||
server = {
|
||||
port = mkOption {
|
||||
@ -64,7 +111,11 @@ in
|
||||
|
||||
database = {
|
||||
type = mkOption {
|
||||
type = types.enum [ "mysql" "pgsql" "oracle" ];
|
||||
type = types.enum [
|
||||
"mysql"
|
||||
"pgsql"
|
||||
"oracle"
|
||||
];
|
||||
example = "mysql";
|
||||
default = "pgsql";
|
||||
description = "Database engine to use.";
|
||||
@ -79,9 +130,12 @@ in
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default =
|
||||
if cfg.database.type == "mysql" then config.services.mysql.port
|
||||
else if cfg.database.type == "pgsql" then config.services.postgresql.settings.port
|
||||
else 1521;
|
||||
if cfg.database.type == "mysql" then
|
||||
config.services.mysql.port
|
||||
else if cfg.database.type == "pgsql" then
|
||||
config.services.postgresql.settings.port
|
||||
else
|
||||
1521;
|
||||
defaultText = literalExpression ''
|
||||
if config.${opt.database.type} == "mysql" then config.${options.services.mysql.port}
|
||||
else if config.${opt.database.type} == "pgsql" then config.services.postgresql.settings.port
|
||||
@ -148,9 +202,9 @@ in
|
||||
};
|
||||
|
||||
hostname = mkOption {
|
||||
type = types.str;
|
||||
default = "zabbix.local";
|
||||
description = "Hostname for either nginx or httpd.";
|
||||
type = types.str;
|
||||
default = "zabbix.local";
|
||||
description = "Hostname for either nginx or httpd.";
|
||||
};
|
||||
|
||||
nginx.virtualHost = mkOption {
|
||||
@ -170,7 +224,13 @@ in
|
||||
};
|
||||
|
||||
poolConfig = mkOption {
|
||||
type = with types; attrsOf (oneOf [ str int bool ]);
|
||||
type =
|
||||
with types;
|
||||
attrsOf (oneOf [
|
||||
str
|
||||
int
|
||||
bool
|
||||
]);
|
||||
default = {
|
||||
"pm" = "dynamic";
|
||||
"pm.max_children" = 32;
|
||||
@ -191,7 +251,6 @@ in
|
||||
Additional configuration to be copied verbatim into {file}`zabbix.conf.php`.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@ -199,16 +258,23 @@ in
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
||||
services.zabbixWeb.extraConfig = optionalString ((versionAtLeast config.system.stateVersion "20.09") && (versionAtLeast cfg.package.version "5.0.0")) ''
|
||||
$DB['DOUBLE_IEEE754'] = 'true';
|
||||
'';
|
||||
services.zabbixWeb.extraConfig =
|
||||
optionalString
|
||||
(
|
||||
(versionAtLeast config.system.stateVersion "20.09") && (versionAtLeast cfg.package.version "5.0.0")
|
||||
)
|
||||
''
|
||||
$DB['DOUBLE_IEEE754'] = 'true';
|
||||
'';
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"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} - -"
|
||||
];
|
||||
systemd.tmpfiles.rules =
|
||||
[ "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;
|
||||
@ -226,15 +292,19 @@ in
|
||||
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) ''
|
||||
''
|
||||
+ optionalString (config.time.timeZone != null) ''
|
||||
date.timezone = "${config.time.timeZone}"
|
||||
'' + optionalString (cfg.database.type == "oracle") ''
|
||||
''
|
||||
+ optionalString (cfg.database.type == "oracle") ''
|
||||
extension=${pkgs.phpPackages.oci8}/lib/php/extensions/oci8.so
|
||||
'';
|
||||
phpEnv.ZABBIX_CONFIG = "${zabbixConfig}";
|
||||
settings = {
|
||||
"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;
|
||||
"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;
|
||||
};
|
||||
|
||||
@ -258,7 +328,8 @@ in
|
||||
DirectoryIndex index.php
|
||||
</Directory>
|
||||
'';
|
||||
} ];
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
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; };
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user