devbox
devbox copied to clipboard
Cannot set PATH env var in both a plugin and devbox.json
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
- setup temp project:
cd $(mktemp -d) && devbox init && devbox generate direnv - add ruby (the only built in plugin that sets
env.PATH):devbox add ruby - OBSERVE ruby plugin has prepended a dir to the PATH:
echo $PATH | grep ".devbox/virtenv/ruby/bin" - add
"env": { "PATH": "/path/to/my/bin:$PATH" }todevbox.json - OBSERVE path has been prepended as expected
echo $PATH | grep "/path/to/my/bin" - 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