Select a default jdk implementation in a nix-shell derivation

This is where overlays are useful. For instance, this would use the same jdk everywhere:

let
  pkgs = import <nixpkgs> { overlays = [ (self: super: {
    jdk = super.adoptopenjdk-jre-openj9-bin-11;
  }) ]; };
in
with pkgs;
stdenv.mkDerivation {
  name = "clojure";
  nativeBuildInputs = [
    jdk
    lumo
    leiningen
    clojure
  ];
  buildInputs = [
    openssl
  ];
}

You have to be careful that this approach isn’t a mass rebuild (for instance, overriding something like stdenv will mean you must rebuild everything). But for jdk, it works well (the example above rebuilds clojure, leiningen, and lumo).

2 Likes