Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Stack install package dependency from github

Is it possible to install a version of a package from github using Haskell stack?

e.g. in a .cabal or a stack.yaml file, how can I point a dependency at a git repo/branch/revision?

like image 928
Abraham P Avatar asked Jul 14 '16 14:07

Abraham P


3 Answers

For stack <1.11:

The documentation for the stack.yaml packages section gives examples of referring to more complex package locations.

packages:
- location: .
- location: dir1/dir2
- location: https://example.com/foo/bar/baz-0.0.2.tar.gz
- location: http://github.com/yesodweb/wai/archive/2f8a8e1b771829f4a8a77c0111352ce45a14c30f.zip
- location:
    git: [email protected]:commercialhaskell/stack.git
    commit: 6a86ee32e5b869a877151f74064572225e1a0398
- location:
    hg: https://example.com/hg/repo
    commit: da39a3ee5e6b4b0d3255bfef95601890afd80709

Then add extra-dep: true to the package entry just to tell stack not to treat the code it pulls in as something you're developing on (e.g., don't load it in GHCi).

like image 114
R B Avatar answered Nov 10 '22 00:11

R B


New syntax for Stack >1.7.1

As @Flip commented, the docs at docs.haskellstack.org clarify the new syntax for your stack.yaml is: (note the full commit hash needs to be used)

extra-deps:
- github: apolishch/prime_table
  commit: a510622a824af999a809191e8c959b8ea5fa8bdb
- github: apolishch/reactive-banana
  commit: 74bac0f86ed172f95bb6f6a31041992fc161cf79
  subdirs: reactive-banana

To be clear: dependencies in your stack.yaml make sure that the packages (which are not in Stackage) are available would some .cabal file in your project want them, just in case.

You still have to specify the name of the package in build-depends in your .cabal file to say you actually depend on the package.

Note it doesn't matter what branch the commit is on, and repos can be forks. When a package is in a subdirectory, you can specify it, otherwise it will default to top-level.

Syntax for Stack >1.6.0

extra-deps:
- github: [email protected]:apolishch/prime_table.git
  commit: a510622a824af999a809191e8c959b8ea5fa8bdb

[Edit] I have found that sometimes the syntax from 1.7.1 fails with error message

C:\Users\username\AppData\Local\Programs\stack\x86_64-windows\ghc-8.4.3\lib/../mingw/bin\ar.exe: .stack-work\dist\7d103d30\build\objs-10648\libHSpackagename-0.1.0.0-DlGXqyeqb9MDn2z8KhgjVb.a: No such file or directory

and I solved that by using the 1.6.0 syntax, even though I was using Stack 1.7.1. When using Travis, that will fail because Travis can't clone via SSH without your SSH keys of course. But you can still use the https link as

extra-deps:
- github: https://github.com/apolishch/prime_table.git
  commit: a510622a824af999a809191e8c959b8ea5fa8bdb
like image 32
PHPirate Avatar answered Nov 09 '22 23:11

PHPirate


In my case i wanted to depend on a fork of pandoc, specifying a precise commit. It worked by adding the following to stack.yml:

extra-deps: - archive: https://github.com/italia/pandoc/archive/1327c564cccf5dfa387a2956443990d9854c85cd.zip

This would work with any branch-like URL on Git. I found my url by browsing the files at the commit and copying the URL from the "Download ZIP" button.

Note that my branch has a specific version, higher than any version Stack could fetch from the resolver. I pinpoint the version in the Cabal dependencies. If the version on that branch would overlap with one available in the resolver's index, i'm not sure about which one would be picked

like image 20
danza Avatar answered Nov 09 '22 23:11

danza