stackbuilders / dotenv-hs

Load environment variables from dotenv files for Haskell
https://hackage.haskell.org/package/dotenv
MIT License
65 stars 14 forks source link

Document .env search behavior in Cabal monorepo #180

Closed malteneuss closed 9 months ago

malteneuss commented 1 year ago

I'm using dotenv in a subproject of a monorepo setup with the following folder structure:

- subproject
  - subproject.cabal
  - .env        # subproject .env
- cabal.project
- .env          # repository root .env

When i start the subproject from the subproject folder like

subproject$ cabal run subproject

i would expect for the subrproject .env file to be loaded, because this is in the current working directory. However, i noticed that the repository root .env is loaded instead. Is that expected behavior? If yes, i could add an entry to the documentation.

CristhianMotoche commented 1 year ago

Hello @malteneuss I would also expect the behaviour that you mention. Let me review it to understand what is going on under the hood.

CristhianMotoche commented 10 months ago

Hello @malteneuss I'm really sorry for replying so late to you. I finally got some time to test the behavior that you mention and I was not able to replicate it. FWIW, I followed these steps to replicate it:

  1. I created a module and a submodule inside it.
  2. I added dotenv to the deps of submodule.
  3. I created a simple app that load and prints a couple of env vars in submodule
module Main where

import Configuration.Dotenv
import System.Environment (getEnv)

main :: IO ()
main = do
  loadFile defaultConfig

  putStrLn "Running from submodule"

  getEnv "FOO" >>= putStrLn
  getEnv "BAR" >>= putStrLn
  1. I added a .env file in module and submodule
  2. I compiled submodule and executed it:

I got these results:

camm@cristhian-pc ~/c/d/d/m/submodule (chore/test-issue-180)> cabal exec submodule
Resolving dependencies...
Running from submodule
submodule
submodule

FWIW, I created this branch with the test example: https://github.com/stackbuilders/dotenv-hs/tree/chore/test-issue-180/dotenv-test-180/module

Therefore, I'm not sure if there is actually a dotenv issue here.

Please, take a look at it and let me know if you have any comments. Thanks in advance!

CristhianMotoche commented 9 months ago

Hello @malteneuss Please, let me know if the way I tested this was the same as yours. Otherwise, this may not be an issue in dotenv and we can close this issue.

CristhianMotoche commented 9 months ago

I'll close this issue now. Feel free to reopen if the problem persists.