Haskell's "stack" failing. Trouble understanding package system

I’m running NixOS in a virtual machine and I’m having this issue running “stack”:

error: attribute ‘ghc902’ missing, at (string):1:43
(use ‘–show-trace’ to show detailed location information)

I presume this is an issue because it can’t find ghc 9.02

I ran the following nix-env -qaPA 'nixos.haskell.compiler' (which I found on StackOverflow) and got the following result:

nixos.haskell.compiler.ghc8107                 ghc-8.10.7
nixos.haskell.compiler.ghc884                  ghc-8.8.4
nixos.haskell.compiler.ghc901                  ghc-9.0.1
nixos.haskell.compiler.ghc921                  ghc-9.2.1
nixos.haskell.compiler.ghcHEAD                 ghc-9.3.20211111
nixos.haskell.compiler.ghc8102Binary           ghc-binary-8.10.2
nixos.haskell.compiler.ghc8102BinaryMinimal    ghc-binary-8.10.2
nixos.haskell.compiler.ghc8107Binary           ghc-binary-8.10.7
nixos.haskell.compiler.ghc8107BinaryMinimal    ghc-binary-8.10.7
nixos.haskell.compiler.ghc865Binary            ghc-binary-8.6.5
nixos.haskell.compiler.integer-simple.ghc8107  ghc-integer-simple-8.10.7
nixos.haskell.compiler.integer-simple.ghc884   ghc-integer-simple-8.8.4
nixos.haskell.compiler.integer-simple.ghc901   ghc-integer-simple-9.0.1
nixos.haskell.compiler.integer-simple.ghc921   ghc-integer-simple-9.2.1
nixos.haskell.compiler.native-bignum.ghcHEAD   ghc-native-bignum-9.3.20211111
nixos.haskell.compiler.ghcjs                   ghcjs-8.10.7

This seems to confirm that NixOS can’t see ghc 9.0.2, just ghc 9.0.1

But what is weird is that I have ran sudo nixos-rebuild switch --upgrade but this makes no difference.

What makes it even more confusing when I search on Nix packages on the website https://search.nixos.org/packages?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=haskell.compiler I only find such packages in the unstable branch, not the stable branch.

I do have nixos-unstable in my nix-channels:

sudo nix-channel --list

nixos https://nixos.org/channels/nixos-21.11
nixos-unstable https://nixos.org/channels/nixos-unstable

But on the website, search, I see ghc 9.0.2, not ghc 9.0.1.

So I’m thoroughly confused. Anyone have any insights here?

Here’s two other threads that are at least somewhat related to what you’re trying to do:

If you can’t figure your problem out after reading through these two threads, feel free to ping me and I’ll try to give you a deeper explanation.

If you do figure out your problem, I encourage you to post your solution so that it helps the next person that stumbles on this post.

The stable channel takes precedence, there’s no fallback mechanism.

I’ll have a look through those threads.

But a point is raised in Can I use Haskell’s stack with nix run for a resolver not in my current nixpkgs? which I don’t think is answered there, which I quote:

What’s going on with https://search.nixos.org/packages having seemingly the wrong package list?

To obtain a list of packages, one has to evaluate nixpkgs, i.e. execute a turing complete programming language to yield a non uniformly structured package set. For performance (of normal nix-env usage) reasons a lot of stuff is hidden by default and has to be explicitly included when building the index for nixos-search. Nowadays, the haskell.compiler sub package set is indexed correctly.

TL;DR: A mixture of trade-offs and tech debt, but has been fixed since.