Unable to Use Guix Shell to run a different JVM version

Problem:

An older Clojure program works fine with openjdk@11.0.22:jdk but not with the newer versions. I want to use guix shell to use the older JVM.

My default JVM:

afm@fedora:~/data/repos/vessel-copy$ java --version
openjdk 21.0.2 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+-adhoc.nixbld.source)
OpenJDK 64-Bit Server VM (build 21.0.2+-adhoc.nixbld.source, mixed mode, sharing)

Now:

afm@fedora:~/data/repos/vessel-copy$ guix shell openjdk@11.0.22
afm@fedora:~/data/repos/vessel-copy [env]$ java --version
openjdk 21.0.2 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+-adhoc.nixbld.source)
OpenJDK 64-Bit Server VM (build 21.0.2+-adhoc.nixbld.source, mixed mode, sharing)

Gives me openjdk@21 instead of openjdk@11

When I look at PATH, I see the standard ~/.guix-profile/ but when I use the --search-paths option, I see a new path which, when added to PATH, makes the right java version available.

afm@fedora:~/data/repos/vessel-copy$ guix shell openjdk@11.0.22:jdk --search-paths
export PATH="/gnu/store/64p99r1l198n24rdzq60qqh579wr1w1p-profile/bin${PATH:+:}$PATH"
afm@fedora:~/data/repos/vessel-copy$ guix shell openjdk@11.0.22:jdk
afm@fedora:~/data/repos/vessel-copy [env]$ export PATH="/gnu/store/64p99r1l198n24rdzq60qqh579wr1w1p-profile/bin${PATH:+:}$PATH"
afm@fedora:~/data/repos/vessel-copy [env]$ java --version
openjdk 11.0.22 2024-01-16
OpenJDK Runtime Environment (build 11.0.22+0-adhoc..jdk-11.0.227)
OpenJDK 64-Bit Server VM (build 11.0.22+0-adhoc..jdk-11.0.227, mixed mode)

In summary, it seems as though guix shell is not setting the right paths. Moreover,

guix shell oepnjdk@11.0.22:jdk --check

hangs. This also suggests that there is something wrong with my set up that is mucking up PATH somehow.

Any suggestions/ideas appreciated!

Looks like you have configured environment variables incorrectly.
There is one mistake I made myself. It is mentioned in the manual in the section about guix shell --check.

Such problems usually indicate that the shell startup files are unexpectedly modifying those environment variables. For example, if you are using Bash, make sure that environment variables are set or modified in ~/.bash_profile and not in ~/.bashrc—the former is sourced only by log-in shells. See Bash Startup Files in The GNU Bash Reference Manual, for details on Bash start-up files.