Stack new: error: attribute 'ghc' missing

Hi,
It seems that Stack wants to use a newer version of GHC, a version that is not present in my NixOS packages yet.
That hinders reproducibility a lot.
Yesterday it worked, and today it does not work any more.
On the same machine, without changing its configuration.
Am I missing anything?
Thanks for your help!

Can you figure out which channel it is using / what revision it is at and post the error message below? What stack resolver are you using?

The stack nix integration guesses what the GHC version it wants depending on the used resolver would be called and expects it to be found in <nixpkgs>. This goes wrong as we tend to clean up old GHC versions. We have the latest minor versions of the 8.8, 8.10, 9.0, 9.2 and 9.4 series currently.

In many cases the fix is to either:

  • Pin the used channel to a specific revision that has the desired GHC via the nix.path stack config directive.
  • Update the solver to its latest minor version (e.g. LTS-19.13 → LTS 19.33) which will usually have the latest GHC in the series.
1 Like

It complains that ghc925 is missing.
I don’t know how to do what you indicate.
I wonder why as a lambda user I should have anything to do at all.
Wouldn’t it be better if reproducibility was the default?
Thank you.

Then you most likely need to update your Nix channels, as GHC 9.5.2 was released relatively recently and subsequently added to nixpkgs.

The stack documentation I linked describes how to set a specific NIX_PATH just for the specific stack project, which allows you to pin a certain nixpkgs revision. Switching the resolver is as easy as changing a configuration value in stack.yaml.

Note that the latter doesn’t really apply to you, as you are using an apparently up to date resolver. People usually run into the opposite case that a GHC they need has been dropped from nixpkgs since it is quite outdated already.

Depends on what you mean by reproducibility – it is not magic after all.

The stack Nix integration (which we did not even write) can not feasably ensure that you have the package definitions available for any given GHC version. And we can’t package GHC 9.2.5 before it is released, so an outdated channel of course doesn’t include this version of the compiler.