[NixOS] What else is needed to build the example project from 'New to Haskell'?

3,308 views
Skip to first unread message

Shane Pearman

unread,
Aug 20, 2015, 1:49:08 AM8/20/15
to haskell-stack
https://github.com/commercialhaskell/stack/wiki/New-to-Haskell

Running the final `stack build` command in this tutorial leaves me with a missing C library error:

    Configuring zlib-0.5.4.2...
   
Setup.hs: Missing dependency on a foreign library:
   
* Missing (or bad) header file: zlib.h
   
* Missing C library: z

I'm new to NixOS so I'm still learning the nixpkgs system and development environment. So far I have installed all nix packages declaratively in `/etc/nixos/configuration.nix`:

    environment.systemPackages = with pkgs; [
     
...
      haskellPackages
.ghc
      haskellPackages
.stack
      zlib
     
...

I've also tried packages `zlibStatic` and `haskellPackages.zlib` but `zlib` is still not found. I haven't tried specifying `--extra-include-dirs` or `--extra-lib-dirs` because I'm not sure how to properly point to the zlib files.

Shane Pearman

unread,
Aug 20, 2015, 9:51:53 AM8/20/15
to haskell-stack
After reading the NixOS documentation and searching I've found two simple ways to get the project to build:

1) Start a `nix-shell` with:

    $ nix-shell -p zlib

and `stack build` from there. This is probably the simplest, no extra files need to be created and no changes need to be made.

2) Write an appropriate shell.nix file, or use `cabal2nix` to generate one:

    $ cabal2nix project-name.cabal --sha256=0 --shell > shell.nix

and add `nixpkgs.zlib` to `libraryHaskellDepends` in shell.nix:

    mkDerivation {
      ...
      libraryHaskellDepends = [ base bytestring http-conduit nixpkgs.zlib ];
      ...
    };

and start `nix-shell` and run `stack build`. You can also run `stack build` without entering into the nix-shell prompt by passing it as a `--command` argument:

  $ nix-shell --command `stack build`

Adding `nixpkgs.zlib` to the cabal file as part of `build-depends:` or `extra-libraries:` both gave cabal2nix problems in generating a working shell.nix

And if this is completely the wrong way to do things let me know :)

Shane Pearman

unread,
Aug 20, 2015, 11:18:56 AM8/20/15
to haskell-stack
After playing around some more I found that if `zlib` is listed under `pkgconfig-depends:` in the cabal file then cabal2nix will generate a shell.nix file that doesn't need any further modification and will stack build successfully:

mkDerivation {
 
...
  libraryHaskellDepends
= [ base bytestring http-conduit ]
  libraryPkgconfigDepends
= [ zlib ]
 
...
};


Nicolas R

unread,
Aug 26, 2015, 11:06:00 AM8/26/15
to haskell-stack
thanks for posting

Nicolas

unread,
Aug 26, 2015, 12:55:49 PM8/26/15
to haskell-stack
As I understand it, stack and nix overlap here.

On the one hand, i'd love to have the curated set and consistency that stack provides.
On the other, I'd want the degree of total isolation that nix provides.

I am unsure how to have both. right now my emacs picks up whatever program is in my environment, not stack's environment.

Hopefully nixpkgs will provide some access to the curated stackage versioning

Mateusz Kowalczyk

unread,
Aug 26, 2015, 1:03:47 PM8/26/15
to haskel...@googlegroups.com
See

https://github.com/NixOS/cabal2nix/issues/184

for some discussion. There is no real problem with doing it, it just
needs someone to do the legwork. I encourage you to open an issue on
nixpkgs/cabal2nix repos asking for this or posting to the nix-dev
mailing list.

--
Mateusz K.

Diego Saa

unread,
Dec 21, 2015, 11:00:23 AM12/21/15
to haskell-stack
I added zlib to pkgconfig-depends, generated the shell.nix file with cabal2nix, and ran stack build from the nix shell, but I still get
<command line>: can't load .so/.DLL for: libz.so (libz.so: cannot open shared object file: No such file or directory)

Geraldus

unread,
Dec 21, 2015, 5:37:15 PM12/21/15
to Diego Saa, haskell-stack
Did you tried `nix-shell -p zlib`?  I had some issues with shell.nix approach, but first approach works for me.  

пн, 21 дек. 2015 г. в 21:00, Diego Saa <cuco...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "haskell-stack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-stac...@googlegroups.com.
To post to this group, send email to haskel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/haskell-stack/af258688-7e3f-430d-be22-5ce6f78d3206%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Geraldus

unread,
Dec 21, 2015, 5:37:56 PM12/21/15
to Diego Saa, haskell-stack
By the way, Shane Pearman, thanks for sharing!

вт, 22 дек. 2015 г. в 3:37, Geraldus <hera...@gmail.com>:

Артур Файзрахманов

unread,
Jan 2, 2016, 10:49:50 AM1/2/16
to haskell-stack

Well, I can build project, but can't run GHCi:

nix-shell -p zlib

[nix-shell:~/my-project]$ stack ghci
Using main module: Package `app' component exe:app-exe with main-is file: /home/gman/my-project/app/Main.hs
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: app
GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help

Mathieu Boespflug

unread,
Jan 27, 2016, 4:32:12 AM1/27/16
to Артур Файзрахманов, haskell-stack
This is due to a known GHC bug:



--
You received this message because you are subscribed to the Google Groups "haskell-stack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-stac...@googlegroups.com.
To post to this group, send email to haskel...@googlegroups.com.

Andika Riyandi

unread,
Mar 3, 2016, 11:50:02 PM3/3/16
to haskell-stack
i have try to create some nix-shell with the default.nix and shell.nix like this http://lpaste.net/153943 (default.nix) and shell-nix http://lpaste.net/153944
 
when i run nix-shell it says

"glpk and pcre is not found"

does stack need this two to be running properly in nix-shell? or this is not stack problem?

secondly, i tried to uninstall Stack which i installed inside nix-shell, but when i try to nix-env -e Stack, nothing happened. 

i already ask it in #nixos but no one response...

hope i can get answer in this group.

Geraldus

unread,
Mar 4, 2016, 1:28:26 PM3/4/16
to Andika Riyandi, haskell-stack
Sorry, as for me I do not have NixOS installation at this moment, a shortage of time didn't let me to learn nix concepts any deeper so I decided to leave it (at least for now).

пт, 4 мар. 2016 г. в 9:50, Andika Riyandi <andika...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "haskell-stack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-stac...@googlegroups.com.
To post to this group, send email to haskel...@googlegroups.com.

Pierre Radermecker

unread,
May 14, 2016, 4:33:51 PM5/14/16
to haskell-stack
It might be related to this issue: https://github.com/commercialhaskell/stack/issues/2130#issuecomment-219149275

There is a workaround described that might be of help.
Reply all
Reply to author
Forward
0 new messages