Stream: nix

Topic: Nix using incorrect GHC


view this post on Zulip Aman Singh (Feb 21 2024 at 10:02):

@Srid I have created this flake and want to add support for multiple version of ghc in my project.
While testing with GHC 8.10.7 I noticed that dependencies were complaining of base package being different than expected.

Below is my flake.nix

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs";
  };

  outputs = {self, nixpkgs}:
    let
        system = "x86_64-darwin";
        pkgs = nixpkgs.legacyPackages.${system};
        overlay = final: prev: {
          isomorphism-class = pkgs.haskell.lib.dontCheck (pkgs.haskell.lib.doJailbreak prev.isomorphism-class);
          hspec = pkgs.haskell.lib.doJailbreak prev.hspec;
          servant = pkgs.haskell.lib.doJailbreak prev.servant;
          aeson = pkgs.haskellPackages.callHackage "aeson" "1.5.6.0" {};
          test = final.callCabal2nix "test" ./. {};
        };
      myHaskellPackages = pkgs.haskell.packages.ghc8107.extend overlay;
    in
    {
      packages.${system}.default = myHaskellPackages.test;
    };
  }

I noticed that aeson is being built with GHC 9.4.8. After checking it's derivation build logs.

$ nix-store -l /nix/store/vmpqkhqcpcnhj0q29lmzbs7zxsnmwcw8-aeson-1.5.6.0.drv

@nix { "action": "setPhase", "phase": "setupCompilerEnvironmentPhase" }
Running phase: setupCompilerEnvironmentPhase
Build with /nix/store/ckgd7ip5m9xid8xhr7qbz8iaxxfsnw7j-ghc-9.4.8.
@nix { "action": "setPhase", "phase": "unpackPhase" }
Running phase: unpackPhase
unpacking source archive /nix/store/bhbxs5cp61d3hmlakcsb5i21lbdqpfpm-aeson-1.5.6.0.tar.gz
source root is aeson-1.5.6.0
setting SOURCE_DATE_EPOCH to timestamp 1000000000 of file aeson-1.5.6.0/tests/golden/th.expected
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: patchPhase
Replace Cabal file with edited version from mirror://hackage/aeson-1.5.6.0/revision/7.cabal.
@nix { "action": "setPhase", "phase": "compileBuildDriverPhase" }
Running phase: compileBuildDriverPhase
setupCompileFlags: -package-db=/private/tmp/nix-build-aeson-1.5.6.0.drv-1/tmp.SUGnXWZhew/setup-package.conf.d -j12 -threaded -rtsopts
[1 of 2] Compiling Main             ( Setup.lhs, /private/tmp/nix-build-aeson-1.5.6.0.drv-1/tmp.SUGnXWZhew/Main.o )
[2 of 2] Linking Setup
@nix { "action": "setPhase", "phase": "configurePhase" }
Running phase: configurePhase
configureFlags: --verbose --prefix=/nix/store/ral7v6f2xc6yi6axy53ln7d29a2cc6p8-aeson-1.5.6.0 --libdir=$prefix/lib/$compiler --libsubdir=$abi/$libname --docdir=/nix/store/mljk66bq4f5zskrn17gv8aiy43bkpfac-aeson-1.5.6.0-doc/share/doc/aeson-1.5.6.0 --with-gcc=clang --package-db=/private/tmp/nix-build-aeson-1.5.6.0.drv-1/tmp.SUGnXWZhew/package.conf.d --ghc-options=-j12 --disable-split-objs --enable-library-profiling --profiling-detail=exported-functions --disable-profiling --enable-shared --disable-coverage --enable-static --disable-executable-dynamic --enable-tests --disable-benchmarks --enable-library-vanilla --disable-library-for-ghci --ghc-options=-haddock --extra-lib-dirs=/nix/store/cday6lpb3xbxpswci75yp77q49jyjf97-ncurses-6.4/lib --extra-lib-dirs=/nix/store/3hxzjdfb88ni8f7h7xbqirsm7massl90-libffi-3.4.4/lib --extra-lib-dirs=/nix/store/dvb8a6g3vmzcckmdjgbcnkw7vpy5df0h-gmp-with-cxx-6.3.0/lib --extra-include-dirs=/nix/store/p8igv6f25sjhhk95wbvcvb82v1sybv10-libiconv-50/include --extra-lib-dirs=/nix/store/p8igv6f25sjhhk95wbvcvb82v1sybv10-libiconv-50/lib --extra-include-dirs=/nix/store/ymw82wxygwr9mia2qnh6a7pbw6jr2rjw-libcxx-16.0.6-dev/include --extra-lib-dirs=/nix/store/vj3mzjyppyjqpqs6k0v9hyr80abmp1ay-libcxx-16.0.6/lib --extra-include-dirs=/nix/store/b3l52c0yywpjqwzkg5f600m5r1njgwx8-libcxxabi-16.0.6-dev/include --extra-lib-dirs=/nix/store/jgzbk5v82s2da4fqd4pjnphpb0c9r351-libcxxabi-16.0.6/lib --extra-include-dirs=/nix/store/m2v3zscdv32dwn55k2wpxjfn42hpjrh4-compiler-rt-libc-16.0.6-dev/include --extra-lib-dirs=/nix/store/4zx1dv50bbj63z5nrh3wjhz22np1f862-compiler-rt-libc-16.0.6/lib --extra-framework-dirs=/nix/store/a55b69y2gdzkd4i4cnjx6agyq0p2bsav-apple-framework-CoreFoundation/Library/Frameworks
Using Parsec parser
Configuring aeson-1.5.6.0...
CallStack (from HasCallStack):
  withMetadata, called at libraries/Cabal/Cabal/src/Distribution/Simple/Utils.hs:370:14 in Cabal-3.8.1.0:Distribution.Simple.Utils
Error: Setup: Encountered missing or private dependencies:
bytestring >=0.10.8.1 && <0.11.2,
ghc-prim >=0.2 && <0.8,
hashable-time >=0.2.1 && <0.3,
primitive >=0.7.0.1 && <0.8,
template-haskell >=2.9.0.0 && <2.18,
text >=1.2.3.0 && <1.3,
vector >=0.12.0.1 && <0.13

In logs it's visible that aeson is using GHC 9.4.8. If I comment aeson from my flake.nix then it uses the correct GHC but it picks the latest aeson package.

How can I pin the aeson version and make it to use a specific GHC version ?

view this post on Zulip Aravind Gopal (Feb 21 2024 at 10:09):

My suggestion. Use Haskell-flake. basePackages param would define the version of ghc and overrides would also be compiled with that ghc version

view this post on Zulip Srid (Feb 21 2024 at 10:22):

@Aravind Gopal Here's first familiarizing himself with the basics before trying flake-parts and the rest.

view this post on Zulip Srid (Feb 21 2024 at 10:24):

@Aman Singh

The problem is here:

aeson = pkgs.haskellPackages.callHackage "aeson" "1.5.6.0" {};

pkgs.haskellPackages is the default haskell package set using GHC 9.4.8. Replace that with prev (just as you already do for the test package).

Also see https://nixos.wiki/wiki/Overlays

view this post on Zulip Srid (Feb 21 2024 at 10:26):

prev should refer to pkgs.haskell.packages.ghc8107, because you are passing that overlay to the extend function. Overlays are actually simple concept, to extend a Nix attrset. Their implementation is simple: https://github.com/NixOS/nixpkgs/blob/master/lib/fixed-points.nix

view this post on Zulip Aman Singh (Feb 22 2024 at 08:48):

Yeah, it worked. Didn't knew functions carried such context as well. I was able to build my project. Trying haskell-flake now.


Last updated: Nov 15 2024 at 12:33 UTC