`stack setup` fails to compile a sanity check #21744

Closed
jdagilliland opened this Issue Jan 8, 2017 · 6 comments

Projects

None yet

2 participants

@jdagilliland
Contributor

Issue description

stack setup fails to install a sanity check even after deleting ~/.stack/, however works in a nix-shell.
I'm not sure what I need to do in order to get ordinary stack commands to run in my regular nix environment.

Steps to reproduce

-> % nix-env -q gcc-wrapper gmp stack | cat -
gcc-wrapper-5.4.0
gmp-6.1.1
stack-1.3.2
-> % rm -rf ~/.stack
-> % stack setup
Using latest snapshot resolver: lts-7.14
Writing implicit global project config file to: /home/jdag/.stack/global-project/stack.yaml
Note: You can change the snapshot via the resolver field there.
Downloaded lts-7.14 build plan.    
Fetched package index.                                                                                    
Populated index cache.    
Preparing to install GHC to an isolated location.
This will not interfere with any system-level installation.
Downloaded ghc-8.0.1.                                      
Installed GHC.                                                                
The GHC located at /home/jdag/.stack/programs/x86_64-linux/ghc-8.0.1/bin/ghc failed to compile a sanity check. Please see:

    http://docs.haskellstack.org/en/stable/install_and_upgrade/

for more information. Exception was:
Running /home/jdag/.stack/programs/x86_64-linux/ghc-8.0.1/bin/ghc /tmp/stack-sanity-check4023/Main.hs -no-user-package-db in directory /tmp/stack-sanity-check4023/ exited with ExitFailure 1

[1 of 1] Compiling Main             ( /tmp/stack-sanity-check4023/Main.hs, /tmp/stack-sanity-check4023/Main.o )
Linking /tmp/stack-sanity-check4023/Main ...

/nix/store/zgnh07lr5l9i3jnvl3b8ikkgfs23llnx-binutils-2.27/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)

However, when I re-run the command inside a nix-shell, I get a quite different result:

-> % nix-shell -p gcc -p gmp -p stack

[nix-shell:~]$ stack setup
stack will use a sandboxed GHC it installed
For more information on paths, see 'stack path' and 'stack exec env'
To use this GHC and packages outside of a project, consider using:
stack ghc, stack ghci, stack runghc, or stack exec

Technical details

  • System:
-> % lsb_release -a
No LSB modules are available.
Distributor ID: BunsenLabs
Description:    BunsenLabs GNU/Linux 8.6 (Hydrogen)
Release:        8.6
Codename:       bunsen-hydrogen

It's Debian Jessie basically

  • Nix version:
-> % nix-env --version
nix-env (Nix) 1.11.5
  • Nixpkgs version: (run nix-instantiate --eval '<nixpkgs>' -A lib.nixpkgsVersion)
-> % nix-instantiate --eval '<nixpkgs>' -A lib.nixpkgsVersion
"17.03pre98398.7215118"
@jdagilliland jdagilliland changed the title from `stack setup` fails to compile a sanity check to `stack setup` fails to compile a sanity check label:"6.topic: haskell" Jan 8, 2017
@jdagilliland jdagilliland changed the title from `stack setup` fails to compile a sanity check label:"6.topic: haskell" to `stack setup` fails to compile a sanity check Jan 8, 2017
@peti
Member
peti commented Jan 10, 2017 edited

Apparently, your host system lacks libgmp:

ld: cannot find -lgmp

The library is available in the Nix shell environment because Nix provides it, but outside of the Nix the library is missing.

@jdagilliland
Contributor

But my stack executable comes from Nix:

-> % readlink -f $(which stack)
/nix/store/ic8kcv1sanm922h9xq75x52p51gqm0i5-stack-1.3.2/bin/stack

And as you can see from the original traceback, my ld executable comes from Nix too, and I have libgmp installed in Nix.

I guess my real question is: given that I can get gmp inside a Nix-shell, how can I make the same resource available to tools I use under Nix, without being inside a Nix-shell.

@peti
Member
peti commented Jan 11, 2017

my ld executable comes from Nix too, and I have libgmp installed in Nix.

There is not such thing as installing something "in Nix". The Nix ld has no default paths whatsoever. If you want it to find libgmp, then you'll have to tell it (or rather, tell stack) where to look for it.

how can I make the same resource available to tools I use under Nix, without being inside a Nix-shell.

You have to configure appropriate search paths, i.e. those that nix-shell configures for you when running inside of it.

@jdagilliland
Contributor

That makes perfect sense. Sometimes I forget that Nix isn't all encompassing magic. However, might it make sense for me to try to augment the nix expression for stack so that it is able to find libs installed by Nix on which it depends? I'm not sure how to do that (yet), but am willing to give it a whirl.
Or would it make more sense to try to add ~/.nix-profile/lib to something like $LD_LIBRARY_PATH in my profile?

I guess if I got desperate I could sudo aptitude install libgmp-dev on Debian, but that feels like a cop out.

@peti
Member
peti commented Jan 13, 2017

There's at least a dozen different way to accomplish what you want. I'll just mention the simplest solutions to get you started. First, determine the paths to libgmp:

$ gmplib=$(nix-build --no-out-link "<nixpkgs>" -A gmp.out)/lib
$ gmpinc=$(nix-build --no-out-link "<nixpkgs>" -A gmp.dev)/include

Now, run stack with the arguments --extra-include-dirs=$gmpinc --extra-lib-dirs=$gmplib. Or configure those paths in ~/.stack/config.yaml globally so that don't have to bother typing them on the command line. Alternatively, install libgmp into a nix-env user profile, like

$ nix-env -p /nix/var/nix/profiles/$USER/libgmp -f "<nixpkgs>" -iA gmp

..., and use the paths /nix/var/nix/profiles/$USER/libgmp/{include,lib} instead, which have advantage that they remain valid after after you've update to a new library version, i.e. by running:

$ nix-env -p /nix/var/nix/profiles/$USER/libgmp -f "<nixpkgs>" -u

Last but not least, it's probably a bad idea to use stack setup at all when you have Nix available and chances are that you'll be much better off with stack's Nix support, i.e. by specifying the --nix flag.

@peti peti closed this Jan 13, 2017
@jdagilliland
Contributor

Thanks for the awesome advice! I'll try out some of those options and see how I do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment