1 { config, lib, options, pkgs, ... }:
6 cfg = config.services.kibana;
7 opt = options.services.kibana;
9 ge7 = builtins.compareVersions cfg.package.version "7" >= 0;
10 lt6_6 = builtins.compareVersions cfg.package.version "6.6" < 0;
12 cfgFile = pkgs.writeText "kibana.json" (builtins.toJSON (
13 (filterAttrsRecursive (n: v: v != null && v != []) ({
14 server.host = cfg.listenAddress;
15 server.port = cfg.port;
16 server.ssl.certificate = cfg.cert;
17 server.ssl.key = cfg.key;
19 kibana.index = cfg.index;
20 kibana.defaultAppId = cfg.defaultAppId;
22 elasticsearch.url = cfg.elasticsearch.url;
23 elasticsearch.hosts = cfg.elasticsearch.hosts;
24 elasticsearch.username = cfg.elasticsearch.username;
25 elasticsearch.password = cfg.elasticsearch.password;
27 elasticsearch.ssl.certificate = cfg.elasticsearch.cert;
28 elasticsearch.ssl.key = cfg.elasticsearch.key;
29 elasticsearch.ssl.certificateAuthorities = cfg.elasticsearch.certificateAuthorities;
34 options.services.kibana = {
35 enable = mkEnableOption (lib.mdDoc "kibana service");
37 listenAddress = mkOption {
38 description = lib.mdDoc "Kibana listening host";
39 default = "127.0.0.1";
44 description = lib.mdDoc "Kibana listening port";
50 description = lib.mdDoc "Kibana ssl certificate.";
52 type = types.nullOr types.path;
56 description = lib.mdDoc "Kibana ssl key.";
58 type = types.nullOr types.path;
62 description = lib.mdDoc "Elasticsearch index to use for saving kibana config.";
67 defaultAppId = mkOption {
68 description = lib.mdDoc "Elasticsearch default application id.";
75 description = lib.mdDoc ''
78 Defaults to `"http://localhost:9200"`.
80 Don't set this when using Kibana >= 7.0.0 because it will result in a
81 configuration error. Use {option}`services.kibana.elasticsearch.hosts`
85 type = types.nullOr types.str;
89 description = lib.mdDoc ''
90 The URLs of the Elasticsearch instances to use for all your queries.
91 All nodes listed here must be on the same cluster.
93 Defaults to `[ "http://localhost:9200" ]`.
95 This option is only valid when using kibana >= 6.6.
98 type = types.nullOr (types.listOf types.str);
101 username = mkOption {
102 description = lib.mdDoc "Username for elasticsearch basic auth.";
104 type = types.nullOr types.str;
107 password = mkOption {
108 description = lib.mdDoc "Password for elasticsearch basic auth.";
110 type = types.nullOr types.str;
114 description = lib.mdDoc ''
115 CA file to auth against elasticsearch.
117 It's recommended to use the {option}`certificateAuthorities` option
118 when using kibana-5.4 or newer.
121 type = types.nullOr types.path;
124 certificateAuthorities = mkOption {
125 description = lib.mdDoc ''
126 CA files to auth against elasticsearch.
128 Please use the {option}`ca` option when using kibana \< 5.4
129 because those old versions don't support setting multiple CA's.
131 This defaults to the singleton list [ca] when the {option}`ca` option is defined.
133 default = if cfg.elasticsearch.ca == null then [] else [ca];
134 defaultText = literalExpression ''
135 if config.${opt.elasticsearch.ca} == null then [ ] else [ ca ]
137 type = types.listOf types.path;
141 description = lib.mdDoc "Certificate file to auth against elasticsearch.";
143 type = types.nullOr types.path;
147 description = lib.mdDoc "Key file to auth against elasticsearch.";
149 type = types.nullOr types.path;
154 description = lib.mdDoc "Kibana package to use";
155 default = pkgs.kibana;
156 defaultText = literalExpression "pkgs.kibana";
157 type = types.package;
161 description = lib.mdDoc "Kibana data directory";
162 default = "/var/lib/kibana";
166 extraConf = mkOption {
167 description = lib.mdDoc "Kibana extra configuration";
173 config = mkIf (cfg.enable) {
176 assertion = ge7 -> cfg.elasticsearch.url == null;
178 "The option services.kibana.elasticsearch.url has been removed when using kibana >= 7.0.0. " +
179 "Please use option services.kibana.elasticsearch.hosts instead.";
182 assertion = lt6_6 -> cfg.elasticsearch.hosts == null;
184 "The option services.kibana.elasticsearch.hosts is only valid for kibana >= 6.6.";
187 systemd.services.kibana = {
188 description = "Kibana Service";
189 wantedBy = [ "multi-user.target" ];
190 after = [ "network.target" "elasticsearch.service" ];
191 environment = { BABEL_CACHE_PATH = "${cfg.dataDir}/.babelcache.json"; };
194 "${cfg.package}/bin/kibana" +
195 " --config ${cfgFile}" +
196 " --path.data ${cfg.dataDir}";
198 WorkingDirectory = cfg.dataDir;
202 environment.systemPackages = [ cfg.package ];
204 users.users.kibana = {
206 description = "Kibana service user";
211 users.groups.kibana = {};