1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.kibana;
7
8 cfgFile = pkgs.writeText "kibana.json" (builtins.toJSON (
9 (filterAttrsRecursive (n: v: v != null) ({
10 host = cfg.listenAddress;
11 port = cfg.port;
12 ssl_cert_file = cfg.cert;
13 ssl_key_file = cfg.key;
14
15 kibana_index = cfg.index;
16 default_app_id = cfg.defaultAppId;
17
18 elasticsearch_url = cfg.elasticsearch.url;
19 kibana_elasticsearch_username = cfg.elasticsearch.username;
20 kibana_elasticsearch_password = cfg.elasticsearch.password;
21 kibana_elasticsearch_cert = cfg.elasticsearch.cert;
22 kibana_elasticsearch_key = cfg.elasticsearch.key;
23 ca = cfg.elasticsearch.ca;
24
25 bundled_plugin_ids = [
26 "plugins/dashboard/index"
27 "plugins/discover/index"
28 "plugins/doc/index"
29 "plugins/kibana/index"
30 "plugins/markdown_vis/index"
31 "plugins/metric_vis/index"
32 "plugins/settings/index"
33 "plugins/table_vis/index"
34 "plugins/vis_types/index"
35 "plugins/visualize/index"
36 ];
37 } // cfg.extraConf)
38 )));
39in {
40 options.services.kibana = {
41 enable = mkEnableOption "enable kibana service";
42
43 listenAddress = mkOption {
44 description = "Kibana listening host";
45 default = "127.0.0.1";
46 type = types.str;
47 };
48
49 port = mkOption {
50 description = "Kibana listening port";
51 default = 5601;
52 type = types.int;
53 };
54
55 cert = mkOption {
56 description = "Kibana ssl certificate.";
57 default = null;
58 type = types.nullOr types.path;
59 };
60
61 key = mkOption {
62 description = "Kibana ssl key.";
63 default = null;
64 type = types.nullOr types.path;
65 };
66
67 index = mkOption {
68 description = "Elasticsearch index to use for saving kibana config.";
69 default = ".kibana";
70 type = types.str;
71 };
72
73 defaultAppId = mkOption {
74 description = "Elasticsearch default application id.";
75 default = "discover";
76 type = types.str;
77 };
78
79 elasticsearch = {
80 url = mkOption {
81 description = "Elasticsearch url";
82 default = "http://localhost:9200";
83 type = types.str;
84 };
85
86 username = mkOption {
87 description = "Username for elasticsearch basic auth.";
88 default = null;
89 type = types.nullOr types.str;
90 };
91
92 password = mkOption {
93 description = "Password for elasticsearch basic auth.";
94 default = null;
95 type = types.nullOr types.str;
96 };
97
98 ca = mkOption {
99 description = "CA file to auth against elasticsearch.";
100 default = null;
101 type = types.nullOr types.path;
102 };
103
104 cert = mkOption {
105 description = "Certificate file to auth against elasticsearch.";
106 default = null;
107 type = types.nullOr types.path;
108 };
109
110 key = mkOption {
111 description = "Key file to auth against elasticsearch.";
112 default = null;
113 type = types.nullOr types.path;
114 };
115 };
116
117 package = mkOption {
118 description = "Kibana package to use";
119 default = pkgs.kibana;
120 defaultText = "pkgs.kibana";
121 type = types.package;
122 };
123
124 dataDir = mkOption {
125 description = "Kibana data directory";
126 default = "/var/lib/kibana";
127 type = types.path;
128 };
129
130 extraConf = mkOption {
131 description = "Kibana extra configuration";
132 default = {};
133 type = types.attrs;
134 };
135 };
136
137 config = mkIf (cfg.enable) {
138 systemd.services.kibana = {
139 description = "Kibana Service";
140 wantedBy = [ "multi-user.target" ];
141 after = [ "network-interfaces.target" "elasticsearch.service" ];
142 environment = { BABEL_CACHE_PATH = "${cfg.dataDir}/.babelcache.json"; };
143 serviceConfig = {
144 ExecStart = "${cfg.package}/bin/kibana --config ${cfgFile}";
145 User = "kibana";
146 WorkingDirectory = cfg.dataDir;
147 };
148 };
149
150 environment.systemPackages = [ cfg.package ];
151
152 users.extraUsers = singleton {
153 name = "kibana";
154 uid = config.ids.uids.kibana;
155 description = "Kibana service user";
156 home = cfg.dataDir;
157 createHome = true;
158 };
159 };
160}