I want to make scripts that work on both nix and non-nix OS without changes
example-script.hs
#!/usr/bin/env stack
{- stack
script
--resolver lts-9.18
-}
import System.Environment (getArgs)
main :: IO ()
main = do
args <- getArgs
print args
~/.stack/config.yaml
nix:
enable: true
packages:
- libcxx
- icu
- gcc
- ncurses
- zlib
~/projects/nuuz/nuuz-chrome-extension/packages/metalib î‚° î‚ master î‚° update-index-js.hs index.js
Already downloaded.
Running /home/bjorn/.stack/programs/x86_64-linux/ghc-8.0.2.temp/ghc-8.0.2/configure --prefix=/home/bjorn/.stack/programs/x86_64-linux/ghc-8.0.2/ in directory /home/bjorn/.stack/programs/x86_64-linux/ghc-8.0.2.temp/ghc-8.0.2/ exited with ExitFailure 1
checking for path to top of build tree...
/home/bjorn/.stack/programs/x86_64-linux/ghc-8.0.2.temp/ghc-8.0.2/configure: utils/ghc-pwd/dist-install/build/tmp/ghc-pwd-bindist: /bin/bash: bad interpreter: No such file or directory
configure: error: cannot determine current directory
Error: Error encountered while configuring GHC with
/home/bjorn/.stack/programs/x86_64-linux/ghc-8.0.2.temp/ghc-8.0.2/configure --prefix=/home/bjorn/.stack/programs/x86_64-linux/ghc-8.0.2/
run in /home/bjorn/.stack/programs/x86_64-linux/ghc-8.0.2.temp/ghc-8.0.2/
The following directories may now contain files, but won't be used by stack:
- /home/bjorn/.stack/programs/x86_64-linux/ghc-8.0.2.temp/
- /home/bjorn/.stack/programs/x86_64-linux/ghc-8.0.2/
Configuring GHC ...%
But I can resolve this issue by adding --nix option
#!/usr/bin/env stack
{- stack
script
--nix
--resolver lts-9.18
-}
To work without --nix
✘  ~  stack --version
Version 1.5.1 x86_64
Sorry, can't upgrade to latest stack-1.6.3
Sorry for the delay in response. Was reminded of this ticket via #3887. Indeed, stack script does not read the global config. This is likely for reproducibility, but I'm thinking that it should read it. There is some further discussion in #3887
I'm running into this exact same problem. I'd like stack script to read the nix settings from ~/.stack/config.yaml, so I can run Haskell scripts on distributions with or without nix.
I'm going to make this change
Most helpful comment
I'm going to make this change