-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java: Populate $out/lib/jvm
#312887
base: staging
Are you sure you want to change the base?
java: Populate $out/lib/jvm
#312887
Conversation
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/auto-detecting-java-installations/4677/11 |
/share/jvm
$out/share/jvm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only Nix beginner, so I can't review Nix files reliably.
One comment (concern) about the new location pattern to be founded here (share
instead of lib
).
Otherwise, the concept LGTM.
I'm somewhat reluctant about this change:
Having let this simmer for a while, I think I would prefer the approach of having each JDK contribute itself to a That said, as this topic has been stagnant for a while, I'd be supportive of this change as well, just to get things unstuck and gain some more experience on how this works out in practice ;) |
In response to @raboof:
I agree. This is not the intended use-case here. I mention how it is possible to pass JDKs to Gradle, for example, which fits this use-case.
This is why it is opt-in (currently tied to
I believe that this is also useful with let
pkgs = import ./default.nix {};
env = pkgs.buildEnv {
name = "development";
paths = with pkgs; [
(adoptopenjdk-hotspot-bin-8 // { meta.priority = 6; })
(adoptopenjdk-hotspot-bin-11 // { meta.priority = 5; })
];
};
in
pkgs.mkShellNoCC {
packages = [ env ];
shellHook = ''
echo "Your JVMs are in '${env}/lib/jvm' check it out:"
ls -o ${env}/lib/jvm
'';
} This gives you:
I know that this is your preferred approach, I have linked #76699 above, but I think that what I am proposing here both fits the "Nix way" (convention on derivation outputs instead of environment variables) and also the "Java ecosystem way" (crawling magic directories). |
Forgive the bikeshedding, but why Edit: Oops, I see this was already raised here. |
$out/share/jvm
$out/lib/jvm
Description of changes
This change should make it easier to detect available JDKs by providing symlinks at the canonical location
$out/lib/jvm/$name
.In the Java ecosystem, this is a common pattern. For example, the Gradle build tool supports "crawling" many of those locations:
/usr/lib{,64}/jvm
,{/opt,/usr/{,local/}}java
$HOME/.jdks
$HOME/.sdkman/candidates
The Scala tool sbt follows does something very similar and an attempt to integrate with NixOS has stalled.
There's been some discussion about how to make integration of these tools with NixOS easier, see https://discourse.nixos.org/t/4677 and an earlier attempt at #76699
Since the attempts by @raboof, I have made some progress with Gradle in #119444. The approach gives more control but is not ergonomic since it requires overriding Gradle to pass in JDKs. Note that this proposal is not meant to replace passing toolchains to Gradle but proposed in addition.
Recently @kravemir has reignited the discussion and has suggested to implement detection based on environments/profiles in gradle/gradle#29214 (comment). This PR is an attempt to standardize a detection location per-derivation, namely
$out/lib/jvm/$name
and to enable linking these paths whenever someone setsprograms.java.enable
.A hook is provided so that all JDKs can use the same code for creating the symlink.
Once this has landed, it'd be possible to have tools like Gradle and sbt crawl
/run/current-system/sw/lib/jvm
,~/.nix-profile/lib/jvm
, or other locations vianix-shell
.For now I have only changed four JDKs, but that should be sufficient to see what's going on and test the approach. Of course I am happy to add the hook to other JDKs too.
Alternative Considered
I also considered generating a
pkgs.linkFarm
in the Java module, but this solution is not as portable. By creating the link in each derivation, downstream package consumers can also make use of the mechanism, e.g. home-manager could also link them somewhere without having to reimplement linking.Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.