Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended approach to use Stack as global package manager

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.

like image 507
Radon Rosborough Avatar asked Mar 27 '18 04:03

Radon Rosborough


1 Answers

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.

like image 55
mgsloan Avatar answered Sep 30 '22 10:09

mgsloan