anchor.diff:        '';
         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 ];
  
positive.code: 
      port = mkOption {
        description = "Elasticsearch port to listen for HTTP traffic";
        default = "9200";
        type = types.str;
      };
  
      tcp_port = mkOption {
        description = "Elasticsearch port for the node to node communication";
        default = "9300";
        type = types.str;
      };
  
      cluster_name = mkOption {
  
negative.code:       name = "elasticsearch";
        uid = config.ids.uids.elasticsearch;
        description = "Elasticsearch daemon user";
        home = cfg.dataDir;
      };
    };
  }
  