Why do some SDKs and emulators installed through IntelliJ don't work in NixOS?

Apparently IntelliJ IDEA (from nixpkgs) can’t install its own JDK for some reason and I might have to install and point to it manually.

This has led me to the titles question.

Also this has led me to believe that the same problem occurs in my Android Studio emulator problem (since I would get the same error as below when trying to run the emulator manually)

P.S.: Here’s the error from the failing IDEA Java execution:

/home/ari/.jdks/jbr-17.0.9/bin/java’: No such file or directory

Even though it’s there.

1 Like

It’d be helpful to see the output of the command:

ldd /home/ari/.jdks/jbr-17.0.9/bin/java
1 Like

Thank you @doronbehar! Here is its output:

❯ ldd /home/ari/.jdks/jbr-17.0.9/bin/java
	linux-vdso.so.1 (0x00007ffee6794000)
	libz.so.1 => not found
	libjli.so => /home/ari/.jdks/jbr-17.0.9/bin/../lib/libjli.so (0x00007f8f3ee70000)
	libpthread.so.0 => /nix/store/1zy01hjzwvvia6h9dq5xar88v77fgh9x-glibc-2.38-44/lib/libpthread.so.0 (0x00007f8f3ee6b000)
	libdl.so.2 => /nix/store/1zy01hjzwvvia6h9dq5xar88v77fgh9x-glibc-2.38-44/lib/libdl.so.2 (0x00007f8f3ee66000)
	libc.so.6 => /nix/store/1zy01hjzwvvia6h9dq5xar88v77fgh9x-glibc-2.38-44/lib/libc.so.6 (0x00007f8f3ec7d000)
	/lib64/ld-linux-x86-64.so.2 => /nix/store/1zy01hjzwvvia6h9dq5xar88v77fgh9x-glibc-2.38-44/lib64/ld-linux-x86-64.so.2 (0x00007f8f3ee89000)
	libz.so.1 => not found

For now the solution seems to be to download the desired JDK from nixpkgs, find it in the /nix/store, add its path (with /lib/openjdk appended to it) to the SDK section of Platform Settings inside Project Stucture and choose this new SDK in Project Settings in order to use it.

Doesn’t sound good to me - this path will get lost when you update your system and you’d collect garbage. You could achieve the exact same experience with using the desired JDK in environment.systemPackages, and use the path from /run/current-system/sw/bin/java.

Also if you don’t want to make it globally available, because it is a too specific JDK, you could also use something like this in your system configuration:

    environment.extraSetup = ''
      ln -s ${pkgs.jdk17}/bin/java $out/bin/java17
    '' 

If you also need the other files from ${jdk17}/lib, you can also add:

      ln -s ${pkgs.jdk17}/lib $out/lib/jdk17
1 Like

You are talking about the Nix attribute jetbrains.idea right?

Interesting… Could you try and run the same ldd command, from within the IDE? I’m sure there is a Bash shell option there or alike Inside it you should have the $LD_LIBRARY_PATH including zlib, according to:

And:

I think so. It’s the pkgs.jetbrains.idea-community from nixos-unstable from inside my Home Manager flake.

From that execution it appears that libz is sourced from a different hash than the other libs:

From IDE ❯ ldd /home/ari/.jdks/jbr-17.0.9/bin/java                         
        linux-vdso.so.1 (0x00007ffc985b6000)
        libz.so.1 => /nix/store/bqwpsy99nbgp918w3mwn73jygm1i5ck4-zlib-1.3.1/lib/libz.so.1 (0x00007f8fbceee000)
        libjli.so => /home/ari/.jdks/jbr-17.0.9/bin/../lib/libjli.so (0x00007f8fbcedc000)
        libpthread.so.0 => /nix/store/1zy01hjzwvvia6h9dq5xar88v77fgh9x-glibc-2.38-44/lib/libpthread.so.0 (0x00007f8fbced7000)
        libdl.so.2 => /nix/store/1zy01hjzwvvia6h9dq5xar88v77fgh9x-glibc-2.38-44/lib/libdl.so.2 (0x00007f8fbced2000)
        libc.so.6 => /nix/store/1zy01hjzwvvia6h9dq5xar88v77fgh9x-glibc-2.38-44/lib/libc.so.6 (0x00007f8fbcce9000)
        /lib64/ld-linux-x86-64.so.2 => /nix/store/1zy01hjzwvvia6h9dq5xar88v77fgh9x-glibc-2.38-44/lib64/ld-linux-x86-64.so.2 (0x00007f8fbcf13000)

And that indeed appears to be set by $LD_LIBRARY_PATH :

From IDE ❯ echo $LD_LIBRARY_PATH
/nix/store/bqwpsy99nbgp918w3mwn73jygm1i5ck4-zlib-1.3.1/lib:/nix/store/j2k44gyws2wlx3xrkv54zv0nhjihr0a5-pipewire-1.0.1-jack/lib

Yes that makes sense. Then what happens when you try to run that java from that IDE shell? Does it also give the No such file or directory error as reported originally?

Yes, the IntelliJ-installed java fails:

From IDE ❯ nice -n 10 /home/ari/.jdks/jbr-17.0.9/bin/java
nice: ‘/home/ari/.jdks/jbr-17.0.9/bin/java’: No such file or directory

So I guess the solution is to manage the SDKs through additional Nix configuration (as pointed by you) and not rely on JetBrains’ installations for now.

Yes I guess so… It is indeed one of the drawbacks of NixOS, that sometimes it’s impossible to further investigate why these outside-world binaries won’t run…

In your case, I suspect that this java executable executes other binaries from somewhere, that have missing libraries, like I suspected zlib to be a missing library. The way to further debug this is to run strace ~/.jdks/jbr-17.0.9/bin/java and find out what happens there. I’m not familiar with this kind of debugging so I won’t be able to further help.

If you will find the binary with the missing library, I’d be glad to help review a PR to Nixpkgs.

Anyways, thanks for all of the info you’ve provided. Was a pleasure interacting with you. And I’ll probably not look into strace unless I run into more problems.