Always symlinking the latest "jdk" to a certain path

Since IntelliJ keeps forgetting the JDK I set for a project, I was thinking: could I automatically link the latest jdk (meaning whatever I get when I nix-shell -p jdk) to a certain path? For example /opt/jdk or something?

For my user, I can certainly do nix-build -A jdk '<nixpkgs>' --out-link ~/jdk, but that doesn’t get updated as the system upgrades.

For NixOS you can check how /bin/sh is staticly created:

If you install OpenJDK system-wide on NixOS, you should be able to use /run/current-system/sw/lib/openjdk/ ;).

1 Like

I use this approach:

  environment.etc = with pkgs; {
    "jdk".source = jdk;
    "jdk8".source = jdk8;
    "jdk12".source = jdk12;
  };

which gives:

$ ls -l /etc/jdk*
lrwxrwxrwx 1 root root 15 Jun  3 07:38 /etc/jdk -> /etc/static/jdk
lrwxrwxrwx 1 root root 17 Jun  3 07:38 /etc/jdk12 -> /etc/static/jdk12
lrwxrwxrwx 1 root root 16 Jun  3 07:38 /etc/jdk8 -> /etc/static/jdk8

$ ls -l /etc/static/jdk*
lrwxrwxrwx 3 root root 60 Dec 31  1969 /etc/static/jdk -> /nix/store/16fgzv12dnlwbblxrmnf132jb2y2jg5v-openjdk-8u212-ga
lrwxrwxrwx 2 root root 57 Dec 31  1969 /etc/static/jdk12 -> /nix/store/z8mdrhyp1jxn9jxwsl2qkkw59qj9md0j-openjdk-12-ga
lrwxrwxrwx 3 root root 60 Dec 31  1969 /etc/static/jdk8 -> /nix/store/16fgzv12dnlwbblxrmnf132jb2y2jg5v-openjdk-8u212-ga
1 Like

@Jerith Thanks, this is the method I now use!