Why does Nix have Haskell packages that are incompatible with GHC for a given version?

In the process of trying to build a Haskell application with Nix I ran into the following situation.

I use amazonka, which works well with GHC 8.8.4 and 8.10.7. I then tried to use ghc810 in my flake but when things wouldn’t work, I wanted to debug it in a repl. So I did the following in a Nix repl:

:lf .#
pkgs = import inputs.nixpkgs {}
pkgs.lib.getVersion pkgs.haskell.packages.ghc810.modern-uri

This is surprising since modern-uri requires base (>=4.15 && <5.0) but according to wiki.haskell.org GHC 8.10.7 has base

I’m probably not understanding how all of this works but to me it looks like the modern-uri you get with ghc810 shouldn’t ever compile? I created an example repository that hopefully demonstrates the issue.

$ nix run
error: builder for '/nix/store/bx4r1zbif27w4s12ffcnm4nxyvc9w7ff-modern-uri-' failed with exit code 1;
       last 10 log lines:
       >   $, called at libraries/Cabal/Cabal/Distribution/Simple/Configure.hs:1024:20 in Cabal-
       >   configureFinalizedPackage, called at libraries/Cabal/Cabal/Distribution/Simple/Configure.hs:477:12 in Cabal-
       >   configure, called at libraries/Cabal/Cabal/Distribution/Simple.hs:625:20 in Cabal-
       >   confHook, called at libraries/Cabal/Cabal/Distribution/Simple/UserHooks.hs:65:5 in Cabal-
       >   configureAction, called at libraries/Cabal/Cabal/Distribution/Simple.hs:180:19 in Cabal-
       >   defaultMainHelper, called at libraries/Cabal/Cabal/Distribution/Simple.hs:116:27 in Cabal-
       >   defaultMain, called at Setup.hs:6:8 in main:Main
       > Setup: Encountered missing or private dependencies:
       > base >=4.15 && <5.0
       For full logs, run 'nix log /nix/store/bx4r1zbif27w4s12ffcnm4nxyvc9w7ff-modern-uri-'.
error: 1 dependencies of derivation '/nix/store/dnn4cc3rdmyla3c4nfjki5b7cpg47573-ghc-8.10.7-with-packages.drv' failed to build
error: 1 dependencies of derivation '/nix/store/d7wshyf6xxncmc1bfghlm2q9h8h4ldpa-nix-shell-env.drv' failed to build

Interesting, I wonder why too.

Have you considered asking in the haskell discourse/reddit instead?

It seems like a Nix problem because the example repository I created works just fine with Cabal. Cabal selects a version of modern-uri that satisfies all constraints. But, and that’s my theory, the Haskell packages set in Nixpkgs only ever contains a single version of every package, there’s not much to choose here.

nixpkgs uses the same set of haskell package versions for all GHC versions. It is generated from stackage, along with having all other hackage packages not included in stackage just set to their latest versions. So a package is most likely to work if it’s A) in the stackage snapshot, and B) using the same GHC version as that stackage snapshot. Otherwise it might be a bit of a crapshoot. We do have specific fixups for different haskell package sets in the pkgs/development/haskell-modules/configuration-ghc-VERSION.nix files, but these are pretty ad-hoc and not at all comprehensive.


I see, thank you. In that case I’ll probably just ditch Nix and just use Cabal.

There are other tools, like haskell.nix, that can create haskell package sets that match your cabal build plan, rather than using the stackage snapshot in nixpkgs.