Same flake-id refers to different flakes in the registry?

Consider the following two ways to access the jdk17 package in nixpkgs.
The first:

$ nix develop nixpkgs#jdk17

$ which java

The second:

$ cat flake.nix 
  outputs = { nixpkgs, ... }:
    system = "x86_64-linux";
    pkgs = nixpkgs.legacyPackages.${system};
    devShells.${system}.default = pkgs.mkShell {
      packages = [ pkgs.jdk17 ];

$ nix develop

$ which java

I was expecting to get the same package since both ways get jdk17 from an indirection to the flake registry, but evidently, that is not what happened. I suspect it may have something to do with the flake registry and pins but have yet to find a concrete explanation after much toiling.
This versioning discrepancy is rather significant for me as I have a jar file that works with the 17.0.7 version but not the 17.0.11+9 one.
Any help would be greatly appreciated.

nix develop nixpkgs#jdk17refers to the nixpkgs pinned by your system registry.

The flake has its own lockfile, which is independent of the system registry (created the first time you use the flake and updated independently from the system registry).

You likely created the flake after your last system update or using a different release branch, hence the discrepancy.