I just noticed that Haskell programs run via stack
do not receive environment variables from the calling environment. Here's a sample program:
-- testenv.hs
import System.Environment
main :: IO ()
main = print =<< getEnv "FOOBAR"
If I run it without stack, like this, it works:
% FOOBAR=123 runhaskell testenv.hs
"123"
But using stack:
% FOOBAR=123 stack runhaskell testenv.hs
testenv.hs: FOOBAR: getEnv: does not exist (no environment variable)
Same goes for when it is compiled: FOOBAR=123 stack exec testenv
fails while FOOBAR=123 .stack-work/install/BLAHBLAH/testenv
works.
Is there a way to force stack to pass-through certain environment variables?
The real problem I'm having is with yesod devel
, there are some settings I want to override with environment variables, but yesod devel
uses stack to run the program so they don't go through.
This is stack 1.6.5 on NixOS 18.03.132262.0a73111bc29.
It seems like this is the relevant section of the stack manual, which I missed:
“By default, stack will run the build in a pure Nix build environment (or shell), which means two important things: (1) basically no environment variable will be forwarded from your user session to the nix-shell [...]”
So this advice worked:
“To override this behaviour, add pure: false to your stack.yaml or pass the --no-nix-pure option to the command line.”
% FOOBAR=123 stack --no-nix-pure runhaskell testenv.hs
"123"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With