jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
7.83k stars 187 forks source link

Cannot set PATH env var in both a plugin and devbox.json #2138

Open jay-aye-see-kay opened 3 weeks ago

jay-aye-see-kay commented 3 weeks ago

What happened?

Setting PATH in a project's devbox.json#env will override that setting in made in any plugins. I haven't tested what happens if two plugins try to set PATH but expect it would be a "last wins" situation.

A workaround is to set PATH in shell.init_hook rather than in env. This is a bit more verbose but appears to always work as expected. A quick fix for the ruby plugin might be to do this, i.e.

 "shell": {
      "init_hook": [
          "export PATH=\"{{ .Virtenv }}/bin:$PATH\""
      ]
  }

Ideally env vars in plugins would be expanded sequentially so that PATH could be modified by multiple plugins. But I'm not sure how difficult that would be to implement.

Steps to reproduce

  1. setup temp project: cd $(mktemp -d) && devbox init && devbox generate direnv
  2. add ruby (the only built in plugin that sets env.PATH): devbox add ruby
  3. OBSERVE ruby plugin has prepended a dir to the PATH: echo $PATH | grep ".devbox/virtenv/ruby/bin"
  4. add "env": { "PATH": "/path/to/my/bin:$PATH" } to devbox.json
  5. OBSERVE path has been prepended as expected echo $PATH | grep "/path/to/my/bin"
  6. OBSERVE BUG ruby plugin's change to PATH has been overwritten: echo $PATH | grep ".devbox/virtenv/ruby/bin" (no result)

Command

No response

devbox.json

{
  "packages": ["ruby@latest"],
  "env": {
    "PATH": "/path/to/my/bin:$PATH"
  }
}

Devbox version

0.11.0

Nix version

2.18.1

What system does this bug occur on?

macOS (Apple Silicon)

Debug logs

No response