Overriding the JDK for Gradle in a Nix Flake

You were close, but there’s no need for an overlay :slightly_smiling_face:

{
  description = "A very basic flake";

  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";

  outputs = { self, nixpkgs }: {

    devShells.x86_64-linux.default = let
        pkgs = import nixpkgs { system = "x86_64-linux"; };
        # choose our preferred jdk package
        jdk = pkgs.jdk21;
    in pkgs.mkShell {
        buildInputs = with pkgs; [
          jdk
          # customise the jdk which gradle uses by default
          (callPackage gradle-packages.gradle_8 {
            java = jdk;
          })
        ];
    };
  };
}
3 Likes