pixi icon indicating copy to clipboard operation
pixi copied to clipboard

Adding support for environment variable in `inputs` and `outputs` field

Open RaphaelRibes opened this issue 9 months ago • 6 comments

I want to be adding support for environment variable in inputs and outputs field

Problem description

For example being able to do

[tasks.mkdir_test]
cmd = "mkdir -p $INIT_CWD/test"
outputs = ["$INIT_CWD/test"]

or

[tasks.mkdir_test]
args = [
    { arg = "root", default = "$INIT_CWD"}
]
cmd = "mkdir -p {{ root }}/test"
outputs = ["{{ root }}/test"]

For now it returns

pixi run mkdir_test 
✨ Pixi task (mkdir_test in default): mkdir -p $INIT_CWD/test
WARN No files matched the output globs for task 'mkdir_test'
WARN Output globs: `$INIT_CWD/test

Where it should return for example

pixi run mkdir_test 
✨ Pixi task (mkdir_test in default): mkdir -p $INIT_CWD/test

pixi run mkdir_test 
✨ Pixi task (mkdir_test in default): mkdir -p $INIT_CWD/test
Task '_mkdir_outputs' can be skipped (cache hit) 🚀 

ls
test/

With no warning

RaphaelRibes avatar Feb 10 '26 10:02 RaphaelRibes

hey can i work on this issue ?

Premkumar-2004 avatar Feb 10 '26 18:02 Premkumar-2004

I like the suggested syntax, and I think mise uses the same: https://mise.jdx.dev/environments/#environment-in-tasks

Another idea could be to use env.THING, similar to how rattler-build is exposing the env context, but I think it's too complex.

But @ruben-arts should give his approval on this

nichtmacho avatar Feb 10 '26 19:02 nichtmacho

Yeah I think we should scope to args!

baszalmstra avatar Feb 10 '26 19:02 baszalmstra

The $ENV_VAR would be a custom parsing job. Just like Nichita and Bas say. Doing it first for the args would be a good step forward. The env.THING would be nice but is much more involved. Because pixi can control the env. So which env does it use.

The {{ pixi.xxx }} standard arguments could potentionaly be extended with the init_cwd to help with simplifing the usecase in the initial issue description.

ruben-arts avatar Feb 11 '26 09:02 ruben-arts

I see INIT_CWD is set in get_task_env() in executable_task.rs at runtime. For the {{ pixi.init_cwd }} approach, should we use std::env::current_dir() directly in to_jinja_context(), or is there a preferred way to access this earlier in the rendering pipeline?

Premkumar-2004 avatar Feb 11 '26 16:02 Premkumar-2004

Feel free to make the PR, sounds like you have a pretty good idea of whats going on.

tdejager avatar Feb 13 '26 10:02 tdejager