Haskell Stack doesn't use system Ghc - haskell

I'm trying to use Haskell Stack to setup a project but using the stack provided ghc I am having a -fPIC error
GitHub issue
To bypass the fPIC problem I'm trying to use a package manager provided GHC using the 7.10.3 version (stack currently is using 8.0.2)
When I try to force stack to use the systm ghc it simply ignores me.
I've tried to override using /home/user/.stack/config.yaml and {project}/stack.yaml system-ghc : true option... but stack use the 8.0.2 version in the setup.
Am I missing something?
TL;DR
Stack ignore the system-ghc : true option
I'm runnig Sabayon 16
"haskell-primer" is the project name
stack list-dependencies
base 4.9.1.0
ghc-prim 0.5.0.0
haskell-primer 0.1.0.0
integer-gmp 1.0.0.1
rts 1.0

Setting system-ghc: true allows Stack to use the system GHC if it matches the resolver's constraints. It will not force Stack to use the system GHC if it does not match the constraints. If your resolver requires GHC 8 but your system has GHC 7 then Stack will not use your system GHC no matter what value you give system-ghc. Conversely, if system-ghc: false then Stack will never use the system GHC, regardless of whether its version matches.
From the Stack FAQ, emphasis mine:
If you would like stack to use your system GHC installation, use the --system-ghc flag or run stack config set system-ghc --global true to make stack check your PATH for a suitable GHC by default.
Note that stack can only use a system GHC installation if its version is compatible with the configuration of the current project, particularly the resolver setting.

Related

global GHC from Stack?

I have happily installed Stack, and run my code with stack ghci or stack exec and whatnot.
I would like to use vscode-haskell, and that requires a ghc available in the PATH.
Is it possible to create a ghc command available globally using stack? (e.g. some suitable commans in my powershell/bash profile)
ps. Close duplicates that did not help me are
Using stack ghc as replacement of ghc but only talks about makefiles
Haskell Stack doesn't use system Ghc is about making Stack use a system GHC if it is available which is not the case for me
Haskell stack with global ghc which is close to a dupplicate of [2]

Is there a way for `stack --nix` to allow newer versions of ghc to be used?

I'm running stack --nix init for a new project (xmonad config) and getting error: attribute 'ghc863' missing, at (string):1:43; I have ghc 8.6.5 in the environment, and stack --version reports: 2.1.3.1 x86_64 hpack-0.32.0. My project is roughly following this blog post for building XMonad (with exceptions made to do things using Nix where possible), and so far only consists of cloning the three repos into .xmonad and running stack --nix init; the three repos are: xmobar, xmonad-contrib, xmonad.
Is there a way for stack --nix to allow newer versions of ghc to be used? Or are there other possible causes for the issue?
I saw stack --nix build complains about ghc version mismatch but felt this didn't really illuminate the issue, though it does suggest possibly alternatives using cabal/nix.

Stack only finds newer version of Cabal

I'm trying to build a project of mine using Stackage lts-13.12.
After Stack was complaining that the version of Cabal was too new, I've tried to install an older version:
cabal --version
cabal-install version 2.2.0.0
compiled using version 2.2.0.1 of the Cabal library
However, when I run stack solver, I get the following error:
Using configuration file: stack.yaml
Using cabal packages:
- ./
Using resolver: lts-13.12
Warning: Installed version of cabal-install (2.4.1.0) is newer than stack has been tested with. If you run into difficulties, consider downgrading.
Using compiler: ghc-8.6.4
Asking cabal to calculate a build plan...
Trying with packages from lts-13.12 and 1 external packages as hard constraints...
The following lines from cabal-install output could not be parsed:
optparse-applicative-0.14.3.0 (via: project-0.1.0.0 project-0.1.0.0) (new
package)
CallStack (from HasCallStack):
error, called at src/Stack/Solver.hs:174:16 in stack-1.9.3-F7FXKCpM3pk5wCtbL9Utvv:Stack.Solver
My questions are:
Why is Stack seeing the newer Cabal? How can I make it see the older one?
Why is Stack incompatible with Cabal 2.4.1.0, when that's the version in the Stackage LTS 13.12?
I'm running Version 1.9.3 of Stack, if that makes a difference.
Stack solver error messages are known to be bad and choke on cabal output. I don't believe this feature is well maintained.
I do wish stack would update its errors and warnings. Sticking with cabal-install-2.4.1.0 is probably the best choice.
Instead of using stack solver, I recommend you force it to use lts-13.12 and then add extra deps by hand to address any issues you encounter. Most of the time stack will helpfully recommend the right extra deps (without using the solver), but you do need to apply some intuition to make sure they are right.

How to update to GHC 8.0

I am trying to use the Quantum Programming language Quipper, and I am running into issues due to the version of GHC I am using:
root#ubuntu:~$ apt-show-versions ghc
ghc:amd64/xenial 7.10.3-7 uptodate
ghc:i386 not installed
As it turns out, 7.10 is the only version that Quipper cannot compile with.
I then discovered that apparently the only way to install Haskell 8.0 was using haskell-stack. Ok, I've never installed something on a stack, so this will go over well.
So I used the instructions on this website to install haskell-stack, then ran the commands:
root#ubuntu:~$ stack setup
root#ubuntu:~$ stack update
root#ubuntu:~$ stack install ghc
The last command returned the following:
Didn't see ghc-8.0.2 in your package indices.
Updating and trying again.
Updating package index Hackage (mirrored at https://s3.amazonaws.com/hackage.fpc Selected mirror https://s3.amazonaws.com/hackage.fpcomplete.com/
Updating package index Hackage (mirrored at https://s3.amazonaws.com/hackage.fpc Downloading timestamp
Updating package index Hackage (mirrored at https://s3.amazonaws.com/hackage.fpc Downloading snapshot
Updating package index Hackage (mirrored at https://s3.amazonaws.com/hackage.fpc Updating index
Updating package index Hackage (mirrored at https://s3.amazonaws.com/hackage.fpc Updated package list downloaded
Updating package index Hackage (mirrored at https://s3.amazonaws.com/hackage.fpc Populated index cache.
The following package identifiers were not found in your indices: ghc-8.0.2
Perhaps you meant AAI, AAI, AAI, AES, AES, AES, AES, AES, AES, or AES?
So, a quick check again:
root#ubuntu:~$ apt-show-versions ghc
ghc:amd64/xenial 7.10.3-7 uptodate
ghc:i386 not installed
Nope, still 7.10. Tried also to download the package from this website. The package failed to be extracted, so that's a good sign. Rinsed and repeated the above commands, and still nothing. Then I edited the stack.yaml file to say:
resolver: lts-9.14
resolver: ghc-8.0.2
Did absolutely nothing. What step am I missing? Its frustrating when people basically say "the stack does everything for you" and I'm like "what exactly am I supposed to do?"
EDIT
As I said above, downloading the package for 8.0.2 from haskell.org gives fails to extract the archive:
Don't jump into installing the binaries directly. While, as others mentioned, stack isn't the only way, it is certainly one of the easier ones.
So first thing, stack setup actually downloads GHC for you based on the resolver it finds. If you are not in a stack project, it'll default to the global stack config. On the other hand stack install is used for installing packages. That means doing stack install ghc is trying to look for a package on stackage that's called ghc, of which I don't think there are any.
To run the GHC that stack installed, you'll do stack ghc and to get a GHCi session, stack ghci (generally just prefix with stack).
You could also run the general stack exec -- .. to run a command with stack's path variables. E.g. stack exec -- ghci will work here as well, or stack exec -- ghc --version to get the GHC version.
Binary distributions of GHC can be obtained from GHC HQ:
8.0.2 here https://www.haskell.org/ghc/download_ghc_8_0_2.html#binaries
8.2.2 here https://www.haskell.org/ghc/download_ghc_8_2_2.html#binaries
Any suggestion that any one tool is necessary to obtain GHC is wrong.
EDIT: On a nix computer, for example, one can do the following (approx, not tested):
wget https://downloads.haskell.org/~ghc/8.2.2/ghc-8.2.2-x86_64-deb8-linux.tar.xz
tar xJf ghc-8.2.2*
cd ghc*
./configure --prefix=$HOME
make install
If you don't like portable shell and really want to use apt then consider using hvr's PPA which is pretty darn popular.

Can you have different compilers and resolvers on Stack?

I have a Stack project that can build both GHCJS and GHC binaries. How can I specify on stack.yaml that builds should use both compilers?
I think you have to either
use two different files, say ghc.yaml and ghcjs.yaml, you can then use stack --stack-yaml ghc.yaml or stack --stack-yaml ghcjs.yaml to use those
you can set the compiler ghc or ghcjs by setting the resolver (see haskellstack.org/config#resolver)
or there is a compiler option (see haskellstack.org/config#compiler)
or directly use the commandline option --compiler

Resources