Give dependency paths to package: in package or in module?

Suppose I’m building a package for an app which runs off Java. It can already understand JAVA_HOME and JAVA environment variables.

So I basically have two options:

  • In package patchPhase, run find -exec sed to replace ${JAVA} with ${jre}/bin/java.
  • In module, set systemd.services.myname.environment.JAVA_HOME = "${pkgs.jre}".

Which one is preferrable? If the latter, do I rather mention jre in the package, or rather not and make them link at module stage rather than register a package-to-package dependency?

Program should be usable by themselves, so also outside of modules.

Likely the best solution here is to wrap the executables to set $JAVA_HOME and $JAVA_HOME in the package builder.

What I have done on several packages, as @FRidh suggests, is wrap the scripts. For example in micronaut

wrapProgram $out/bin/mn \
      --prefix JAVA_HOME : ${jdk} 
1 Like

Well it’s kinda usable, but with required env vars (so it is in its original downloadable ZIP form). Isn’t nice for a nix package then, to be left this way?

I’ll try the wrap thing.

wrapProgram also solves this, you can ensure that some env vars are present when the program is executed.