Stack: Sandboxed Execution proposal

Created on 28 Dec 2017  路  8Comments  路  Source: commercialhaskell/stack

General summary/comments

Currently there are tools, like ghc-mod, LiquidHaskell and other that link to GHC as a library and depend on exact version of GHC to work correctly. It is great pain to support different projects with different GHCs that way. Lot of great tools depend on exact GHC version.
It would be great if there is sandboxing of "stack install" based on current Stackage version (LTS) or GHC version.
I mean this:
stack install --sandbox ghc-mod
That line to install ghc-mod into special folder that is indexed by current Stackage version.
Then when you run:
stack exec -- ghc-mod
This line to add this special folder in front of the PATH, so the exact ghc-mod version compatible with the GHC is found.

Stackage version could be used (instead of GHC version) for indexing as the tool that ran may depend (be compatible) with exact versions of other installed tools.

documentation

All 8 comments

I think stack build does what you're asking for. For example:

$ rm ~/.local/bin/hpack

$ which hpack || echo hpack not on PATH
hpack not on PATH

$ stack exec -- hpack --version
Executable named hpack not found on path: ["/Users/manny/.stack/global-project/.stack-work/install/x86_64-osx/lts-10.1/8.2.2/bin","/Users/manny/.stack/snapshots/x86_64-osx/lts-10.1/8.2.2/bin","/Users/manny/.stack/compiler-tools/x86_64-osx/ghc-8.2.2/bin","/Users/manny/.stack/programs/x86_64-osx/ghc-8.2.2/bin","/Users/manny/.nix-profile/bin","/Users/manny/.nix-profile/sbin","/Users/manny/.eb-dotfiles/bin","/Users/manny/.local/bin","/Users/manny/bin","/usr/local/bin","/usr/bin","/bin","/usr/sbin","/sbin","/opt/X11/bin"]

$ stack build hpack
[snip]
hpack-0.21.2: configure
hpack-0.21.2: build
hpack-0.21.2: copy/register
Completed 44 action(s).

$ stack exec -- hpack --version
hpack version 0.21.2

$ stack exec which hpack
/Users/manny/.stack/snapshots/x86_64-osx/lts-10.1/8.2.2/bin/hpack

$ which hpack || echo hpack not on PATH
hpack not on PATH

If you want "sandboxing" like this by GHC version, that's exactly what the --copy-compiler-tool flag does on stack build. So if you do stack build ghc-mod --copy-compiler-tool it should be available via stack exec -- ghc-mod exactly when you're in a context with the same GHC version.

It'd also be great to have some automatic way to identify something as a compiler tool, possibly nicely mixed with https://github.com/commercialhaskell/stack/issues/2122 . More thoughts on this here https://github.com/commercialhaskell/intero/issues/324

Marking this as a documentation / support issue, feel free to close or open PR improving docs.

Great! I didn't know that!

I found one issue with that:

  1. stack build --copy-compiler-tool ghc-mod
  2. Go and delete ghc-mod.exe into C:\sr\snapshots\726bcf65\bin\
  3. stack build --copy-compiler-tool ghc-mod

Instead of building another one and then copy, it showed that error:

Couldn't find executable ghc-mod in directory C:\sr\snapshots\726bcf65\bin\

@varosi True, that is an issue tracked by https://github.com/commercialhaskell/stack/issues/3083

Thanks!

Welcome! :D Sounds like this can be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

symbiont-joseph-kachmar picture symbiont-joseph-kachmar  路  3Comments

abhinav picture abhinav  路  4Comments

tinkyholloway picture tinkyholloway  路  4Comments

mgsloan picture mgsloan  路  3Comments

igrep picture igrep  路  3Comments