How to create a development environment with Intellij IDEA and OpenJDK

I’m trying to create a Java delopment environment with the latest JDK and Jetbrain’s Intellij IDEA Ultimate.

To begin with I ran the command

$ nix-build '<nixpkgs>' -A jdk -o jdk

in my project directory (thanks @clever for the tip!) to get a stable link to the OpenJDK binary.

I’ve two different versions of shell.nix for the project. The first one create a regular shell environment containing the applications I want, and the second one creates a FHS environment. The first version looks like this:

{
	pkgs ? import <nixpkgs> {}
}:

pkgs.mkShell
{
	buildInputs =
	[
		pkgs.jdk
		pkgs.jetbrains.idea-ultimate
	];
}

I when enter the environment with nix-shell and start Intellij.

FindingJDK
(“Softsex” is not what you think what it is :wink: )

But when I try to add the JDK — using the symbolic link created by the previous command — in Intellij I get the error message

The selected directory points to a JRE, not a JDK.
You can download a JDK from https://www.oracle.com/technetwork/java/javase/downloads/index.html

Error message

@monty then suggested that I probably needed a FHS-environment. So I created a new version of the shell.nix file containing

{
	pkgs ? import <nixpkgs> {}
}:

(
	pkgs.buildFHSUserEnv
	{
		name = "foo";
		targetPkgs = pkgs:
		[
			pkgs.jetbrains.idea-ultimate
			pkgs.jdk
		];
	}
).env

but the error message still occur.

I was able to solve this issue by telling IntelliJ to use lib/openjdk instead of simply the path to the JDK. So /nix/store/...-openjdk/lib/openjdk instead of /nix/store/...-openjdk. Hope this helps!

3 Likes

Thanks @pimiddy! Your solution solved it for me! But I’m wondering why it works. :thinking:

Hi there,

I’m trying to reproduce this, but running into

[…]
Runnable configure script is not present

Generating runnable configure script at /private/tmp/nix-build-jetbrains-jdk-11_0_11-b1504.13.drv-0/source/build/.configure-support/generated-configure.sh

Autoconf is not found on the PATH, and AUTOCONF is not set.

You need autoconf to be able to generate a runnable configure script.

Error: Cannot find autoconf

builder for ‘/nix/store/y2mxc6p45rkniw25500ynjl7h80knh57-jetbrains-jdk-11_0_11-b1504.13.drv’ failed with exit code 1

cannot build derivation ‘/nix/store/0ki7sflqmzd54nym7hvv00zmadhc20ha-idea-ultimate-2021.2.drv’: 1 dependencies couldn’t be built

error: build of ‘/nix/store/0ki7sflqmzd54nym7hvv00zmadhc20ha-idea-ultimate-2021.2.drv’ failed
[…]

What am I missing?

Running on Mac OS
nix-repl> builtins.currentSystem “x86_64-darwin”

Did you ever solve this @m68funk ? I am seeing the same currently and even if I nix-env -i autoconf it doesn’t seem to recognize it. I also tried setting AUTOCONF to the installed binary path, no success either.

No I haven’t. But I also have not been digging that deep into it…