Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install a Haskell package directly from a git repository?

stack allows one to define git repositories as packages using the stack.yaml file. Is it possible to do something like the following, directly via command-line:

stack install --resolver=lts-12.1 [email protected]:saurabhnanda/some-repo.git

Use-case: Install a command-line tool that I have written during a docker build process. I want to avoid cloning the repo and then building it. Is there a short-hand for this?

like image 616
Saurabh Nanda Avatar asked Mar 18 '20 15:03

Saurabh Nanda


1 Answers

EDIT

New solution

Right after submitting the answer I thought of a separate solution.

You can create a custom custom-snapshot.yaml file in your repository that extends some existing snapshot, such as lts-15.3 for example. Add your package to it in a similar way you would add it to the stack.yaml. And the point to it when installing the tool:

$ stack install --resolver https://raw.githubusercontent.com/saurabhnanda/my-cool-tool/master/custom-snapshot.yaml my-cool-tool

or even shorter:

$ stack install --resolver github:saurabhnanda/my-cool-tool:custom-snapshot.yaml my-cool-tool 

Disclaimer - I have not tried it, but in theory it should work.

Old solution

I don't think you can do it at cli without stack.yaml

So two options are:

  • either create a temporary project with stack new add your repository to the stack.yaml
  • or add the same information to into the global stack.yaml, location of which can be found programmatically:
$ stack path --config-location
/home/saurabhnanda/.stack/global-project/stack.yaml

and add this to extra-deps:

- github: saurabhnanda/some-repo
  commit: master
  subdirs:
    - my-cool-tool

After that running stack install my-cool-tool should work as normal.

I don't think it would be too hard too write up a Haskell script that could do one of those two solutions for you and host as a gist that can be curled and executed on demand with stack.

like image 95
lehins Avatar answered Oct 21 '22 10:10

lehins