Recommended approach to use Stack as global packag

2020-07-03 07:14发布

问题:

I would like to install some Haskell libraries globally, for example hindent which is used by my editor's Haskell integration. What is the recommended way to do this?

I thought that stack install hindent was the correct way to do this. However, then I wanted to update my packages and found that there was no way to do this. According to the GitHub issue report I found,

stack is concerned with managing a local build sandbox for a project. It isn't intended to be a global package manager.

There appear to be workarounds such as maintaining a dummy project with artificial dependencies on the packages I would like installed. This sounds like a terrible hack, and I have been unable to find any official documentation on what approach should actually be taken.

Installing Haskell packages using my system package manager (Homebrew) is not an option since they are not packaged.

I would have opened an issue report against Stack, however the contribution guidelines requested that I instead ask a question here under the haskell-stack tag.

回答1:

Well, stack install in any project will install to ~/.local/bin therefore making whatever executable you install be globally accessible.

The global project is used when running stack without a project, it is located in ~/.stack/global-project/stack.yaml.

If you want all of your globally accessible tools to have the same dependencies (perhaps to ensure that the ghc version matches or something), then you could make a project intended to build all of these tools. It's up to you whether or not it is the "global project" - there's not much special about it, it's just a default if you run stack and aren't in a project.

In order to record "what haskell executables do I want installed globally", you might consider creating a shell file like

#!/bin/sh
stack install hindent

And then running this whenever you change the versions of the installed tools.

Also, for tools like intero that need to match the ghc version, you can do stack install --copy-compiler-tool intero, and it will be available on the PATH when stack is used with that ghc version.