2013-08-27 20:42:59 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.elasticsearch;
|
|
|
|
|
|
|
|
es_home = "/var/lib/elasticsearch";
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "elasticsearch.yml" ''
|
|
|
|
network.host: ${cfg.host}
|
|
|
|
network.port: ${cfg.port}
|
|
|
|
network.tcp.port: ${cfg.tcp_port}
|
|
|
|
cluster.name: ${cfg.cluster_name}
|
|
|
|
${cfg.extraConf}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options.services.elasticsearch = {
|
|
|
|
enable = mkOption {
|
|
|
|
description = "Whether to enable elasticsearch";
|
|
|
|
default = false;
|
|
|
|
type = types.uniq types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
description = "Elasticsearch listen address";
|
|
|
|
default = "127.0.0.1";
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-08-27 20:42:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
description = "Elasticsearch port to listen for HTTP traffic";
|
|
|
|
default = "9200";
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-08-27 20:42:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
tcp_port = mkOption {
|
|
|
|
description = "Elasticsearch port for the node to node communication";
|
|
|
|
default = "9300";
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-08-27 20:42:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
cluster_name = mkOption {
|
|
|
|
description = "Elasticsearch name that identifies your cluster for auto-discovery";
|
|
|
|
default = "elasticsearch";
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-08-27 20:42:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConf = mkOption {
|
|
|
|
description = "Extra configuration for elasticsearch";
|
|
|
|
default = "";
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-08-27 20:42:59 +02:00
|
|
|
example = ''
|
|
|
|
node.name: "elasticsearch"
|
|
|
|
node.master: true
|
|
|
|
node.data: false
|
|
|
|
index.number_of_shards: 5
|
|
|
|
index.number_of_replicas: 1
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logging = mkOption {
|
|
|
|
description = "Elasticsearch logging configuration";
|
|
|
|
default = ''
|
2013-10-12 12:42:10 +02:00
|
|
|
rootLogger: INFO, console
|
2013-08-27 20:42:59 +02:00
|
|
|
logger:
|
2013-10-12 12:42:10 +02:00
|
|
|
action: INFO
|
2013-08-27 20:42:59 +02:00
|
|
|
com.amazonaws: WARN
|
|
|
|
appender:
|
|
|
|
console:
|
|
|
|
type: console
|
|
|
|
layout:
|
|
|
|
type: consolePattern
|
|
|
|
conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
|
|
|
|
'';
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-08-27 20:42:59 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.etc = [
|
|
|
|
{ source = configFile;
|
|
|
|
target = "elasticsearch/elasticsearch.yml"; }
|
|
|
|
{ source = pkgs.writeText "logging.yml" cfg.logging;
|
|
|
|
target = "elasticsearch/logging.yml"; }
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.elasticsearch = mkIf cfg.enable {
|
|
|
|
description = "Elasticsearch daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
|
|
|
environment = { ES_HOME = es_home; };
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.elasticsearch}/bin/elasticsearch -f -Des.path.conf=/etc/elasticsearch";
|
|
|
|
User = "elasticsearch";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.elasticsearch ];
|
|
|
|
|
|
|
|
users.extraUsers = singleton {
|
|
|
|
name = "elasticsearch";
|
|
|
|
uid = config.ids.uids.elasticsearch;
|
|
|
|
description = "Elasticsearch daemon user";
|
|
|
|
home = es_home;
|
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|