2019-02-17 18:08:47 +00:00
|
|
|
{ config, lib, pkgs, ... }: with lib; let
|
|
|
|
cfg = config.services.icingaweb2;
|
|
|
|
poolName = "icingaweb2";
|
2019-06-29 02:47:43 +01:00
|
|
|
phpfpmSocketName = "/var/run/phpfpm/${poolName}.sock";
|
2019-02-17 18:08:47 +00:00
|
|
|
|
2019-03-15 19:35:13 +00:00
|
|
|
defaultConfig = {
|
|
|
|
global = {
|
2019-07-07 02:03:59 +01:00
|
|
|
module_path = "${pkgs.icingaweb2}/modules";
|
2019-03-15 19:35:13 +00:00
|
|
|
};
|
|
|
|
};
|
2019-02-17 18:08:47 +00:00
|
|
|
in {
|
2019-07-07 02:03:59 +01:00
|
|
|
meta.maintainers = with maintainers; [ das_j ];
|
|
|
|
|
2019-02-17 18:08:47 +00:00
|
|
|
options.services.icingaweb2 = with types; {
|
|
|
|
enable = mkEnableOption "the icingaweb2 web interface";
|
|
|
|
|
|
|
|
pool = mkOption {
|
|
|
|
type = str;
|
2019-03-15 19:35:13 +00:00
|
|
|
default = poolName;
|
2019-02-17 18:08:47 +00:00
|
|
|
description = ''
|
|
|
|
Name of existing PHP-FPM pool that is used to run Icingaweb2.
|
|
|
|
If not specified, a pool will automatically created with default values.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualHost = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = "icingaweb2";
|
|
|
|
description = ''
|
|
|
|
Name of the nginx virtualhost to use and setup. If null, no virtualhost is set up.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
timezone = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "UTC";
|
|
|
|
example = "Europe/Berlin";
|
|
|
|
description = "PHP-compliant timezone specification";
|
|
|
|
};
|
|
|
|
|
|
|
|
modules = {
|
|
|
|
doc.enable = mkEnableOption "the icingaweb2 doc module";
|
|
|
|
migrate.enable = mkEnableOption "the icingaweb2 migrate module";
|
|
|
|
setup.enable = mkEnableOption "the icingaweb2 setup module";
|
|
|
|
test.enable = mkEnableOption "the icingaweb2 test module";
|
|
|
|
translation.enable = mkEnableOption "the icingaweb2 translation module";
|
|
|
|
};
|
|
|
|
|
|
|
|
modulePackages = mkOption {
|
|
|
|
type = attrsOf package;
|
|
|
|
default = {};
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
2019-03-15 19:35:13 +00:00
|
|
|
"snow" = icingaweb2Modules.theme-snow;
|
2019-02-17 18:08:47 +00:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Name-package attrset of Icingaweb 2 modules packages to enable.
|
|
|
|
|
|
|
|
If you enable modules manually (e.g. via the web ui), they will not be touched.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-03-15 19:35:13 +00:00
|
|
|
generalConfig = mkOption {
|
|
|
|
type = nullOr attrs;
|
|
|
|
default = null;
|
|
|
|
example = {
|
|
|
|
general = {
|
|
|
|
showStacktraces = 1;
|
|
|
|
config_resource = "icingaweb_db";
|
|
|
|
};
|
|
|
|
logging = {
|
|
|
|
log = "syslog";
|
|
|
|
level = "CRITICAL";
|
|
|
|
};
|
2019-02-17 18:08:47 +00:00
|
|
|
};
|
2019-03-15 19:35:13 +00:00
|
|
|
description = ''
|
|
|
|
config.ini contents.
|
|
|
|
Will automatically be converted to a .ini file.
|
|
|
|
If you don't set global.module_path, the module will take care of it.
|
2019-02-17 18:08:47 +00:00
|
|
|
|
2019-03-15 19:35:13 +00:00
|
|
|
If the value is null, no config.ini is created and you can
|
|
|
|
modify it manually (e.g. via the web interface).
|
|
|
|
Note that you need to update module_path manually.
|
|
|
|
'';
|
2019-02-17 18:08:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
resources = mkOption {
|
2019-03-15 19:35:13 +00:00
|
|
|
type = nullOr attrs;
|
|
|
|
default = null;
|
|
|
|
example = {
|
|
|
|
icingaweb_db = {
|
|
|
|
type = "db";
|
|
|
|
db = "mysql";
|
|
|
|
host = "localhost";
|
|
|
|
username = "icingaweb2";
|
|
|
|
password = "icingaweb2";
|
|
|
|
dbname = "icingaweb2";
|
2019-02-17 18:08:47 +00:00
|
|
|
};
|
2019-03-15 19:35:13 +00:00
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
resources.ini contents.
|
|
|
|
Will automatically be converted to a .ini file.
|
2019-02-17 18:08:47 +00:00
|
|
|
|
2019-03-15 19:35:13 +00:00
|
|
|
If the value is null, no resources.ini is created and you can
|
|
|
|
modify it manually (e.g. via the web interface).
|
|
|
|
Note that if you set passwords here, they will go into the nix store.
|
|
|
|
'';
|
2019-02-17 18:08:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
authentications = mkOption {
|
2019-03-15 19:35:13 +00:00
|
|
|
type = nullOr attrs;
|
|
|
|
default = null;
|
|
|
|
example = {
|
|
|
|
icingaweb = {
|
|
|
|
backend = "db";
|
|
|
|
resource = "icingaweb_db";
|
2019-02-17 18:08:47 +00:00
|
|
|
};
|
2019-03-15 19:35:13 +00:00
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
authentication.ini contents.
|
|
|
|
Will automatically be converted to a .ini file.
|
2019-02-17 18:08:47 +00:00
|
|
|
|
2019-03-15 19:35:13 +00:00
|
|
|
If the value is null, no authentication.ini is created and you can
|
|
|
|
modify it manually (e.g. via the web interface).
|
|
|
|
'';
|
2019-02-17 18:08:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
groupBackends = mkOption {
|
2019-03-15 19:35:13 +00:00
|
|
|
type = nullOr attrs;
|
|
|
|
default = null;
|
|
|
|
example = {
|
|
|
|
icingaweb = {
|
|
|
|
backend = "db";
|
|
|
|
resource = "icingaweb_db";
|
2019-02-17 18:08:47 +00:00
|
|
|
};
|
2019-03-15 19:35:13 +00:00
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
groups.ini contents.
|
|
|
|
Will automatically be converted to a .ini file.
|
2019-02-17 18:08:47 +00:00
|
|
|
|
2019-03-15 19:35:13 +00:00
|
|
|
If the value is null, no groups.ini is created and you can
|
|
|
|
modify it manually (e.g. via the web interface).
|
|
|
|
'';
|
2019-02-17 18:08:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
roles = mkOption {
|
2019-03-15 19:35:13 +00:00
|
|
|
type = nullOr attrs;
|
|
|
|
default = null;
|
|
|
|
example = {
|
|
|
|
Administrators = {
|
|
|
|
users = "admin";
|
|
|
|
permissions = "*";
|
2019-02-17 18:08:47 +00:00
|
|
|
};
|
2019-03-15 19:35:13 +00:00
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
roles.ini contents.
|
|
|
|
Will automatically be converted to a .ini file.
|
|
|
|
|
|
|
|
If the value is null, no roles.ini is created and you can
|
|
|
|
modify it manually (e.g. via the web interface).
|
|
|
|
'';
|
2019-02-17 18:08:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-07-03 17:11:38 +01:00
|
|
|
services.phpfpm.pools = mkIf (cfg.pool == "${poolName}") {
|
|
|
|
"${poolName}" = {
|
|
|
|
listen = phpfpmSocketName;
|
|
|
|
extraConfig = ''
|
|
|
|
listen.owner = nginx
|
|
|
|
listen.group = nginx
|
|
|
|
listen.mode = 0600
|
|
|
|
user = icingaweb2
|
|
|
|
pm = dynamic
|
|
|
|
pm.max_children = 75
|
|
|
|
pm.start_servers = 2
|
|
|
|
pm.min_spare_servers = 2
|
|
|
|
pm.max_spare_servers = 10
|
|
|
|
'';
|
|
|
|
};
|
2019-02-17 18:08:47 +00:00
|
|
|
};
|
|
|
|
|
2019-03-15 19:35:13 +00:00
|
|
|
services.phpfpm.phpOptions = mkIf (cfg.pool == "${poolName}")
|
|
|
|
''
|
|
|
|
extension = ${pkgs.phpPackages.imagick}/lib/php/extensions/imagick.so
|
|
|
|
date.timezone = "${cfg.timezone}"
|
|
|
|
'';
|
|
|
|
|
2019-02-17 18:08:47 +00:00
|
|
|
systemd.services."phpfpm-${poolName}".serviceConfig.ReadWritePaths = [ "/etc/icingaweb2" ];
|
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts = mkIf (cfg.virtualHost != null) {
|
|
|
|
"${cfg.virtualHost}" = {
|
|
|
|
root = "${pkgs.icingaweb2}/public";
|
|
|
|
|
|
|
|
extraConfig = ''
|
|
|
|
index index.php;
|
|
|
|
try_files $1 $uri $uri/ /index.php$is_args$args;
|
|
|
|
'';
|
|
|
|
|
|
|
|
locations."~ ..*/.*.php$".extraConfig = ''
|
|
|
|
return 403;
|
|
|
|
'';
|
|
|
|
|
|
|
|
locations."~ ^/index.php(.*)$".extraConfig = ''
|
|
|
|
fastcgi_intercept_errors on;
|
|
|
|
fastcgi_index index.php;
|
|
|
|
include ${config.services.nginx.package}/conf/fastcgi.conf;
|
|
|
|
try_files $uri =404;
|
|
|
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
2019-06-29 02:47:43 +01:00
|
|
|
fastcgi_pass unix:${phpfpmSocketName};
|
2019-02-17 18:08:47 +00:00
|
|
|
fastcgi_param SCRIPT_FILENAME ${pkgs.icingaweb2}/public/index.php;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# /etc/icingaweb2
|
|
|
|
environment.etc = let
|
2019-04-23 13:04:40 +01:00
|
|
|
doModule = name: optionalAttrs (cfg.modules."${name}".enable) { "icingaweb2/enabledModules/${name}".source = "${pkgs.icingaweb2}/modules/${name}"; };
|
2019-02-17 18:08:47 +00:00
|
|
|
in {}
|
|
|
|
# Module packages
|
|
|
|
// (mapAttrs' (k: v: nameValuePair "icingaweb2/enabledModules/${k}" { source = v; }) cfg.modulePackages)
|
|
|
|
# Built-in modules
|
|
|
|
// doModule "doc"
|
|
|
|
// doModule "migrate"
|
|
|
|
// doModule "setup"
|
|
|
|
// doModule "test"
|
|
|
|
// doModule "translation"
|
|
|
|
# Configs
|
2019-03-15 19:35:13 +00:00
|
|
|
// optionalAttrs (cfg.generalConfig != null) { "icingaweb2/config.ini".text = generators.toINI {} (defaultConfig // cfg.generalConfig); }
|
|
|
|
// optionalAttrs (cfg.resources != null) { "icingaweb2/resources.ini".text = generators.toINI {} cfg.resources; }
|
|
|
|
// optionalAttrs (cfg.authentications != null) { "icingaweb2/authentication.ini".text = generators.toINI {} cfg.authentications; }
|
|
|
|
// optionalAttrs (cfg.groupBackends != null) { "icingaweb2/groups.ini".text = generators.toINI {} cfg.groupBackends; }
|
|
|
|
// optionalAttrs (cfg.roles != null) { "icingaweb2/roles.ini".text = generators.toINI {} cfg.roles; };
|
2019-02-17 18:08:47 +00:00
|
|
|
|
|
|
|
# User and group
|
|
|
|
users.groups.icingaweb2 = {};
|
|
|
|
users.users.icingaweb2 = {
|
|
|
|
description = "Icingaweb2 service user";
|
|
|
|
group = "icingaweb2";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|