Merge branch 'nixos/elasticsearch/elasticsearch_fix' of git://github.com/offlinehacker/nixpkgs
nixos/elasticsearch: Make port an integer, add dataDir option, make pure
This commit is contained in:
commit
78029b7b0f
|
@ -5,16 +5,22 @@ with pkgs.lib;
|
||||||
let
|
let
|
||||||
cfg = config.services.elasticsearch;
|
cfg = config.services.elasticsearch;
|
||||||
|
|
||||||
es_home = "/var/lib/elasticsearch";
|
esConfig = ''
|
||||||
|
|
||||||
configFile = pkgs.writeText "elasticsearch.yml" ''
|
|
||||||
network.host: ${cfg.host}
|
network.host: ${cfg.host}
|
||||||
network.port: ${cfg.port}
|
network.port: ${toString cfg.port}
|
||||||
network.tcp.port: ${cfg.tcp_port}
|
network.tcp.port: ${toString cfg.tcp_port}
|
||||||
cluster.name: ${cfg.cluster_name}
|
cluster.name: ${cfg.cluster_name}
|
||||||
${cfg.extraConf}
|
${cfg.extraConf}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
configDir = pkgs.buildEnv {
|
||||||
|
name = "elasticsearch-config";
|
||||||
|
paths = [
|
||||||
|
(pkgs.writeTextDir "elasticsearch.yml" esConfig)
|
||||||
|
(pkgs.writeTextDir "logging.yml" cfg.logging)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
|
||||||
###### interface
|
###### interface
|
||||||
|
@ -34,14 +40,14 @@ in {
|
||||||
|
|
||||||
port = mkOption {
|
port = mkOption {
|
||||||
description = "Elasticsearch port to listen for HTTP traffic";
|
description = "Elasticsearch port to listen for HTTP traffic";
|
||||||
default = "9200";
|
default = 9200;
|
||||||
type = types.str;
|
type = types.int;
|
||||||
};
|
};
|
||||||
|
|
||||||
tcp_port = mkOption {
|
tcp_port = mkOption {
|
||||||
description = "Elasticsearch port for the node to node communication";
|
description = "Elasticsearch port for the node to node communication";
|
||||||
default = "9300";
|
default = 9300;
|
||||||
type = types.str;
|
type = types.int;
|
||||||
};
|
};
|
||||||
|
|
||||||
cluster_name = mkOption {
|
cluster_name = mkOption {
|
||||||
|
@ -79,27 +85,32 @@ in {
|
||||||
'';
|
'';
|
||||||
type = types.str;
|
type = types.str;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dataDir = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
default = "/var/lib/elasticsearch";
|
||||||
|
description = ''
|
||||||
|
Data directory for elasticsearch.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
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 = {
|
systemd.services.elasticsearch = {
|
||||||
description = "Elasticsearch daemon";
|
description = "Elasticsearch daemon";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network-interfaces.target" ];
|
after = [ "network-interfaces.target" ];
|
||||||
environment = { ES_HOME = es_home; };
|
environment = { ES_HOME = cfg.dataDir; };
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = "${pkgs.elasticsearch}/bin/elasticsearch -f -Des.path.conf=/etc/elasticsearch";
|
ExecStart = "${pkgs.elasticsearch}/bin/elasticsearch -f -Des.path.conf=${configDir}";
|
||||||
User = "elasticsearch";
|
User = "elasticsearch";
|
||||||
};
|
};
|
||||||
|
preStart = ''
|
||||||
|
mkdir -m 0700 -p ${cfg.dataDir}
|
||||||
|
if [ "$(id -u)" = 0 ]; then chown -R elasticsearch ${cfg.dataDir}; fi
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = [ pkgs.elasticsearch ];
|
environment.systemPackages = [ pkgs.elasticsearch ];
|
||||||
|
@ -108,8 +119,7 @@ in {
|
||||||
name = "elasticsearch";
|
name = "elasticsearch";
|
||||||
uid = config.ids.uids.elasticsearch;
|
uid = config.ids.uids.elasticsearch;
|
||||||
description = "Elasticsearch daemon user";
|
description = "Elasticsearch daemon user";
|
||||||
home = es_home;
|
home = cfg.dataDir;
|
||||||
createHome = true;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue