Cannot change oraclejdk11 version via overlay

I’ve just run nix flake update and am trying to rebuild now. I can’t because I have to use oraclejdk11, which needs to be manually downloaded. However, I only find download links for v11.0.24, not v11.0.10 as packaged in NixOS 24.05

I’m therefore trying it with an overlay, which strangely doesn’t take any effect. This is my first time using overlays, so maybe I’m missing something?

I imports the following into my main config

# jdk.nix
{pkgs, ...}: {
  nixpkgs.overlays = [
    (final: prev: {
      oraclejdk11 = prev.oraclejdk11.overrideAttrs (_: {version = "11.0.24";});
    })
  ];
  environment.systemPackages = [
    pkgs.oraclejdk11
  ];
}

I still get the error

error: builder for '/nix/store/hbr81cf8ymz03cwzrl5jz3slq4882z5m-jdk-11.0.10_linux-x64_bin.tar.gz.drv' failed with exit code 1;
       last 10 log lines:
       > ***
       > Unfortunately, we cannot download file jdk-11.0.10_linux-x64_bin.tar.gz automatically.
       > Please go to https://www.oracle.com/java/technologies/javase-jdk11-downloads.html to download it yourself, and add it to the Nix store
       > using either
       >   nix-store --add-fixed sha256 jdk-11.0.10_linux-x64_bin.tar.gz
       > or
       >   nix-prefetch-url --type sha256 file:///path/to/jdk-11.0.10_linux-x64_bin.tar.gz
       >
       > ***
       >
       For full logs, run 'nix log /nix/store/hbr81cf8ymz03cwzrl5jz3slq4882z5m-jdk-11.0.10_linux-x64_bin.tar.gz.drv'.
error: 1 dependencies of derivation '/nix/store/9d43dlhh2n9ly19kvijpir28p5blln6f-oraclejdk-11.0.24.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ir4faw4jfd7jghr7cknn6id7gqjjyvhr-man-paths.drv' failed to build
error: 1 dependencies of derivation '/nix/store/3ijmzmngmy5nfhv73wadjzv1igag6kwq-oraclejdk-11.0.24_fish-completions.drv' failed to build
error: 1 dependencies of derivation '/nix/store/8fm773icjanbmcdc0b65b9hka5wji69v-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/3wbb9a6klaxik6r6xxj930vdhy18qnsp-nixos-system-nixos-24.05.20240916.086b448.drv' failed to build

Changing the version doesn’t change src. You need to override that as well.
Also, JDK is a dev package and is more suited for a dev shell (nix-shell or nix develop with some mkShell derivation)

Ah okay. I thought, since it’s a rec attr set and src uses version it would take effect, since it’s a lazy language. Is there a concise explanation for why it doesn’t?

rec is simply syntactic sugar and the values determined by evaluating the attrset in isolation are what are considered.

https://nixos.org/manual/nixpkgs/unstable/#mkderivation-recursive-attributes

Hmm makes sense. It’s a little unfortunate, but makes sense. If I attempted to write a derivation, would I have options to make it easier to change the version by overriding just the one field (even though it’s used multiple times internally)?

Yes, you can use the finalAttrs scheme mentioned at the link above, but only with some builders (stdenv.mkDerivation, and the nim and php builders iirc). Also you’ll still need to override the hash regardless.