Can't build haskell project with multiple components in cabal file

I am trying to build a haskell executable that depends on 2 internal libraries (basically just splitting the project up into components). Unfortunately nix can’t seem to find these.

This is the flake config:

      hsPkgs = pkgs.haskell.packages.${compilerVersion}.override {
        overrides = hfinal: hprev: {
          ## Project
          servicehub = 
              (hfinal.callCabal2nix "servicehub" ./. {});

          # External Packages

here is the (abridged) cabal file:

library database
  hs-source-dirs:  components/database

library server
  build-depends: database
  hs-source-dirs:  components/server

executable servicehub
  hs-source-dirs: app
  build-depends:  server

Here is the error when I run nix build

λ nix build
error: builder for '/nix/store/aay69s3mj7cp9w8bgh1dc88avzrijc0q-servicehub-0.drv' failed with exit code 1;
       last 10 log lines:
       > [2 of 2] Linking Setup
       > configuring
       > configureFlags: --verbose --prefix=/nix/store/a7xwcjyiffyglnsr8jpb9hn1z1lvpp7i-servicehub-0 --libdir=$prefix/lib/$compiler --libsubdir=$abi/$libname --with-gcc=gcc --package-db=/build/tmp.9iO5ilwQ3J/package.conf.d --ghc-options=-j16 +RTS -A64M -RTS --disable-split-objs --disable-library-profiling --disable-profiling --enable-shared --disable-coverage --enable-static --disable-executable-dynamic --enable-tests --disable-benchmarks --enable-library-vanilla --disable-library-for-ghci --ghc-option=-split-sections --extra-lib-dirs=/nix/store/q5mhssfls6iych80439511vz7539gd95-ncurses-6.4/lib --extra-lib-dirs=/nix/store/zi3wndir89vvbly8fkdwvq9v17vrpw8h-libffi-3.4.4/lib --extra-lib-dirs=/nix/store/q7ax2400mx46afnkcbfxfjddzgl4ck44-gmp-with-cxx-6.2.1/lib
       > Using Parsec parser
       > Configuring servicehub-0...
       > CallStack (from HasCallStack):
       >   withMetadata, called at libraries/Cabal/Cabal/src/Distribution/Simple/Utils.hs:370:14 in Cabal-
       > Error: Setup: Encountered missing or private dependencies:
       > database, server
       For full logs, run 'nix log /nix/store/aay69s3mj7cp9w8bgh1dc88avzrijc0q-servicehub-0.drv'.

As an update changing the references to the internal libraries as per the second bullet point here changed my error to this:

λ nix build
error: builder for '/nix/store/b72g0y8vkyqmgdhhznykkxybn2jqg7jg-servicehub-0.drv' failed with exit code 1;
       last 10 log lines:
       > Using strip version 2.40 found on system at:
       > /nix/store/nlgyw2fv0cm8rkz8qm1jyw78vyif1bl9-gcc-wrapper-12.2.0/bin/strip
       > Using tar found on system at:
       > /nix/store/lcfhnr6wrj9ssd3dxs39sprvz6qrxlj5-gnutar-1.34/bin/tar
       > No uhc found
       > building
       > Preprocessing library 'database' for servicehub-0..
       > Error: Setup: can't find source for Types/Orphans/Password in
       > components/database, dist/build/database/autogen, dist/build/global-autogen

Okay, forgot to git add . in the last post. The solution was the explicit internal library qualification in the cabal file.


executable my-package
  build-depends my-package:my-internal-lib

Glad you were able to figure this out. How about marking your last post as the solution?

1 Like