summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
authorDomen Kožar <domen@dev.si>2013-08-30 18:05:08 +0200
committerDomen Kožar <domen@dev.si>2013-08-30 18:05:08 +0200
commite45e62e078d5004415857bab59e54fc791d074f6 (patch)
treeb67277134021f31f3005128255caf5a84ccf1173 /modules
parent718efd02b68abe396d4198029ae7da6653202907 (diff)
parentc613ae7b829fdbf80c3057445a6a719799fa5404 (diff)
downloadnixlib-e45e62e078d5004415857bab59e54fc791d074f6.tar
nixlib-e45e62e078d5004415857bab59e54fc791d074f6.tar.gz
nixlib-e45e62e078d5004415857bab59e54fc791d074f6.tar.bz2
nixlib-e45e62e078d5004415857bab59e54fc791d074f6.tar.lz
nixlib-e45e62e078d5004415857bab59e54fc791d074f6.tar.xz
nixlib-e45e62e078d5004415857bab59e54fc791d074f6.tar.zst
nixlib-e45e62e078d5004415857bab59e54fc791d074f6.zip
merge
Diffstat (limited to 'modules')
-rw-r--r--modules/misc/ids.nix1
-rw-r--r--modules/module-list.nix1
-rw-r--r--modules/services/search/elasticsearch.nix115
3 files changed, 117 insertions, 0 deletions
diff --git a/modules/misc/ids.nix b/modules/misc/ids.nix
index fd1aca263564..6bb98c354dbc 100644
--- a/modules/misc/ids.nix
+++ b/modules/misc/ids.nix
@@ -102,6 +102,7 @@ in
     quassel = 89;
     amule = 90;
     minidlna = 91;
+    elasticsearch = 92;
 
     # When adding a uid, make sure it doesn't match an existing gid.
 
diff --git a/modules/module-list.nix b/modules/module-list.nix
index 20ad0a014f1a..b50be9c34fa9 100644
--- a/modules/module-list.nix
+++ b/modules/module-list.nix
@@ -188,6 +188,7 @@
   ./services/scheduling/atd.nix
   ./services/scheduling/cron.nix
   ./services/scheduling/fcron.nix
+  ./services/search/elasticsearch.nix
   ./services/security/clamav.nix
   ./services/security/fprot.nix
   ./services/security/frandom.nix
diff --git a/modules/services/search/elasticsearch.nix b/modules/services/search/elasticsearch.nix
new file mode 100644
index 000000000000..6dfabc7e3053
--- /dev/null
+++ b/modules/services/search/elasticsearch.nix
@@ -0,0 +1,115 @@
+{ 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";
+      types = type.uniq types.string;
+    };
+
+    port = mkOption {
+      description = "Elasticsearch port to listen for HTTP traffic";
+      default = "9200";
+      types = type.uniq types.string;
+    };
+
+    tcp_port = mkOption {
+      description = "Elasticsearch port for the node to node communication";
+      default = "9300";
+      types = type.uniq types.string;
+    };
+
+    cluster_name = mkOption {
+      description = "Elasticsearch name that identifies your cluster for auto-discovery";
+      default = "elasticsearch";
+      types = type.uniq types.string;
+    };
+
+    extraConf = mkOption {
+      description = "Extra configuration for elasticsearch";
+      default = "";
+      types = type.uniq types.string;
+      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 = ''
+        rootLogger: DEBUG, console
+        logger:
+          action: DEBUG
+          com.amazonaws: WARN
+        appender:
+          console:
+            type: console
+            layout:
+              type: consolePattern
+              conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"
+      '';
+      types = type.uniq types.string;
+    };
+  };
+
+  ###### 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;
+    };
+  };
+}