Stack does not use the system-global installed ghc but always tries to
install its own. Even when instructed otherwise.
This looks like a duplicate of #2842, but it is not related to #2852
because ~/.stack/config.yaml contains system-ghc: true.
~$ rm -rf ~/.ghc ~/.cabal ~/.stack
Instruct stack to use globally installed ghc
~$ stack config set system-ghc --global true
/home/sk/.stack/config.yaml has been updated.
Verify:
~$ cat ~/.stack/config.yaml
templates:
params: null
system-ghc: true
Setup new project
~$ stack new foo
Downloading template "new-template" to create project "foo" in foo/ ...
[...]
Populated index cache.
* Matches lts-8.6
Selected resolver: lts-8.6
Initialising configuration using resolver: lts-8.6
Total number of user packages considered: 1
Writing configuration to file: foo/stack.yaml
All done.
~$ cd foo
~/foo$ du -sh .
28K .
Try to compile
~/foo$ stack build
Error message:
~/foo$ stack build
Compiler version mismatched, found ghc-8.0.1 (x86_64), but expected minor version match with ghc-8.0.2 (x86_64-ncurses6) (based on resolver setting in /home/sk/foo/stack.yaml).
To install the correct GHC into /home/sk/.stack/programs/x86_64-linux/, try running "stack setup" or use the "--install-ghc" flag.
Compilation without errors, using system-global ghc. I would
have expected the resolver to resolve to something that matches the
system-global ghc.
~$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.0.1
~$ stack --version | head -n1
Version 1.4.0 x86_64
~$ cabal --version
cabal-install version 1.24.0.0
compiled using version 1.24.0.0 of the Cabal library
From the Arch Linux repositories https://www.archlinux.org/.
I think this happens because your system-ghc is version 8.0.1 and stack resolver lts-8.6 requires 8.0.2.
As far as I know, there is no option to relax this constraint. There is a 'compiler-check: newer-minor' option that allows newer minor versions, but not older ones like in your case. Maybe such option should be added.
A better solution might be to use the '--resolver ghc-8.0.1' option when calling stack. Then it will use a stackage version that made for your ghc version.
use the '--resolver ghc-8.0.1' option when calling stack
Yes, that works.
Most helpful comment
A better solution might be to use the '--resolver ghc-8.0.1' option when calling stack. Then it will use a stackage version that made for your ghc version.