Haskell stack with global ghc - haskell

Is it possible to use stack with an already installed ghc without stack installing a local copy of ghc or cabal?

Yes. If the ghc in PATH is of right version for the selected snapshot, stack will happily use it.
% ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.8.4
% stack --resolver=lts-2.22 install packdeps
Run from outside a project, using implicit global project config
Using resolver: lts-2.22 specified on command line
packdeps-0.4.1: unregistering
packdeps-0.4.2: download
...
% stack --resolver=nightly-2015-12-25 install packdeps
Run from outside a project, using implicit global project config
Using resolver: nightly-2015-12-25 specified on command line
Compiler version mismatched, found ghc-7.8.4 (x86_64), but expected minor version match with ghc-7.10.3 (x86_64) (based on resolver setting in /Users/phadej/.stack/global/stack.yaml).
Try running "stack setup" to install the correct GHC into /Users/phadej/.stack/programs/x86_64-osx/
You can also skip ghc check --skip-ghc-check:
% stack --resolver=nightly-2015-12-25 --skip-ghc-check install packdeps
Run from outside a project, using implicit global project config
Using resolver: nightly-2015-12-25 specified on command line
split-0.2.2: configure
...
but that might be a bad idea

Related

How to fix hdevtools - "GHC_PACKAGE_PATH is incompatible.." error

I'm a haskell beginner, I use the advent of code as learning examples.
When setting up for this year I reinstalled stack (on a new machine, however copied most dotfiles over) and was starting from my last years notes and was not able to get hdevtools working again.
I have set up a new project with stack new advent2019. In case it matters stack build on the "empty" project seems to take several minutes - seems much longer than last year. I install hdevtools with stack build hdevtools.
When I run stack exec hdevtools -- check src/Lib.hs I get following error:
Cabal error: hdevtools: Use of GHC's environment variable GHC_PACKAGE_PATH is incompatible
with Cabal. Use the flag --package-db to specify a package database (it can be
used multiple times).
So far I tried:
I checked my shell and did an rg --no-ignore over my home directory to confirm GHC_PACKAGE_PATH is not set by me. Also over the project directory.
I was not able to figure out how to use the mentioned --package-db flag - putting it after hdevtools I get an unknown flag error, putting it to stack I get an invalid option.
stack exec --no-ghc-package-path hdevtools -- check src/Lib.hs - mentioned here
I deleted all possible related files: ~/.local/bin/hdevtools, everything from ~/.stack, all ~/.ghc*.
None helped with the error.
I suppose I overlooked something obvious - however can you help point it out?
For completeness:
on OS X, 10.15.1
stack --version: Version 1.9.3, Git revision 40cf7b37526b86d1676da82167ea8758a854953b (6211 commits) x86_64 hpack-0.31.1
stack ghc -- --version: The Glorious Glasgow Haskell Compilation System, version 8.6.5
stack path:
stack-root: /Users/me/.stack
project-root: /Users/me/Code/advent2019
config-location: /Users/me/Code/advent2019/stack.yaml
bin-path: /Users/me/.stack/snapshots/x86_64-osx/lts-14.16/8.6.5/bin:/Users/me/.stack/compiler-tools/x86_64-osx/ghc-8.6.5/bin:/Users/me/.stack/programs/x86_64-osx/ghc-8.6.5/bin:/usr/local/texlive/2018basic/bin/x86_64-darwin:/Users/me/.local/bin/:/Users/me/.gem/bin:/Users/me/.yarn/bin:/Users/me/Library/Python/3.7/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Library/TeX/texbin:.:/Applications/Wireshark.app/Contents/MacOS
programs: /Users/me/.stack/programs/x86_64-osx
compiler-exe: /Users/me/.stack/programs/x86_64-osx/ghc-8.6.5/bin/ghc
compiler-bin: /Users/me/.stack/programs/x86_64-osx/ghc-8.6.5/bin
compiler-tools-bin: /Users/me/.stack/compiler-tools/x86_64-osx/ghc-8.6.5/bin
local-bin: /Users/me/.local/bin
extra-include-dirs:
extra-library-dirs:
snapshot-pkg-db: /Users/me/.stack/snapshots/x86_64-osx/lts-14.16/8.6.5/pkgdb
local-pkg-db: /Users/me/Code/advent2019/.stack-work/install/x86_64-osx/lts-14.16/8.6.5/pkgdb
global-pkg-db: /Users/me/.stack/programs/x86_64-osx/ghc-8.6.5/lib/ghc-8.6.5/package.conf.d
ghc-package-path: /Users/me/Code/advent2019/.stack-work/install/x86_64-osx/lts-14.16/8.6.5/pkgdb:/Users/me/.stack/snapshots/x86_64-osx/lts-14.16/8.6.5/pkgdb:/Users/me/.stack/programs/x86_64-osx/ghc-8.6.5/lib/ghc-8.6.5/package.conf.d
snapshot-install-root: /Users/me/.stack/snapshots/x86_64-osx/lts-14.16/8.6.5
local-install-root: /Users/me/Code/advent2019/.stack-work/install/x86_64-osx/lts-14.16/8.6.5
snapshot-doc-root: /Users/me/.stack/snapshots/x86_64-osx/lts-14.16/8.6.5/doc
local-doc-root: /Users/me/Code/advent2019/.stack-work/install/x86_64-osx/lts-14.16/8.6.5/doc
dist-dir: .stack-work/dist/x86_64-osx/Cabal-2.4.0.1
/Users/me/Code/advent2019/.stack-work/install/x86_64-osx/lts-14.16/8.6.5/hpc
local-bin-path: /Users/me/.local/bin
ghc-paths: /Users/me/.stack/programs/x86_64-osx
The --no-ghc-package-path solution should have worked. However, you can just run hdevtools outside of Stack. On a Linux machine, if I run the following set of commands exactly:
$ stack new advent2019
$ cd advent2019
$ stack build
$ stack install hdevtools
$ hdevtools check src/Lib.hs
then hdevtools starts without error and runs in the background.
If your shell can't find hdevtools, it may be that ~/.local/bin is not in your path, so add it or try this instead:
$ ~/.local/bin/hdevtools check src/Lib.hs
Turns out I overlooked the .cabal directory in my purge. Though still had to also wipe .stack before installing hdevtools. Also had to build test separately so I would get dependency errors.
I don't think this is a solution for someone who uses haskell productively. Reminds me of my Windows 95 days where support told you to format and reinstall for every issue.

stack does not resolve dependencies when installing hip

I want to install the Haskell libary hip from https://hackage.haskell.org/package/hip by using stack. This does not work, because stack seems to not being able to install dependencies.
I have stack freshly installed by curl -sSL https://get.haskellstack.org/ | sh, and stack --version gives me
Version 1.9.3, Git revision 40cf7b37526b86d1676da82167ea8758a854953b (6211 commits) x86_64 hpack-0.31.1
I have tried several things like another resolver, reinstalling different versions of stack, ghc or cabal.
I have tried stack new test, and inside the test folder, i wrote stack install hip.
I got the following error:
Error: While constructing the build plan, the following exceptions were
encountered:
In the dependencies for hip-1.5.3.0:
Chart must match >=1.5, but the stack configuration has no specified
version (latest matching version is 1.9)
Chart-diagrams must match >=1.5, but the stack configuration has no
specified version (latest matching version is 1.9)
needed since hip is a build target.
Some different approaches to resolving this:
* Consider trying 'stack solver', which uses the cabal-install solver to
attempt to find some working build configuration. This can be convenient
when dealing with many complicated constraint errors, but results may be
unpredictable.
* Recommended action: try adding the following to your extra-deps
in /home/jarek/Desktop/test/stack.yaml:
Chart-1.9#sha256:f41568b6b3704f66c2ec163295b430ab7d798f91de426c2d5aba747d1135cd9b
Chart-diagrams-1.9#sha256:cdd0c22d730e507f9644e690833096ee127302b5ff5e1571f6def419160a2642
Plan construction failed.
I expect something like:
Building dependencies...
Installing Chart-1.9
...
...
...
hip successfully installed.
Please tell me if i did not provide all infos necessary for you to help me with my problem.
Installing with the resolver lts-7.5 works.
Why not do what stack recommended?
Recommended action: try adding the following to your extra-deps
in /home/jarek/Desktop/test/stack.yaml:
Chart-1.9#sha256:f41568b6b3704f66c2ec163295b430ab7d798f91de426c2d5aba747d1135cd9b
Chart-diagrams-1.9#sha256:cdd0c22d730e507f9644e690833096ee127302b5ff5e1571f6def419160a
It's the easiest way to accomplish your goal.
Update: lts-10.10 is the most recent resolver to include hip. If you update your stack.yaml to use lts-10.10 and add hip in your .cabal file, you should be good to go.

Cabal 2.0 required when using a nightly snapshot with stack

I'm trying to setup a new project using the nightly-2017-08-17 snapshot
stack new test --resolver nightly-2017-08-17
However this gives the following error:
Downloading template "new-template" to create project "test" in test/ ...
Looking for .cabal or package.yaml files to use to init the project.
Using cabal packages:
- test/test.cabal
Selected resolver: nightly-2017-08-17
Unable to parse cabal file: FromString "This package requires at least Cabal version 2.0" Nothing
Cabal is in its latest version:
stack setup --upgrade-cabal
Currently installed Cabal is 2.0.0.2, newest is 2.0.0.2. I'm not upgrading Cabal.
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
Is this not the correct way of selecting this nightly snapshot with stack or is this a bug in the tool?
Cabal's file format has changed in the 2.0 release of it (likely because of backpack). You have to use Stack version >= 1.5.1 which bypasses this error. A proper fix for this will be likely released in the next version of Stack. IIRC, the fix is already in the master brach of the stack - so the upgrade via --source-only willl also work for you.
You can read the changelog here to know more information about it.

Change ghci version on stack

I have stack installed on my computer for haskell:
Developers-MacBook-Pro:~ developer$ stack ghci
Configuring GHCi with the following packages:
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /private/var/folders/2x/t_2cl03x2092dkzvc702d7lc0000gn/T/ghci2170/ghci-script
Prelude>
As you can see version is still 8.0.1. Then I upgraded the stack as follow:
Developers-MacBook-Pro:~ developer$ stack upgrade
Current Stack version: 1.3.2, available download version: 1.4.0
Newer version detected, downloading
Querying for archive location for platform: osx-x86_64-static
Querying for archive location for platform: osx-x86_64
Downloading from: https://github.com/commercialhaskell/stack/releases/download/v1.4.0/stack-1.4.0-osx-x86_64.tar.gz
Download complete, testing executable
Version 1.4.0, Git revision e714f1dd3fade19496d91bd6a017e435a96a6bcd (4640 commits) x86_64 hpack-0.17.0
New stack executable available at /Users/developer/.local/bin/stack
After I start stack ghci again and I've got still version 8.0.1, what am I doing wrong?
The image shows, that ghci version 8.0.2 has successfully installed:
The path is /Users/developer/.stack/programs/x86_64-osx/
Update
In the path /Users/developer/.stack/, there is a folder called global-project and I change the yaml as follow:
Now stack ghci run on version 8.0.2:
Developers-MBP:~ developer$ stack ghci
Configuring GHCi with the following packages:
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /private/var/folders/2x/t_2cl03x2092dkzvc702d7lc0000gn/T/ghci526/ghci-script
According to https://docs.haskellstack.org/en/stable/faq/#what-version-of-ghc-is-used-when-i-run-something-like-stack-ghci,
The version of GHC, as well as which packages can be installed, are specified by the resolver.
So, to change the version of GHC used when executing stack ghci outside stack projects, do:
Find an existing resolver in ~/.stack/build-plan, e.g. lts-10.4, or download a new resolver you need;
Execute stack config set resolver lts-10.4. Yes it updates ~/.stack/global-project/stack.yaml.
As thus, stack ghci outside stack projects will use GHC 8.2.2, which is the GHC version specified by resolver lts-10.4 (This relationship can be found at https://www.stackage.org/lts-10.4, or in file ~/.stack/build-plan/lts-10.4.yaml which says ghc-version: '8.2.2').
stack is a build tool that coordinates building projects with different versions of GHC and sets of dependencies. So you can upgrade stack independently of ghc.
I'm not quite sure what the expected behavior of stack ghci is when it's run outside of a project directory. Presumably you con configure the default version of ghc to use in that case in your ~/.stack/config.yaml. See: http://docs.haskellstack.org/en/stable/yaml_configuration/
You should also be able to do:
$ stack ghci --with-ghc ghc-7.10.3
But usually the version of ghc is determined by the stackage snapshot you've configured for your project, for instance if you have a stack.yaml with:
resolver: lts-3.3
...you will be using ghc-7.10.3

Stack not resolving dependencies properly

I'm trying to set up Hakyll on a fresh Ubuntu 16.04 instance, but I can't seem to get the Stack-based setup instructions right.
Starting out with stack install hakyll, I get:
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for hakyll-4.9.3.0:
http-conduit-2.1.11 must match >=2.2 && <2.3 (latest applicable is 2.2.3)
Plan construction failed.
I got a similar error when tying to stack-install http-conduit-2.1.11, this time with:
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for http-conduit-2.2.3:
http-client-0.4.31.2 must match >=0.5 && <0.6 (latest applicable is 0.5.5)
http-client-tls-0.2.4.1 must match >=0.3 && <0.4 (latest applicable is 0.3.3.1)
Plan construction failed.
After resolving dependencies for this (also using Stack), I tried once again to stack install http-conduit-2.1.11, but I once again got the same dependency error.
The packages http-client-0.4.31.2 and http-client-tls-0.2.4.1 appear in my ~/.stack/precompiled/x86_64-linux/ghc-8.0.1/1.24.0.0/, which isn't explicitly in my $PATH, however that feels like an extremely hacky solution, and I haven't found any documentation recommending this approach.
How can I correctly install Hakyll on my machine?
Dependency management with stack is meant to be reproducible and declarative, that means that a stack project will only compile once all dependencies are recorded in the .cabal file(s) of the project and once the stack.yaml of the project defines versions for these dependencies either in the resolver or the extra-deps section.
Your confusion seems to stem from a misunderstanding of what stack install does. The command line help has this to say about it:
build Build the package(s) in this directory/configuration
install Shortcut for 'build --copy-bins'
...
--[no-]copy-bins Enable/disable copying binaries to the local-bin-path
(see 'stack path')
stack install does not save any dependencies.
So the proper way of making hakyll available as a dependency to your code is:
Create a proper stack project with stack init if you already have a Cabal package, or stack new if you don't.
Add hakyll to the library or executable build-depends in your .cabal file.
Attempt to stack build and follow the instructions in any error messages until all issues are resolved.
A simpler solution than #sjakobi's in this case was to specify a resolver as a command line option when starting a new Stack project:
stack install hakyll --resolver=5.11 --install-ghc

Resources