mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
nixos/zabbixWeb: format
Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
This commit is contained in:
parent
9ca5b84e27
commit
7d3b77d66f
1 changed files with 115 additions and 47 deletions
|
@ -1,9 +1,31 @@
|
||||||
{ config, lib, options, pkgs, ... }:
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
options,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
inherit (lib) mkDefault mkEnableOption mkPackageOption mkRenamedOptionModule mkForce mkIf mkMerge mkOption types;
|
inherit (lib)
|
||||||
inherit (lib) literalExpression mapAttrs optionalString optionals versionAtLeast;
|
mkDefault
|
||||||
|
mkEnableOption
|
||||||
|
mkPackageOption
|
||||||
|
mkRenamedOptionModule
|
||||||
|
mkForce
|
||||||
|
mkIf
|
||||||
|
mkMerge
|
||||||
|
mkOption
|
||||||
|
types
|
||||||
|
;
|
||||||
|
inherit (lib)
|
||||||
|
literalExpression
|
||||||
|
mapAttrs
|
||||||
|
optionalString
|
||||||
|
optionals
|
||||||
|
versionAtLeast
|
||||||
|
;
|
||||||
|
|
||||||
cfg = config.services.zabbixWeb;
|
cfg = config.services.zabbixWeb;
|
||||||
opt = options.services.zabbixWeb;
|
opt = options.services.zabbixWeb;
|
||||||
|
@ -17,13 +39,25 @@ let
|
||||||
<?php
|
<?php
|
||||||
// Zabbix GUI configuration file.
|
// Zabbix GUI configuration file.
|
||||||
global $DB;
|
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['SERVER'] = '${cfg.database.host}';
|
||||||
$DB['PORT'] = '${toString cfg.database.port}';
|
$DB['PORT'] = '${toString cfg.database.port}';
|
||||||
$DB['DATABASE'] = '${cfg.database.name}';
|
$DB['DATABASE'] = '${cfg.database.name}';
|
||||||
$DB['USER'] = '${cfg.database.user}';
|
$DB['USER'] = '${cfg.database.user}';
|
||||||
# NOTE: file_get_contents adds newline at the end of returned string
|
# 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.
|
// Schema name. Used for IBM DB2 and PostgreSQL.
|
||||||
$DB['SCHEMA'] = ''';
|
$DB['SCHEMA'] = ''';
|
||||||
$ZBX_SERVER = '${cfg.server.address}';
|
$ZBX_SERVER = '${cfg.server.address}';
|
||||||
|
@ -33,12 +67,22 @@ let
|
||||||
|
|
||||||
${cfg.extraConfig}
|
${cfg.extraConfig}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(mkRenamedOptionModule
|
(mkRenamedOptionModule
|
||||||
[ "services" "zabbixWeb" "virtualHost" ] [ "services" "zabbixWeb" "httpd" "virtualHost" ])
|
[
|
||||||
|
"services"
|
||||||
|
"zabbixWeb"
|
||||||
|
"virtualHost"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"services"
|
||||||
|
"zabbixWeb"
|
||||||
|
"httpd"
|
||||||
|
"virtualHost"
|
||||||
|
]
|
||||||
|
)
|
||||||
];
|
];
|
||||||
# interface
|
# interface
|
||||||
|
|
||||||
|
@ -46,7 +90,10 @@ in
|
||||||
zabbixWeb = {
|
zabbixWeb = {
|
||||||
enable = mkEnableOption "the Zabbix web interface";
|
enable = mkEnableOption "the Zabbix web interface";
|
||||||
|
|
||||||
package = mkPackageOption pkgs [ "zabbix" "web" ] { };
|
package = mkPackageOption pkgs [
|
||||||
|
"zabbix"
|
||||||
|
"web"
|
||||||
|
] { };
|
||||||
|
|
||||||
server = {
|
server = {
|
||||||
port = mkOption {
|
port = mkOption {
|
||||||
|
@ -64,7 +111,11 @@ in
|
||||||
|
|
||||||
database = {
|
database = {
|
||||||
type = mkOption {
|
type = mkOption {
|
||||||
type = types.enum [ "mysql" "pgsql" "oracle" ];
|
type = types.enum [
|
||||||
|
"mysql"
|
||||||
|
"pgsql"
|
||||||
|
"oracle"
|
||||||
|
];
|
||||||
example = "mysql";
|
example = "mysql";
|
||||||
default = "pgsql";
|
default = "pgsql";
|
||||||
description = "Database engine to use.";
|
description = "Database engine to use.";
|
||||||
|
@ -79,9 +130,12 @@ in
|
||||||
port = mkOption {
|
port = mkOption {
|
||||||
type = types.port;
|
type = types.port;
|
||||||
default =
|
default =
|
||||||
if cfg.database.type == "mysql" then config.services.mysql.port
|
if cfg.database.type == "mysql" then
|
||||||
else if cfg.database.type == "pgsql" then config.services.postgresql.settings.port
|
config.services.mysql.port
|
||||||
else 1521;
|
else if cfg.database.type == "pgsql" then
|
||||||
|
config.services.postgresql.settings.port
|
||||||
|
else
|
||||||
|
1521;
|
||||||
defaultText = literalExpression ''
|
defaultText = literalExpression ''
|
||||||
if config.${opt.database.type} == "mysql" then config.${options.services.mysql.port}
|
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
|
else if config.${opt.database.type} == "pgsql" then config.services.postgresql.settings.port
|
||||||
|
@ -148,9 +202,9 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
hostname = mkOption {
|
hostname = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "zabbix.local";
|
default = "zabbix.local";
|
||||||
description = "Hostname for either nginx or httpd.";
|
description = "Hostname for either nginx or httpd.";
|
||||||
};
|
};
|
||||||
|
|
||||||
nginx.virtualHost = mkOption {
|
nginx.virtualHost = mkOption {
|
||||||
|
@ -170,7 +224,13 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
poolConfig = mkOption {
|
poolConfig = mkOption {
|
||||||
type = with types; attrsOf (oneOf [ str int bool ]);
|
type =
|
||||||
|
with types;
|
||||||
|
attrsOf (oneOf [
|
||||||
|
str
|
||||||
|
int
|
||||||
|
bool
|
||||||
|
]);
|
||||||
default = {
|
default = {
|
||||||
"pm" = "dynamic";
|
"pm" = "dynamic";
|
||||||
"pm.max_children" = 32;
|
"pm.max_children" = 32;
|
||||||
|
@ -191,7 +251,6 @@ in
|
||||||
Additional configuration to be copied verbatim into {file}`zabbix.conf.php`.
|
Additional configuration to be copied verbatim into {file}`zabbix.conf.php`.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -199,16 +258,23 @@ in
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
|
||||||
services.zabbixWeb.extraConfig = optionalString ((versionAtLeast config.system.stateVersion "20.09") && (versionAtLeast cfg.package.version "5.0.0")) ''
|
services.zabbixWeb.extraConfig =
|
||||||
$DB['DOUBLE_IEEE754'] = 'true';
|
optionalString
|
||||||
'';
|
(
|
||||||
|
(versionAtLeast config.system.stateVersion "20.09") && (versionAtLeast cfg.package.version "5.0.0")
|
||||||
|
)
|
||||||
|
''
|
||||||
|
$DB['DOUBLE_IEEE754'] = 'true';
|
||||||
|
'';
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [
|
systemd.tmpfiles.rules =
|
||||||
"d '${stateDir}' 0750 ${user} ${group} - -" ] ++ optionals (cfg.frontend == "httpd") [
|
[ "d '${stateDir}' 0750 ${user} ${group} - -" ]
|
||||||
"d '${stateDir}/session' 0750 ${user} ${config.services.httpd.group} - -"
|
++ optionals (cfg.frontend == "httpd") [
|
||||||
] ++ optionals (cfg.frontend == "nginx") [
|
"d '${stateDir}/session' 0750 ${user} ${config.services.httpd.group} - -"
|
||||||
"d '${stateDir}/session' 0750 ${user} ${config.services.nginx.group} - -"
|
]
|
||||||
];
|
++ optionals (cfg.frontend == "nginx") [
|
||||||
|
"d '${stateDir}/session' 0750 ${user} ${config.services.nginx.group} - -"
|
||||||
|
];
|
||||||
|
|
||||||
services.phpfpm.pools.zabbix = {
|
services.phpfpm.pools.zabbix = {
|
||||||
inherit user;
|
inherit user;
|
||||||
|
@ -226,15 +292,19 @@ in
|
||||||
always_populate_raw_post_data = -1
|
always_populate_raw_post_data = -1
|
||||||
# https://bbs.archlinux.org/viewtopic.php?pid=1745214#p1745214
|
# https://bbs.archlinux.org/viewtopic.php?pid=1745214#p1745214
|
||||||
session.save_path = ${stateDir}/session
|
session.save_path = ${stateDir}/session
|
||||||
'' + optionalString (config.time.timeZone != null) ''
|
''
|
||||||
|
+ optionalString (config.time.timeZone != null) ''
|
||||||
date.timezone = "${config.time.timeZone}"
|
date.timezone = "${config.time.timeZone}"
|
||||||
'' + optionalString (cfg.database.type == "oracle") ''
|
''
|
||||||
|
+ optionalString (cfg.database.type == "oracle") ''
|
||||||
extension=${pkgs.phpPackages.oci8}/lib/php/extensions/oci8.so
|
extension=${pkgs.phpPackages.oci8}/lib/php/extensions/oci8.so
|
||||||
'';
|
'';
|
||||||
phpEnv.ZABBIX_CONFIG = "${zabbixConfig}";
|
phpEnv.ZABBIX_CONFIG = "${zabbixConfig}";
|
||||||
settings = {
|
settings = {
|
||||||
"listen.owner" = if cfg.frontend == "httpd" then config.services.httpd.user else config.services.nginx.user;
|
"listen.owner" =
|
||||||
"listen.group" = if cfg.frontend == "httpd" then config.services.httpd.group else config.services.nginx.group;
|
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;
|
} // cfg.poolConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -258,7 +328,8 @@ in
|
||||||
DirectoryIndex index.php
|
DirectoryIndex index.php
|
||||||
</Directory>
|
</Directory>
|
||||||
'';
|
'';
|
||||||
} ];
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
services.nginx = mkIf (cfg.frontend == "nginx") {
|
services.nginx = mkIf (cfg.frontend == "nginx") {
|
||||||
|
@ -266,17 +337,17 @@ in
|
||||||
virtualHosts.${cfg.hostname} = mkMerge [
|
virtualHosts.${cfg.hostname} = mkMerge [
|
||||||
cfg.nginx.virtualHost
|
cfg.nginx.virtualHost
|
||||||
{
|
{
|
||||||
root = mkForce "${cfg.package}/share/zabbix";
|
root = mkForce "${cfg.package}/share/zabbix";
|
||||||
locations."/" = {
|
locations."/" = {
|
||||||
index = "index.html index.htm index.php";
|
index = "index.html index.htm index.php";
|
||||||
tryFiles = "$uri $uri/ =404";
|
tryFiles = "$uri $uri/ =404";
|
||||||
};
|
};
|
||||||
locations."~ \.php$".extraConfig = ''
|
locations."~ \.php$".extraConfig = ''
|
||||||
fastcgi_pass unix:${fpm.socket};
|
fastcgi_pass unix:${fpm.socket};
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users.${user} = mapAttrs (name: mkDefault) {
|
users.users.${user} = mapAttrs (name: mkDefault) {
|
||||||
|
@ -285,9 +356,6 @@ in
|
||||||
inherit group;
|
inherit group;
|
||||||
};
|
};
|
||||||
|
|
||||||
users.groups.${group} = mapAttrs (name: mkDefault) {
|
users.groups.${group} = mapAttrs (name: mkDefault) { gid = config.ids.gids.zabbix; };
|
||||||
gid = config.ids.gids.zabbix;
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue