Fix collision with multiple JDKs

I am trying to install multiple versions of adoptopenjdk-bin from NUR for use in intellij. When I add adoptopenjdk-bin and adoptopenjdk-hotspot-bin-11 to my confugration I get a collision error.

collision between `/nix/store/dgxdsvyh3g3g5k23byh1mkzc1byl0icj-adoptopenjdk-hotspot-bin-11.0.9/include/classfile_constants.h' and `/nix/store/9am56df31z5yjnqbbdvn2szyn2g7cagg-adoptopenjdk-hotspot-bin-15.0.1/include/classfile_constants.h'
builder for '/nix/store/fii313k5rkklxn7nac4vn3jfjqvpld1c-home-manager-path.drv' failed with exit code 25
cannot build derivation '/nix/store/r423gz1khbc15ryhs7aqfipy62nqlip0-home-manager-generation.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/151rb79n5ssl30cs4b4p7mygyrcg9k7z-activate-john.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/hb39qv66h0cikbslhywcyif2di4as2lp-unit-home-manager-john.service.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/ywd6rjr6irjvpajiashr74bp9whj54dg-system-units.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/bs7ml80pzjibrczjnm0m2n4gfchd55ys-etc.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/ydqgswplziqb40d4ifcx8y26jvwyrkvz-nixos-system-n2-20.09.2405.e065200fc90.drv': 1 dependencies couldn't be built
error: build of '/nix/store/ydqgswplziqb40d4ifcx8y26jvwyrkvz-nixos-system-n2-20.09.2405.e065200fc90.drv' failed

I believe what I need to do is similar to –set-flags but in the configuration file. Is there any guidance on how this is done? Is it a package override of some kind?

I’m using home-manager but I think the solution would be similar to a normal configuration.nix file.

 15     nur = import <nur> { inherit pkgs; };                                       
 16   in {                                                                          
 17     nixpkgs.config.allowUnfree = true;                                          
 18     nixpkgs.overlays = [                                                        
 19       nur.repos.moaxcp.overlays.use-moaxcp-nur-packages                         
 20       nur.repos.moaxcp.overlays.use-latest                                      
 21     ];                                                                          
 22     home.packages = with pkgs; [                                                
 23       adoptopenjdk-bin                                                          
 24       adoptopenjdk-hotspot-bin-11 

The first overlay upgrades adoptopenjdk-bin to version 15 but I still want other versions installed for use in intellij. I think what I want is to set the priority metadata and to also set active to false for older versions. This will make sure the jdks are installed and available to intellij but not activated them in an environment.

It looks like I can override the priority. This is what I did.

 18     nixpkgs.overlays = [                                                        
 19       nur.repos.moaxcp.overlays.use-moaxcp-nur-packages                         
 20       nur.repos.moaxcp.overlays.use-latest                                      
 21     ];                                                                          
 22     home.packages = with pkgs; let                                              
 23       adoptopenjdk-hotspot-bin-11-low = adoptopenjdk-hotspot-bin-11.overrideAttrs(oldAttrs: {
 24         meta.priority = 10;                                                     
 25       });                                                                       
 26     in [                                                                        
 27       adoptopenjdk-bin                                                          
 28       adoptopenjdk-hotspot-bin-11-low  

Hey. You could link several JDKs to different paths. I use home manager for my case with Intellij.

{ pkgs, config, ... }:
let unstable = pkgs.nixos-unstable;
in {
  home.file."jdks/openjdk8".source = unstable.openjdk8;
  home.file."jdks/oraclejdk8".source = unstable.oraclejdk8;
  home.file."jdks/openjdk11".source = pkgs.openjdk11;
  home.file."jdks/scala".source = pkgs.scala;
}
1 Like

That is awesome! With directories in home it will be easier to find.

For future visitors:

{ pkgs, ... }:

let
  additionalJDKs = with pkgs; [ temurin-bin-11 temurin-bin-17 ];
in
{
  # ...
  programs.java = { /*...*/ };

  home.sessionPath = [ "$HOME/.jdks" ];
  home.file = (builtins.listToAttrs (builtins.map (jdk: {
    name = ".jdks/${jdk.version}";
    value = { source = jdk; };
  }) additionalJDKs));
}