Overriding GHC only for final package

I’ve written some GHC patches that affect only the Haskell RTS and the behaviour of GHCI.

How can I craft a nix expression such that all Haskell dependencies of my package come from cache.nixos.org as usual, but for the final application, my custom GHC is used?

I tried passing --with-ghc to Cabal, but that doesn’t have any of the dependencies, because the ghcWithPackages / ghc-with-packages derivation is constructed such that it has the packages in lib/ and the ghc in bin/, and if I give the GHC in there, Cabal will also use it for ghc-pkg.

I wonder if something like the following wouldn’t work for you:

with import ~/git/nixpkgs {};                                                                                                                                                             
                                                                                                                                                                                          
(haskellPackages.ghcWithPackages (p: [p.splitmix])).override {                                                                                                                            
  ghc = haskell.packages.integer-simple.ghc8107.ghc;                                                                                                                                      
} 

This builds a bunch of packages (including splitmix) with the normal GHC, but then puts you in an environment with the integer-simple GHC.


edit: This literal code won’t actually work as-is in a recent nixpkgs because of a problem with integer-simple I just found: ghcWithPackages environment doesn't build with integer-simple · Issue #153319 · NixOS/nixpkgs · GitHub. But the general approach should still be sound.

1 Like