at v206 4.1 kB view raw
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 server = { 11 host = cfg.host; 12 port = cfg.port; 13 ssl = { 14 cert = cfg.cert; 15 key = cfg.key; 16 }; 17 }; 18 19 kibana = { 20 index = cfg.index; 21 defaultAppId = cfg.defaultAppId; 22 }; 23 24 elasticsearch = { 25 url = cfg.elasticsearch.url; 26 username = cfg.elasticsearch.username; 27 password = cfg.elasticsearch.password; 28 ssl = { 29 cert = cfg.elasticsearch.cert; 30 key = cfg.elasticsearch.key; 31 ca = cfg.elasticsearch.ca; 32 }; 33 }; 34 35 logging = { 36 verbose = cfg.logLevel == "verbose"; 37 quiet = cfg.logLevel == "quiet"; 38 silent = cfg.logLevel == "silent"; 39 dest = "stdout"; 40 }; 41 } // cfg.extraConf) 42 ))); 43in { 44 options.services.kibana = { 45 enable = mkEnableOption "enable kibana service"; 46 47 host = mkOption { 48 description = "Kibana listening host"; 49 default = "127.0.0.1"; 50 type = types.str; 51 }; 52 53 port = mkOption { 54 description = "Kibana listening port"; 55 default = 5601; 56 type = types.int; 57 }; 58 59 cert = mkOption { 60 description = "Kibana ssl certificate."; 61 default = null; 62 type = types.nullOr types.path; 63 }; 64 65 key = mkOption { 66 description = "Kibana ssl key."; 67 default = null; 68 type = types.nullOr types.path; 69 }; 70 71 index = mkOption { 72 description = "Elasticsearch index to use for saving kibana config."; 73 default = ".kibana"; 74 type = types.str; 75 }; 76 77 defaultAppId = mkOption { 78 description = "Elasticsearch default application id."; 79 default = "discover"; 80 type = types.str; 81 }; 82 83 elasticsearch = { 84 url = mkOption { 85 description = "Elasticsearch url"; 86 default = "http://localhost:9200"; 87 type = types.str; 88 }; 89 90 username = mkOption { 91 description = "Username for elasticsearch basic auth."; 92 default = null; 93 type = types.nullOr types.str; 94 }; 95 96 password = mkOption { 97 description = "Password for elasticsearch basic auth."; 98 default = null; 99 type = types.nullOr types.str; 100 }; 101 102 ca = mkOption { 103 description = "CA file to auth against elasticsearch."; 104 default = null; 105 type = types.nullOr types.path; 106 }; 107 108 cert = mkOption { 109 description = "Certificate file to auth against elasticsearch."; 110 default = null; 111 type = types.nullOr types.path; 112 }; 113 114 key = mkOption { 115 description = "Key file to auth against elasticsearch."; 116 default = null; 117 type = types.nullOr types.path; 118 }; 119 }; 120 121 logLevel = mkOption { 122 description = "Kibana log level"; 123 default = "normal"; 124 type = types.enum ["verbose" "normal" "silent" "quiet"]; 125 }; 126 127 package = mkOption { 128 description = "Kibana package to use"; 129 default = pkgs.kibana; 130 type = types.package; 131 }; 132 133 dataDir = mkOption { 134 description = "Kibana data directory"; 135 default = "/var/lib/kibana"; 136 type = types.path; 137 }; 138 139 extraConf = mkOption { 140 description = "Kibana extra configuration"; 141 default = {}; 142 type = types.attrs; 143 }; 144 }; 145 146 config = mkIf (cfg.enable) { 147 systemd.services.kibana = { 148 description = "Kibana Service"; 149 wantedBy = [ "multi-user.target" ]; 150 after = [ "network-interfaces.target" "elasticsearch.service" ]; 151 serviceConfig = { 152 ExecStart = "${cfg.package}/bin/kibana --config ${cfgFile}"; 153 User = "kibana"; 154 WorkingDirectory = cfg.dataDir; 155 }; 156 }; 157 158 environment.systemPackages = [ cfg.package ]; 159 160 users.extraUsers = singleton { 161 name = "kibana"; 162 uid = config.ids.uids.kibana; 163 description = "Kibana service user"; 164 home = cfg.dataDir; 165 createHome = true; 166 }; 167 }; 168}