7

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)?

Gaith
  • 798
  • 8
  • 19
  • 4
    I believe that if you use `stack runhaskell` instead of `stack script`, it will use a `stack.yaml` file. The primary purpose of `script` is to ensure the script *doesn’t* use `stack.yaml` so that it’s completely independent. – Alexis King Oct 08 '18 at 18:47

1 Answers1

7

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.
Michael Snoyman
  • 31,100
  • 3
  • 48
  • 77