2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-08-27 18:42:59 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2013-08-27 18:42:59 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.elasticsearch;
|
|
|
|
|
2014-03-10 10:04:29 +00:00
|
|
|
esConfig = ''
|
2013-08-27 18:42:59 +00:00
|
|
|
network.host: ${cfg.host}
|
2014-03-10 10:04:29 +00:00
|
|
|
network.port: ${toString cfg.port}
|
|
|
|
network.tcp.port: ${toString cfg.tcp_port}
|
2013-08-27 18:42:59 +00:00
|
|
|
cluster.name: ${cfg.cluster_name}
|
|
|
|
${cfg.extraConf}
|
|
|
|
'';
|
|
|
|
|
2014-03-10 10:04:29 +00:00
|
|
|
configDir = pkgs.buildEnv {
|
|
|
|
name = "elasticsearch-config";
|
|
|
|
paths = [
|
|
|
|
(pkgs.writeTextDir "elasticsearch.yml" esConfig)
|
|
|
|
(pkgs.writeTextDir "logging.yml" cfg.logging)
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2014-07-05 10:09:53 +00:00
|
|
|
esPlugins = pkgs.buildEnv {
|
|
|
|
name = "elasticsearch-plugins";
|
|
|
|
paths = cfg.plugins;
|
|
|
|
};
|
|
|
|
|
2013-08-27 18:42:59 +00:00
|
|
|
in {
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options.services.elasticsearch = {
|
|
|
|
enable = mkOption {
|
2014-06-24 19:04:56 +00:00
|
|
|
description = "Whether to enable elasticsearch.";
|
2013-08-27 18:42:59 +00:00
|
|
|
default = false;
|
|
|
|
type = types.uniq types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
2014-06-24 19:04:56 +00:00
|
|
|
description = "Elasticsearch listen address.";
|
2013-08-27 18:42:59 +00:00
|
|
|
default = "127.0.0.1";
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-08-27 18:42:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2014-06-24 19:04:56 +00:00
|
|
|
description = "Elasticsearch port to listen for HTTP traffic.";
|
2014-03-10 10:04:29 +00:00
|
|
|
default = 9200;
|
|
|
|
type = types.int;
|
2013-08-27 18:42:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
tcp_port = mkOption {
|
2014-06-24 19:04:56 +00:00
|
|
|
description = "Elasticsearch port for the node to node communication.";
|
2014-03-10 10:04:29 +00:00
|
|
|
default = 9300;
|
|
|
|
type = types.int;
|
2013-08-27 18:42:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cluster_name = mkOption {
|
2014-06-24 19:04:56 +00:00
|
|
|
description = "Elasticsearch name that identifies your cluster for auto-discovery.";
|
2013-08-27 18:42:59 +00:00
|
|
|
default = "elasticsearch";
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-08-27 18:42:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConf = mkOption {
|
2014-06-24 19:04:56 +00:00
|
|
|
description = "Extra configuration for elasticsearch.";
|
2013-08-27 18:42:59 +00:00
|
|
|
default = "";
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-08-27 18:42:59 +00:00
|
|
|
example = ''
|
|
|
|
node.name: "elasticsearch"
|
|
|
|
node.master: true
|
|
|
|
node.data: false
|
|
|
|
index.number_of_shards: 5
|
|
|
|
index.number_of_replicas: 1
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logging = mkOption {
|
2014-06-24 19:04:56 +00:00
|
|
|
description = "Elasticsearch logging configuration.";
|
2013-08-27 18:42:59 +00:00
|
|
|
default = ''
|
2013-10-12 10:42:10 +00:00
|
|
|
rootLogger: INFO, console
|
2013-08-27 18:42:59 +00:00
|
|
|
logger:
|
2013-10-12 10:42:10 +00:00
|
|
|
action: INFO
|
2013-08-27 18:42:59 +00:00
|
|
|
com.amazonaws: WARN
|
|
|
|
appender:
|
|
|
|
console:
|
|
|
|
type: console
|
|
|
|
layout:
|
|
|
|
type: consolePattern
|
|
|
|
conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
|
|
|
|
'';
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-08-27 18:42:59 +00:00
|
|
|
};
|
2014-03-10 10:04:29 +00:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/elasticsearch";
|
|
|
|
description = ''
|
|
|
|
Data directory for elasticsearch.
|
|
|
|
'';
|
|
|
|
};
|
2014-06-24 09:01:28 +00:00
|
|
|
|
|
|
|
extraCmdLineOptions = mkOption {
|
2014-06-24 19:04:56 +00:00
|
|
|
description = "Extra command line options for the elasticsearch launcher.";
|
2014-06-24 09:01:28 +00:00
|
|
|
default = [];
|
|
|
|
type = types.listOf types.string;
|
|
|
|
example = [ "-Djava.net.preferIPv4Stack=true" ];
|
|
|
|
};
|
|
|
|
|
2014-07-05 10:09:53 +00:00
|
|
|
plugins = mkOption {
|
|
|
|
description = "Extra elasticsearch plugins";
|
|
|
|
default = [];
|
|
|
|
type = types.listOf types.package;
|
|
|
|
};
|
|
|
|
|
2013-08-27 18:42:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2013-11-05 07:52:23 +00:00
|
|
|
systemd.services.elasticsearch = {
|
2014-06-24 19:10:22 +00:00
|
|
|
description = "Elasticsearch Daemon";
|
2013-08-27 18:42:59 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
2014-03-10 10:04:29 +00:00
|
|
|
environment = { ES_HOME = cfg.dataDir; };
|
2013-08-27 18:42:59 +00:00
|
|
|
serviceConfig = {
|
2014-07-28 18:12:19 +00:00
|
|
|
ExecStart = "${pkgs.elasticsearch}/bin/elasticsearch -Des.path.conf=${configDir} ${toString cfg.extraCmdLineOptions}";
|
2013-08-27 18:42:59 +00:00
|
|
|
User = "elasticsearch";
|
2014-06-13 11:42:52 +00:00
|
|
|
PermissionsStartOnly = true;
|
2013-08-27 18:42:59 +00:00
|
|
|
};
|
2014-03-10 10:04:29 +00:00
|
|
|
preStart = ''
|
|
|
|
mkdir -m 0700 -p ${cfg.dataDir}
|
|
|
|
if [ "$(id -u)" = 0 ]; then chown -R elasticsearch ${cfg.dataDir}; fi
|
2014-07-05 10:09:53 +00:00
|
|
|
|
|
|
|
# Install plugins
|
|
|
|
rm ${cfg.dataDir}/plugins || true
|
|
|
|
ln -s ${esPlugins}/plugins ${cfg.dataDir}/plugins
|
2014-03-10 10:04:29 +00:00
|
|
|
'';
|
2014-09-13 00:21:31 +00:00
|
|
|
postStart = mkBefore ''
|
|
|
|
until ${pkgs.curl}/bin/curl -s -o /dev/null ${cfg.host}:${toString cfg.port}; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
'';
|
2013-08-27 18:42:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.elasticsearch ];
|
|
|
|
|
|
|
|
users.extraUsers = singleton {
|
|
|
|
name = "elasticsearch";
|
|
|
|
uid = config.ids.uids.elasticsearch;
|
|
|
|
description = "Elasticsearch daemon user";
|
2014-03-10 10:04:29 +00:00
|
|
|
home = cfg.dataDir;
|
2013-08-27 18:42:59 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|