-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] plugin env PATH fix #2418
base: main
Are you sure you want to change the base?
Conversation
rootEnv := mergePATHsFromTwoEnvs(env, c.Root.Env) | ||
maps.Copy(env, rootEnv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use OSExpandEnvMap
instead?
Basically take the environment provided by the plugins and use it to expand the environment of the config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikeland73 after your suggestion, I tried OSExpandEnvMap
and it it doesn't work.
The issue with OSExpandEnvMap
is it merges the two PATHs correctly but it applies the (non-nix) system PATH to the :$PATH
at the end. So with OSExpandEnvMap
PATH becomes: /my/config:/my/plugin:/opt/homebrew/sbin:/usr/local/bin:...
With mergePATHsFromTwoEnvs
PATH becomes: /my/config:/my/plugin:/Users/mohsenansari/code/go.jetpack.io/devbox/examples/stacks/rails/.devbox/nix/profile/default/bin:...:/opt/homebrew/sbin:/usr/local/bin:...
So OSExpandEnvMap can't work here because I don't want to expand $PATH env yet, I just want to merge them correctly without losing :$PATH
suffix or $PATH:
prefix to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essentially, OSExpandEnvMap
expands PATH with non-devboxified PATH value, but I don't want that.
pluginEnv := mergePATHsFromTwoEnvs(env, i.Env()) | ||
maps.Copy(env, pluginEnv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use OSExpandEnvMap
instead of mergePATHsFromTwoEnvs
?
Summary
When a plugin modifies PATH and also config in devbox.json modifies PATH via
env:{}
, the env overwrites the plugin and so PATH modification from the plugin is lost. This is because we domaps.Copy()
to merge the env from plugin to the one from config.The copy is fine for all other env variables but for PATH we need to handle merging the two rather than overwriting.
Fixes #2138
How was it tested?
bug recreate:
"env": {"PATH": "/my/config/bin:$PATH"}
"/my/config/bin"
is prepended.fix recreate: