67

Using cabal, I could install hakyll with the command:

cabal install hakyll

How can I do the same thing using stack?

duplode
  • 33,731
  • 7
  • 79
  • 150
Ben
  • 3,612
  • 3
  • 19
  • 24
  • 7
    For those looking to _add a dependency_ (i.e. use another package, like `text`, in your code): [Understanding stack’s model and avoiding its biggest gotcha: **You almost certainly do not want to use `stack install`**](https://lexi-lambda.github.io/blog/2018/02/10/an-opinionated-guide-to-haskell-in-2018/#understanding-stacks-model-and-avoiding-its-biggest-gotcha); per [`stack` docs](https://docs.haskellstack.org/en/stable/GUIDE/#adding-dependencies) you have to hand-edit `package.yaml` to add the package to the `dependencies` section. – Nickolay May 01 '18 at 12:50

3 Answers3

58
stack install hakyll

stack offers a curated set of packages that won't blow your machine up. If you want to check what packages are available, or exactly what version is supported, or on what version of GHC you can get it, check out https://www.stackage.org/.

For example, you can get hakyll 4.6.9.0 right now for both GHC 7.8.4 and GHC 7.10.1. Pretty neat. - source

EDIT: I forgot to mention, Yuan Wang's method works for getting the version of hakyll that is not curated into stackage. It's up to you what version you need.

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
  • 1
    what about installing packages that are only on hackage but not on stackage? Is the preferred method to install `cabal-install` or to download the tarball and `stack install` it? – mb21 Oct 25 '16 at 08:02
  • 1
    I tried **stack install accelerate-examples** and got huge **Error: While constructing the build plan, the following exceptions were encountered** which goes recursively when trying to fix it. Couldn't even google what the stack build plans are. – Slaus Feb 04 '20 at 06:02
17

add hakyll in stack.yaml generated by stack init or stack new

yaml file should look like:

flags: {}
packages:
  - '.'
extra-deps:
  - hakyll-4.7.1.0
resolver: lts-2.15

after that, run stack solver installs it

https://github.com/commercialhaskell/stack/wiki/stack.yaml

Giulio Vian
  • 8,248
  • 2
  • 33
  • 41
Yuan Wang
  • 479
  • 2
  • 13
  • 15
    Probably worth adding that `stack install hakyll` all by itself is probably sufficient to get the desired result. – Michael Snoyman Jun 25 '15 at 03:28
  • 1
    I think it's worth mentioning that this method is typically only done when the desired version of the package is not present in the selected snapshot. I believe the preferred method of package installation for a project is adding it to the `*.cabal` file's `build-depends`, or running `stack install hakyll` to test it out first. – JoL Apr 24 '17 at 16:17
5

This documentation worked for me

On package.yaml add the library under dependencies, for example:

dependencies:
- base >= 4.7 && < 5
- hakyll # added here
Nestor Tobon
  • 101
  • 2
  • 6
  • For some reason I feel recent versions of GHC have gotten unnecessarily complicated. I used to be able to use cabal. Now I have to go through all of this mess (and more) to get my old programs to compile. – Shawn Eary Sep 24 '21 at 19:59