Lazily evaluated env template variables in path entries
Setup:
-
HOME=/Users/john - A global
config.tomlfile with:- a
_.pathtemplate entry with value"{{env.GEM_HOME}}/bin" - an env entry:
GEM_HOME = "{{env.HOME}}/.gem"
- a
- A
.mise.tomlfile in some directory under the home directory with:- an env entry:
GEM_HOME = "{{env.HOME}}/.mise-gemsets/foo"
- an env entry:
Today, env entries in path templates are expanded using the environment variables defined in the same mise config file, either global or local.
The idea behind a lazily expanded reference in path entries is to only expand the path env reference after both the global and local mise configs have been read, and use whatever value the env variable has at that point.
In the above example, this would mean that in the specific directory a path entry valued /Users/john/.mise-gemsets/foo/bin would be added, whereas elsewhere the entry /Users/john/.gem/bin would be added instead.
Today this doesn't work because the path entry has to be set in the global config where it is always added with the global value, which is not what we want here.
If there's another way to achieve this with existing mise facilities I'd love to learn about it. Thanks!
@jdx here's a demo of my current branch, which allows lazy path entries to be specified using { value = "lazy_path_entry" } in addition to the existing "normal_path_entry". The effect is that the same positional PATH entry is either controlled by the global mise config, or by a local mise config in some directory, as can be seen below:
~/.config/mise/config.toml:
[env]
GEM_HOME = "{{env.HOME}}/.gem"
_.path = [
{ value = "{{env.GEM_HOME}}/bin" },
]
~/github/josb/.mise.toml:
[env]
GEM_HOME = "{{env.HOME}}/.mise-gemsets/foo"
~% mise env
export GEM_HOME=/Users/josb/.gem
export PATH='/Users/josb/.gem/bin:/opt/homebrew/opt/ruby/bin:...
~% cd ~/github/josb
~/github/josb% mise env
export GEM_HOME=/Users/josb/.mise-gemsets/foo
export PATH='/Users/josb/.mise-gemsets/foo/bin:/opt/homebrew/opt/ruby/bin:...
~/github/josb%
Normal _.path entries also still work, of course.
Feedback welcome.
there's another ticket (didn't have time to search for it) where we've talked about being able to configure some env vars to be parsed after tools are loaded that I think would be a prerequisite for doing this
Do you mean https://github.com/jdx/mise/issues/1982? That seems to not concern env var evaluation in env.path entries?
Oh sorry, I thought you wanted it to run after the tools are loaded, this makes sense
I seem to not be able to view your branch, not sure if that's because I'm on my phone
Hm. I'll open a PR in your repo later today so you take a look.
oh it works on my computer, go ahead and submit a PR—first glance it looks solid 👍
@jdx FYI https://github.com/jdx/mise/pull/2310