Merge pull request #9934 from offlinehacker/nixos/kibana/add

Update kibana, add kibana nixos service
This commit is contained in:
Domen Kožar 2015-09-19 10:38:45 +02:00
commit 72ea74b641
5 changed files with 201 additions and 8 deletions

View File

@ -78,6 +78,26 @@ rec {
listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set)); listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set));
/* Filter an attribute set recursivelly by removing all attributes for
which the given predicate return false.
Example:
filterAttrsRecursive (n: v: v != null) { foo = { bar = null; }; }
=> { foo = {}; }
*/
filterAttrsRecursive = pred: set:
listToAttrs (
concatMap (name:
let v = set.${name}; in
if pred name v then [
(nameValuePair name (
if isAttrs v then filterAttrsRecursive pred v
else v
))
] else []
) (attrNames set)
);
/* foldAttrs: apply fold functions to values grouped by key. Eg accumulate values as list: /* foldAttrs: apply fold functions to values grouped by key. Eg accumulate values as list:
foldAttrs (n: a: [n] ++ a) [] [{ a = 2; } { a = 3; }] foldAttrs (n: a: [n] ++ a) [] [{ a = 2; } { a = 3; }]
=> { a = [ 2 3 ]; } => { a = [ 2 3 ]; }

View File

@ -232,6 +232,7 @@
namecoin = 208; namecoin = 208;
dnschain = 209; dnschain = 209;
#lxd = 210; # unused #lxd = 210; # unused
kibana = 211;
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
@ -442,6 +443,7 @@
namecoin = 208; namecoin = 208;
#dnschain = 209; #unused #dnschain = 209; #unused
lxd = 210; # unused lxd = 210; # unused
#kibana = 211;
# When adding a gid, make sure it doesn't match an existing # When adding a gid, make sure it doesn't match an existing
# uid. Users and groups with the same name should have equal # uid. Users and groups with the same name should have equal

View File

@ -365,6 +365,7 @@
./services/scheduling/fcron.nix ./services/scheduling/fcron.nix
./services/scheduling/marathon.nix ./services/scheduling/marathon.nix
./services/search/elasticsearch.nix ./services/search/elasticsearch.nix
./services/search/kibana.nix
./services/search/solr.nix ./services/search/solr.nix
./services/security/clamav.nix ./services/security/clamav.nix
./services/security/fail2ban.nix ./services/security/fail2ban.nix

View File

@ -0,0 +1,168 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.kibana;
cfgFile = pkgs.writeText "kibana.json" (builtins.toJSON (
(filterAttrsRecursive (n: v: v != null) ({
server = {
host = cfg.host;
port = cfg.port;
ssl = {
cert = cfg.cert;
key = cfg.key;
};
};
kibana = {
index = cfg.index;
defaultAppId = cfg.defaultAppId;
};
elasticsearch = {
url = cfg.elasticsearch.url;
username = cfg.elasticsearch.username;
password = cfg.elasticsearch.password;
ssl = {
cert = cfg.elasticsearch.cert;
key = cfg.elasticsearch.key;
ca = cfg.elasticsearch.ca;
};
};
logging = {
verbose = cfg.logLevel == "verbose";
quiet = cfg.logLevel == "quiet";
silent = cfg.logLevel == "silent";
dest = "stdout";
};
} // cfg.extraConf)
)));
in {
options.services.kibana = {
enable = mkEnableOption "enable kibana service";
host = mkOption {
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 {
description = "Elasticsearch url";
default = "http://localhost:9200";
type = types.str;
};
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 {
description = "CA file to auth against elasticsearch.";
default = null;
type = types.nullOr types.path;
};
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;
};
};
logLevel = mkOption {
description = "Kibana log level";
default = "normal";
type = types.enum ["verbose" "normal" "silent" "quiet"];
};
package = mkOption {
description = "Kibana package to use";
default = pkgs.kibana;
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) {
systemd.services.kibana = {
description = "Kibana Service";
wantedBy = [ "multi-user.target" ];
after = [ "network-interfaces.target" "elasticsearch.service" ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/kibana --config ${cfgFile}";
User = "kibana";
WorkingDirectory = cfg.dataDir;
};
};
environment.systemPackages = [ cfg.package ];
users.extraUsers = singleton {
name = "kibana";
uid = config.ids.uids.kibana;
description = "Kibana service user";
home = cfg.dataDir;
createHome = true;
};
};
}

View File

@ -1,22 +1,24 @@
{ stdenv, fetchurl, conf ? null }: { stdenv, makeWrapper, fetchurl, nodejs, coreutils, which }:
with stdenv.lib; with stdenv.lib;
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
name = "kibana-${version}"; name = "kibana-${version}";
version = "3.1.1"; version = "4.2.0";
src = fetchurl { src = fetchurl {
url = "https://download.elasticsearch.org/kibana/kibana/${name}.tar.gz"; url = "http://download.elastic.co/kibana/kibana-snapshot/kibana-4.2.0-snapshot-linux-x86.tar.gz";
sha256 = "195x6zq9x16nlh2akvn6z0kp8qnba4vq90yrysiafgv8dmw34p5b"; sha256 = "01v35iwy8y6gpbl0v9gikvbx3zdxkrm60sxann76mkaq2al3pv0i";
}; };
phases = ["unpackPhase" "installPhase"]; buildInputs = [ makeWrapper ];
installPhase = '' installPhase = ''
mkdir -p $out mkdir -p $out/libexec/kibana $out/bin
mv * $out/ mv * $out/libexec/kibana/
${optionalString (conf != null) "cp ${conf} $out/config.js"} rm -r $out/libexec/kibana/node
makeWrapper $out/libexec/kibana/bin/kibana $out/bin/kibana \
--prefix PATH : "${nodejs}/bin:${coreutils}/bin:${which}/bin"
''; '';
meta = { meta = {