A change in the PATH environment variable is not visible in cabal repl.
Confirmed in versions:
$ echo $PATH
/home/jakobro/.opam/4.01.0/bin:/home/jakobro/.cabal/bin:/home/jakobro/bin:/home/jakobro/.cabal/bin:/home/jakobro/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ export PATH=$PATH:/tmp
$ cabal repl
Prelude> :m Control.Monad System.Environment
Prelude Control.Monad System.Environment> liftM (lookup "PATH") getEnvironment
Just "/home/jakobro/.opam/4.01.0/bin:/home/jakobro/.cabal/bin:/home/jakobro/bin:/home/jakobro/.cabal/bin:/home/jakobro/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
The environment when accessed from cabal repl-based ghci does not reflect the change in the PATH variable.
It does work with newly created environment variables, though.
In pure GHCI everything works fine:
$ echo $PATH
/home/jakobro/.opam/4.01.0/bin:/home/jakobro/.cabal/bin:/home/jakobro/bin:/home/jakobro/.cabal/bin:/home/jakobro/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/tmp
$ ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :m System.Environment Control.Monad
Prelude System.Environment Control.Monad> liftM (lookup "PATH") getEnvironment
Just "/home/jakobro/.opam/4.01.0/bin:/home/jakobro/.cabal/bin:/home/jakobro/bin:/home/jakobro/.cabal/bin:/home/jakobro/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/tmp"
Does this work in ghci for you?
Yes, it works within ghci. (see changes in first post)
A simple workaround is to run cabal configure again.
I can repro by calling repl directly on Setup script, so it must be a Cabal library bug.
This seems a more general issue that seemingly running cabal configure captures the $PATH and reuses it for subsequent steps. That's causing lots of surprise, e.g. https://gitlab.com/tim-m89/clr-haskell/issues/21
I just lost an hour trying to figure out why the getEnv "PATH" in my ghci is different than from the shell.
Looks like I am hitting the same issue with cabal 3.0.0.0.
I tried cabal configure workaround but it doesn't work.
Any other workarounds?
rm -rf dist-newstyle
...
Most helpful comment
A simple workaround is to run
cabal configureagain.