2015-09-19 00:18:43 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.kibana;
|
|
|
|
|
2019-04-14 21:39:46 +02:00
|
|
|
ge7 = builtins.compareVersions cfg.package.version "7" >= 0;
|
|
|
|
lt6_6 = builtins.compareVersions cfg.package.version "6.6" < 0;
|
|
|
|
|
2018-08-03 12:24:38 +02:00
|
|
|
cfgFile = pkgs.writeText "kibana.json" (builtins.toJSON (
|
2019-09-07 14:24:24 +02:00
|
|
|
(filterAttrsRecursive (n: v: v != null && v != []) ({
|
2017-06-13 22:36:08 +02:00
|
|
|
server.host = cfg.listenAddress;
|
|
|
|
server.port = cfg.port;
|
|
|
|
server.ssl.certificate = cfg.cert;
|
|
|
|
server.ssl.key = cfg.key;
|
|
|
|
|
|
|
|
kibana.index = cfg.index;
|
|
|
|
kibana.defaultAppId = cfg.defaultAppId;
|
|
|
|
|
|
|
|
elasticsearch.url = cfg.elasticsearch.url;
|
2019-04-14 21:39:46 +02:00
|
|
|
elasticsearch.hosts = cfg.elasticsearch.hosts;
|
2017-06-13 22:36:08 +02:00
|
|
|
elasticsearch.username = cfg.elasticsearch.username;
|
|
|
|
elasticsearch.password = cfg.elasticsearch.password;
|
|
|
|
|
|
|
|
elasticsearch.ssl.certificate = cfg.elasticsearch.cert;
|
|
|
|
elasticsearch.ssl.key = cfg.elasticsearch.key;
|
|
|
|
elasticsearch.ssl.certificateAuthorities = cfg.elasticsearch.certificateAuthorities;
|
|
|
|
} // cfg.extraConf)
|
|
|
|
)));
|
|
|
|
|
2015-09-19 00:18:43 +02:00
|
|
|
in {
|
|
|
|
options.services.kibana = {
|
2019-04-20 03:41:48 +02:00
|
|
|
enable = mkEnableOption "kibana service";
|
2015-09-19 00:18:43 +02:00
|
|
|
|
2015-12-24 00:28:27 +01:00
|
|
|
listenAddress = mkOption {
|
2015-09-19 00:18:43 +02:00
|
|
|
description = "Kibana listening host";
|
|
|
|
default = "127.0.0.1";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
description = "Kibana listening port";
|
|
|
|
default = 5601;
|
|
|
|
type = types.int;
|
|
|
|
};
|
|
|
|
|
|
|
|
cert = mkOption {
|
|
|
|
description = "Kibana ssl certificate.";
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
key = mkOption {
|
|
|
|
description = "Kibana ssl key.";
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
index = mkOption {
|
|
|
|
description = "Elasticsearch index to use for saving kibana config.";
|
|
|
|
default = ".kibana";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultAppId = mkOption {
|
|
|
|
description = "Elasticsearch default application id.";
|
|
|
|
default = "discover";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
elasticsearch = {
|
|
|
|
url = mkOption {
|
2019-04-14 21:39:46 +02:00
|
|
|
description = ''
|
|
|
|
Elasticsearch url.
|
|
|
|
|
|
|
|
Defaults to <literal>"http://localhost:9200"</literal>.
|
|
|
|
|
|
|
|
Don't set this when using Kibana >= 7.0.0 because it will result in a
|
|
|
|
configuration error. Use <option>services.kibana.elasticsearch.hosts</option>
|
|
|
|
instead.
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
hosts = mkOption {
|
|
|
|
description = ''
|
|
|
|
The URLs of the Elasticsearch instances to use for all your queries.
|
|
|
|
All nodes listed here must be on the same cluster.
|
|
|
|
|
|
|
|
Defaults to <literal>[ "http://localhost:9200" ]</literal>.
|
|
|
|
|
|
|
|
This option is only valid when using kibana >= 6.6.
|
|
|
|
'';
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
2015-09-19 00:18:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
description = "Username for elasticsearch basic auth.";
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
|
|
|
description = "Password for elasticsearch basic auth.";
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
ca = mkOption {
|
2017-06-13 22:36:08 +02:00
|
|
|
description = ''
|
|
|
|
CA file to auth against elasticsearch.
|
|
|
|
|
|
|
|
It's recommended to use the <option>certificateAuthorities</option> option
|
|
|
|
when using kibana-5.4 or newer.
|
|
|
|
'';
|
2015-09-19 00:18:43 +02:00
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
};
|
|
|
|
|
2017-06-13 22:36:08 +02:00
|
|
|
certificateAuthorities = mkOption {
|
|
|
|
description = ''
|
|
|
|
CA files to auth against elasticsearch.
|
|
|
|
|
|
|
|
Please use the <option>ca</option> option when using kibana < 5.4
|
|
|
|
because those old versions don't support setting multiple CA's.
|
|
|
|
|
|
|
|
This defaults to the singleton list [ca] when the <option>ca</option> option is defined.
|
|
|
|
'';
|
2019-04-24 05:48:22 +02:00
|
|
|
default = if cfg.elasticsearch.ca == null then [] else [ca];
|
2017-06-13 22:36:08 +02:00
|
|
|
type = types.listOf types.path;
|
|
|
|
};
|
|
|
|
|
2015-09-19 00:18:43 +02:00
|
|
|
cert = mkOption {
|
|
|
|
description = "Certificate file to auth against elasticsearch.";
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
key = mkOption {
|
|
|
|
description = "Key file to auth against elasticsearch.";
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
description = "Kibana package to use";
|
|
|
|
default = pkgs.kibana;
|
2016-01-17 19:34:55 +01:00
|
|
|
defaultText = "pkgs.kibana";
|
2019-09-06 15:04:29 +02:00
|
|
|
example = "pkgs.kibana";
|
2015-09-19 00:18:43 +02:00
|
|
|
type = types.package;
|
|
|
|
};
|
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
description = "Kibana data directory";
|
|
|
|
default = "/var/lib/kibana";
|
|
|
|
type = types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConf = mkOption {
|
|
|
|
description = "Kibana extra configuration";
|
|
|
|
default = {};
|
|
|
|
type = types.attrs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.enable) {
|
2019-04-14 21:39:46 +02:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = ge7 -> cfg.elasticsearch.url == null;
|
|
|
|
message =
|
|
|
|
"The option services.kibana.elasticsearch.url has been removed when using kibana >= 7.0.0. " +
|
|
|
|
"Please use option services.kibana.elasticsearch.hosts instead.";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = lt6_6 -> cfg.elasticsearch.hosts == null;
|
|
|
|
message =
|
|
|
|
"The option services.kibana.elasticsearch.hosts is only valid for kibana >= 6.6.";
|
|
|
|
}
|
|
|
|
];
|
2015-09-19 00:18:43 +02:00
|
|
|
systemd.services.kibana = {
|
|
|
|
description = "Kibana Service";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 20:20:28 +02:00
|
|
|
after = [ "network.target" "elasticsearch.service" ];
|
2016-02-13 15:01:45 +01:00
|
|
|
environment = { BABEL_CACHE_PATH = "${cfg.dataDir}/.babelcache.json"; };
|
2015-09-19 00:18:43 +02:00
|
|
|
serviceConfig = {
|
2018-11-29 17:10:15 +01:00
|
|
|
ExecStart =
|
|
|
|
"${cfg.package}/bin/kibana" +
|
|
|
|
" --config ${cfgFile}" +
|
|
|
|
" --path.data ${cfg.dataDir}";
|
2015-09-19 00:18:43 +02:00
|
|
|
User = "kibana";
|
|
|
|
WorkingDirectory = cfg.dataDir;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.users.kibana = {
|
2015-09-19 00:18:43 +02:00
|
|
|
uid = config.ids.uids.kibana;
|
|
|
|
description = "Kibana service user";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|