summary refs log tree commit diff
path: root/nixos/modules/services/search
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2014-03-19 18:02:13 -0400
committerShea Levy <shea@shealevy.com>2014-03-19 18:02:13 -0400
commit78029b7b0fd29e9ae5026316480453b0fe07f11a (patch)
tree2d0c95d4c66711cffc6d6b9bcea3de2bb1876f09 /nixos/modules/services/search
parentca81e38178ad4edac19232b482335d3ba89a3cee (diff)
parentcf65a62af43d5614bc81aa9db888e27b29804850 (diff)
downloadnixlib-78029b7b0fd29e9ae5026316480453b0fe07f11a.tar
nixlib-78029b7b0fd29e9ae5026316480453b0fe07f11a.tar.gz
nixlib-78029b7b0fd29e9ae5026316480453b0fe07f11a.tar.bz2
nixlib-78029b7b0fd29e9ae5026316480453b0fe07f11a.tar.lz
nixlib-78029b7b0fd29e9ae5026316480453b0fe07f11a.tar.xz
nixlib-78029b7b0fd29e9ae5026316480453b0fe07f11a.tar.zst
nixlib-78029b7b0fd29e9ae5026316480453b0fe07f11a.zip
Merge branch 'nixos/elasticsearch/elasticsearch_fix' of git://github.com/offlinehacker/nixpkgs
nixos/elasticsearch: Make port an integer, add dataDir option, make pure
Diffstat (limited to 'nixos/modules/services/search')
-rw-r--r--nixos/modules/services/search/elasticsearch.nix50
1 files changed, 30 insertions, 20 deletions
diff --git a/nixos/modules/services/search/elasticsearch.nix b/nixos/modules/services/search/elasticsearch.nix
index b3d934862abf..d647301889af 100644
--- a/nixos/modules/services/search/elasticsearch.nix
+++ b/nixos/modules/services/search/elasticsearch.nix
@@ -5,16 +5,22 @@ with pkgs.lib;
 let
   cfg = config.services.elasticsearch;
 
-  es_home = "/var/lib/elasticsearch";
-
-  configFile = pkgs.writeText "elasticsearch.yml" ''
+  esConfig = ''
     network.host: ${cfg.host}
-    network.port: ${cfg.port}
-    network.tcp.port: ${cfg.tcp_port}
+    network.port: ${toString cfg.port}
+    network.tcp.port: ${toString cfg.tcp_port}
     cluster.name: ${cfg.cluster_name}
     ${cfg.extraConf}
   '';
 
+  configDir = pkgs.buildEnv {
+    name = "elasticsearch-config";
+    paths = [
+      (pkgs.writeTextDir "elasticsearch.yml" esConfig)
+      (pkgs.writeTextDir "logging.yml" cfg.logging)
+    ];
+  };
+
 in {
 
   ###### interface
@@ -34,14 +40,14 @@ in {
 
     port = mkOption {
       description = "Elasticsearch port to listen for HTTP traffic";
-      default = "9200";
-      type = types.str;
+      default = 9200;
+      type = types.int;
     };
 
     tcp_port = mkOption {
       description = "Elasticsearch port for the node to node communication";
-      default = "9300";
-      type = types.str;
+      default = 9300;
+      type = types.int;
     };
 
     cluster_name = mkOption {
@@ -79,27 +85,32 @@ in {
       '';
       type = types.str;
     };
+
+    dataDir = mkOption {
+      type = types.path;
+      default = "/var/lib/elasticsearch";
+      description = ''
+        Data directory for elasticsearch.
+      '';
+    };
   };
 
   ###### 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 = {
       description = "Elasticsearch daemon";
       wantedBy = [ "multi-user.target" ];
       after = [ "network-interfaces.target" ];
-      environment = { ES_HOME = es_home; };
+      environment = { ES_HOME = cfg.dataDir; };
       serviceConfig = {
-        ExecStart = "${pkgs.elasticsearch}/bin/elasticsearch -f -Des.path.conf=/etc/elasticsearch";
+        ExecStart = "${pkgs.elasticsearch}/bin/elasticsearch -f -Des.path.conf=${configDir}";
         User = "elasticsearch";
       };
+      preStart = ''
+        mkdir -m 0700 -p ${cfg.dataDir}
+        if [ "$(id -u)" = 0 ]; then chown -R elasticsearch ${cfg.dataDir}; fi
+      '';
     };
 
     environment.systemPackages = [ pkgs.elasticsearch ];
@@ -108,8 +119,7 @@ in {
       name = "elasticsearch";
       uid = config.ids.uids.elasticsearch;
       description = "Elasticsearch daemon user";
-      home = es_home;
-      createHome = true;
+      home = cfg.dataDir;
     };
   };
 }