How to specify jvm option in java packages

So lets say there is an application with wrapper that executes ${jre}/bin/java -jar/cp ...
And I want to run this application specifying some custom jvm option such as -Xmx, which must be specified between java and -jar/-cp. Nearly all the java application are packaged in way, which makes it impossible. Like in example below:

I thought of two ways, either adding options as package function arguments, or adding JAVA_OPTS to wrapper. Later approach seem more flexible. But I only was able to find 1 package that used this approach.

What is the common approach to deal with setting custom JVM options?

Sorry I am a java noob - but what about setting the custom JVM options in an module for the pkgs - like here in the apache-kafka module? - https://github.com/NixOS/nixpkgs/blob/d02ffbbe834b5599fc5f134e644e49397eb07188/nixos/modules/services/misc/apache-kafka.nix#L133

That’s the first of the two ways already mentioned, right? See also various extraJavaOptions.

For the sake of completeness I think users could also:

  • Wrap a jre with additional arguments and pass it via override
  • Inject additional arguments by string manipulation via overrideAttrs

There doesn’t seem to be a clear convention. It would be nice to have something as ubiquitous as gappsWrapperArgs.

1 Like

I could do that, but than I would have to replicate all the options passed in the wrapper. Also, if it’s a CLI app, I would have to make a custom wrapper and make it available in Path. I mean it’s a solution, but I am wondering if there is any cleaner way to this.

1 Like