jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
8.11k stars 214 forks source link

Use mise tools in env template #1982

Open abatilo opened 2 months ago

abatilo commented 2 months ago

I'd love to be able to use mise installed tools to execute env exec templates.

If I have the following example .mise.toml

[tools]
go = "latest"

[env]
EXAMPLE = "{{exec(command='go version')}}"

I'd hope that EXAMPLE would get populated with the output of go version.

Instead I see the following error:

bash: go: command not found
mise failed to parse template: '{{exec(command='go version')}}'
mise Failed to render '__tera_one_off'
mise Function call 'exec' failed
mise Io error while writing rendered value to output: Other
mise command ["bash", "-c", "go version"] exited with code 127
mise Run with --verbose or MISE_VERBOSE=1 for more information

I tried also using mise exec to execute the command but that didn't work either.

jdx commented 2 months ago

the trouble is people also need some env vars to be loaded before tools. I wonder if maybe we could use [env.post] as a way to mark env vars that should be processed after tools are loaded or something.

jdx commented 2 months ago

another idea:

[env]
EXAMPLE = {value="{{exec(command='go version')}}", when="after_tools"}
abatilo commented 2 months ago

Oh, that's an interesting idea. I hadn't considered the idea of putting hooks in with the env execution also but in hindsight it makes a lot of sense!

richdawe-cio commented 1 month ago

An example of where this would be helpful at my work:

We're using mise to manage our local development environments. We're using FoundationDB with some go bindings that are use cgo to wrap the FoundationDB client libraries. We have foundationdb in the tools config section, and we're defining CGO_CPPFLAGS and other CGO_xxx environment variables in the env config section. These are all dependent on the install path for foundationdb, e.g.: ~/.local/share/mise/installs/foundationdb/x.y.z.

Right now we're using something like this:

[env]
# Needed for FoundationDB.
FDB_LOCATION = "{{exec(command='mise where foundationdb 2>/dev/null || true')}}"
CGO_CPPFLAGS = '-I{{ env.FDB_LOCATION }}/usr/local/include'

But it would be better if we could use something like

FDB_LOCATION = "{{tools(name='foundationdb').install_path}}"

or something like that.

Side note: Use of "{{exec(command='mise where ...')}}" seems to cause a fork-bomb with 2024.6.0 (mise calling mise calling mise etc.), which didn't happen with 2024.5.2.