pixi icon indicating copy to clipboard operation
pixi copied to clipboard

Add tutorial on how to use direnv with pixi

Open Hofer-Julian opened this issue 11 months ago • 4 comments

Direnv is a nice tool, that automatically runs a script defined in .envrc as soon as one is entering the directory. Zed supports it out of the box and vscode has an extension.

This is especially useful when pixi is used with languages other than Python. We should add a tutorial on how to set this up.

Hofer-Julian avatar Feb 13 '25 09:02 Hofer-Julian

The Python VSCode extension has two modes when running things:

  1. running anything in debug mode. here, a shell command is being executed. as long as you ran direnv allow before, it works even without the direnv extension
  2. running tests invoke a subprocess directly without the extra shell. here, the direnv extension is needed

pavelzw avatar Feb 17 '25 12:02 pavelzw

@baszalmstra please reopen

pavelzw avatar Oct 02 '25 06:10 pavelzw

To use direnv with pixi is actually pretty useful. Just two line in .direnv file can do the trick:

watch_file pixi.lock
eval "$(pixi shell-hook)"

watch_file: simply looks for the changes, if made any reloads the variables accordingly. (See: https://github.com/direnv/direnv/blob/1418f217e5caf4af120b1a8482522a5c69edfd6e/stdlib.sh#L410C1-L410C48, no docs yet)

Even simplified with the VSCode extension:

  • Go to command pallet > envrc > create a new .envrc file
  • Now past those two line here.

Final result:

  • Every time you open the project, the the pixi environment loads automatically!

I can open a PR in the docs if this is meaningful.

prady0t avatar Nov 10 '25 21:11 prady0t

Yes, please @prady0t

Hofer-Julian avatar Nov 11 '25 19:11 Hofer-Julian

We can close this as we already have the info in the docs: https://pixi.sh/latest/integration/third_party/direnv/

prady0t avatar Nov 16 '25 19:11 prady0t