Search code examples
haskellcabalnixnixos

nixos 23.11 cabal install mysql-simple problem - "Missing (or bad) C libraries"


I want to install haskell library "mysql-simple" with cabal on nixos 23.11 (channell nixos-23.11), but get this error after cabal run:


cabal run
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
 - mysql-0.2.1 (lib:mysql) (requires build)
 - pcre-light-0.4.1.2 (lib) (requires build)
 - mysql-simple-0.4.9 (lib) (requires build)
 - p1-0.1.0.0 (exe:p1) (configuration changed)
Starting     pcre-light-0.4.1.2 (lib)
Starting     mysql-0.2.1 (all, legacy fallback)

Failed to build mysql-0.2.1. The failure occurred during the configure step.
Build log (
/home/se7en/.cache/cabal/logs/ghc-9.4.8/mysql-0.2.1-602cde24c6c6e4ef89d70ce439e4e60cb870a4ebccbf75cefa3ac608f3d7657a.log
):
[1 of 2] Compiling Main             ( /home/se7en/projects/p1/dist-newstyle/tmp/src-11473/mysql-0.2.1/dist/setup/setup.hs, /home/se7en/projects/p1/dist-newstyle/tmp/src-11473/mysql-0.2.1/dist/setup/Main.o )
[2 of 2] Linking /home/se7en/projects/p1/dist-newstyle/tmp/src-11473/mysql-0.2.1/dist/setup/setup
Configuring mysql-0.2.1...
Error: setup: Missing dependencies on foreign libraries:
* Missing (or bad) C libraries: zstd, ssl, crypto
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.If
the library files do exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 t
o see the error messages.


Failed to build pcre-light-0.4.1.2. The failure occurred during the configure
step.
Build log (
/home/se7en/.cache/cabal/logs/ghc-9.4.8/pcre-light-0.4.1.2-69c5bd37cd1682eb07c9608c0f2355b81c363c716828173fe447fc76354ade26.log
):
Configuring library for pcre-light-0.4.1.2..
Error: .cabal-wrapped: Missing dependency on a foreign library:
* Missing (or bad) C library: pcre
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
library file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.

Error: cabal: Failed to build mysql-0.2.1 (which is required by exe:p1 from
p1-0.1.0.0). See the build log above for details.
Failed to build pcre-light-0.4.1.2 (which is required by exe:p1 from
p1-0.1.0.0). See the build log above for details.

I expect mysql-simple library installed with cabal, but got this errors. Please help to fix this.


Solution

  • I think you can fix this by running cabal inside a nix shell with the C dependencies (and pkg-config for good measure):

    nix-shell -p pkg-config pcre zlib openssl