Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to specify a `stack.yaml` file for a haskell script?

Let's say I have the following script inside my haskell project directory:

#!/usr/bin/env stack
-- stack --resolver lts-12.5 script

-- some imports here

main :: IO ()
main = do
  -- some code here

I'd like to use the stack.yaml file that exists inside the project directory, in order to get the required packages, as I want to get them from a specific git commit instead of lts-12.5.

I've tried adding --stack-yaml stack.yaml after --resolver lts-12.5 but I'm getting this warning when I run the script: Ignoring override stack.yaml file for script command: stack.yaml.

Is it possible to use my stack.yaml file for the script? or is it possible to specify the git commit from which I want to get the package (like using location with commit and git inside stack.yaml)?

like image 200
Gaith Avatar asked Oct 08 '18 17:10

Gaith


People also ask

What is stack Haskell?

Stack's functions Stack handles the management of your toolchain (including GHC — the Glasgow Haskell Compiler — and, for Windows users, MSYS2), building and registering libraries, building build tool dependencies, and more.

Where is Haskell stack installed?

Stack itself is installed in normal system locations based on the mechanism you used (see the Install and upgrade page). Stack installs files in the Stack root and other files in a . stack-work directory within each project's directory. None of this should affect any existing Haskell tools at all.


1 Answers

You can achieve this using custom snapshot files. For example, in snapshot.yaml:

resolver: ghc-8.4.3
name: has-acme-missiles
packages:
- acme-missiles-0.3

In Main.hs:

#!/usr/bin/env stack
-- stack --resolver snapshot.yaml script
import Acme.Missiles

main :: IO ()
main = launchMissiles

Results in:

$ ./Main.hs 
Nuclear launch detected.
like image 70
Michael Snoyman Avatar answered Oct 24 '22 08:10

Michael Snoyman