Skip to content
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

Lazily evaluated env template variables in path entries #1912

Closed
josb opened this issue Apr 17, 2024 · 9 comments
Closed

Lazily evaluated env template variables in path entries #1912

josb opened this issue Apr 17, 2024 · 9 comments

Comments

@josb
Copy link
Contributor

josb commented Apr 17, 2024

Setup:

  • HOME=/Users/john
  • A global config.tomlfile with:
    • a _.path template entry with value "{{env.GEM_HOME}}/bin"
    • an env entry: GEM_HOME = "{{env.HOME}}/.gem"
  • A .mise.toml file in some directory under the home directory with:
    • an env entry: GEM_HOME = "{{env.HOME}}/.mise-gemsets/foo"

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!

@josb
Copy link
Contributor Author

josb commented Jun 18, 2024

@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.

@jdx
Copy link
Owner

jdx commented Jun 19, 2024

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

@josb
Copy link
Contributor Author

josb commented Jun 19, 2024

Do you mean #1982? That seems to not concern env var evaluation in env.path entries?

@jdx
Copy link
Owner

jdx commented Jun 19, 2024

Oh sorry, I thought you wanted it to run after the tools are loaded, this makes sense

@jdx
Copy link
Owner

jdx commented Jun 19, 2024

I seem to not be able to view your branch, not sure if that's because I'm on my phone

@josb
Copy link
Contributor Author

josb commented Jun 19, 2024

Hm. I'll open a PR in your repo later today so you take a look.

@jdx
Copy link
Owner

jdx commented Jun 19, 2024

oh it works on my computer, go ahead and submit a PR—first glance it looks solid 👍

@josb
Copy link
Contributor Author

josb commented Jun 27, 2024

@jdx FYI #2310

jdx added a commit that referenced this issue Dec 16, 2024
jdx added a commit that referenced this issue Dec 16, 2024
jdx added a commit that referenced this issue Dec 16, 2024
@jdx jdx closed this as completed in ca33515 Dec 16, 2024
@josb
Copy link
Contributor Author

josb commented Dec 16, 2024

Thank you, @jdx! Much appreciated. 🙏

miguelmig pushed a commit to miguelmig/mise that referenced this issue Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants