It seems these should go in the ${configDir}/jvm.options"} (/var/lib/elasticsearch/config/jvm.options ?) looking at the package at https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/search/elasticsearch.nix

Possibly I could use the ES_JAVA_OPTS environment variable?

Using services.elasticsearch.extraJavaOptions does not work as it seems something is passing -Xms1g -Xmx1g by default:

Output from ps aux

elastic+ 21271 30.8 47.5 4456956 950968 ? Ssl 01:03 3:41 /nix/store/9c5a9fq2vd6qah77nmg87sjq5wbss1kj-openjdk-8u212-ga-jre/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch.uQNUAfPs -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Xms512m -Xmx512m -Des.path.home=/var/lib/elasticsearch -Des.path.conf=/var/lib/elasticsearch/config -Des.distribution.flavor=default -Des.distribution.type=tar -cp /var/lib/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch

  • Have you seen this, elastic.co/guide/en/elasticsearch/reference/current/… ? It is the first reference found by Googling elastisearch heap size. It contains the full answer to your question, including using an environment variable. – MariusMatutiae Feb 18 '19 at 8:49
  • I have - the difficulty is knowing how to integrate this ENVS / config with Nixos. – Chris Stryczynski Feb 18 '19 at 8:52
  • 1
    The jvm.options file is copied from the Nix store to /var/lib/elasticsearch/config/ every time ElasticSearch is started. Hence changes to the file would get overwritten. Assuming ES_JAVA_OPTS takes precedence over jvm.options, you can do something like services.elasticsearch.extraJavaOptions = [ "-Xms2g" "-Xmx2g" ] – Emmanuel Rosa Feb 18 '19 at 13:50

Perhaps a bit overkill but I'm not too sure how to override a Nixos service's parameters.

Essentially the default options are in .../jvm.options so I copied the elasticsearch.nix from Github and modified the following:

        ${optionalString es6 "sed -i '/-Xms1g/d' ${configDir}/jvm.options"}
        ${optionalString es6 "sed -i '/-Xmx1g/d' ${configDir}/jvm.options"}

Along with changing the name of the service (otherwise I'd assume it would conflict). I then just included this nix expression into my config and it seems to be working with the appropriate values set in ES_JAVA_OPTS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.