6

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 git@github.com: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?

Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60

1 Answers1

1

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.

lehins
  • 9,642
  • 2
  • 35
  • 49
  • that seems like a very cool workaround. However, I can't get the following to work - `stack install --resolver=github:saurabhnanda/aws-lambda-packager:snapshot.yml aws-lambda-packager`, while the following works: `stack install --resolver=/aws-lambda-packager/snapshot.yml aws-lambda-packager` – Saurabh Nanda Mar 29 '20 at 15:21
  • basically referring to the `snapshot.yml` file from github seems to give a weird error, while referring to a local file works. – Saurabh Nanda Mar 29 '20 at 15:22
  • Try fixing the commit sha in the snapshot. Error I get is that stack can't find the cabal file – lehins Mar 29 '20 at 19:39
  • Are you getting the following error as well? `fatal: Could not parse object 'd3312736a38f7b93f87c313a8fb9c0798938b403'` -- Strangely, that commit _does_ exist at https://github.com/saurabhnanda/aws-lambda-packager/commit/d3312736a38f7b93f87c313a8fb9c0798938b403 – Saurabh Nanda Apr 01 '20 at 08:17
  • The commit you specified does not have a cabal file, that's why you are probably having an issue. Also, make sure you are on the latest stack – lehins Apr 01 '20 at 16:11