commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
4k stars 843 forks source link

The --stack-yaml flag should set the STACK_YAML environment variable #3727

Closed jezen closed 4 years ago

jezen commented 6 years ago

I expect the following to use the specified stack.yaml, but it doesn't work:

stack --stack-yaml stack.production.yaml exec -- yesod keter

What does work is specifying the file in the environment variable, like this:

STACK_YAML=stack.production.yaml stack exec -- yesod keter

I'm guessing it should be enough to have Stack set that environment variable if the flag is used, but I don't know. Would that work?

More info: https://github.com/yesodweb/yesod/issues/1472

mgsloan commented 6 years ago

Reasons to do this:

  1. Some cases like this will "just work"

Reasons not to do this:

  1. Changes behavior, could break scripts

  2. It may be surprising to people that inside stack exec bash, PWD is no longer used for figuring out the current stack project.

I'm leaning towards wontfix because STACK_YAML= is sufficient. Maybe we can have yesod-bin recommend that approach?

jezen commented 6 years ago

@mgsloan I would have thought this change would be quite self-contained. Why would changing STACK_YAML affect PWD?

Using the environment variable is indeed sufficient, but I'd also say it's surprising and inconsistent.

kadoban commented 6 years ago

@jezen Usually if you run stack build or any such command, it figures out from the current directory (aka pwd) what stack.yaml to use. But here, if someone were inside stack exec, it wouldn't anymore. You'd be forced to always use the one from the exec call (unless you overrode it)

So the question I think becomes, in what cases are stack runs being nested like this? I'm not sure. I think it could end up being very surprising for STACK_YAML to be set in some cases though.

mgsloan commented 6 years ago

I suggest that if there are ever any cases that STACK_YAML gets set by stack exec, it should always get set by stack exec. Otherwise things aren't predictable enough. I ran into an ugly scenario like this with git's hook scripts - https://public-inbox.org/git/CAEDDsWdXQ1+UukvbfRoTPzY3Y9sOaxQ7nh+qL_Mcuy3=XKKh7w@mail.gmail.com/

I can imagine nested stack being used with stack query commands. I dunno, maybe noone's scripts would break, but it would be a behavior change.