Hi Ben,

On Fri, Feb 20 2026, Ben Sturmfels wrote:
> I noticed that the common direnv idiom with "--pure" isn't quite pure,
> in that it doesn't clear existing environment variables. Has anyone
> come up with an approach that does clear the environment fully?
>
> You typically put something like this in your .direnv file:
>
>   eval "$(guix shell --search-paths --pure ...)"

These days I just have either "use guix --manifest=manifest.scm" or "use
guix --development --file=guix.scm". The eval/--search-paths call is
handled by direnv itself.

I haven't tried adding --pure to "use guix", but I wonder if that would
help?

I'm not optimistic about it isolating everything, though. Direnv's
website[1] says this:

"direnv is not loading the .envrc into the current shell. It’s creating
a new bash sub-process to load the stdlib, direnvrc and .envrc, and only
exports the environment diff back to the original shell."

Based on this, I think Guix would have to export all unused environment
variables as empty strings to get close to the outcome you want (because
I don't think we can unset things inside the "use guix" call).

You might be able to do it with something like this (which I just tried
out):

--8<---------------cut here---------------start------------->8---
unset IFS
for var in $(compgen -e); do
    if [ "$var" != "PATH" ]; then # still need to find Guix!
       unset "$var"
    fi
done

use guix --manifest=manifest.scm --pure
--8<---------------cut here---------------end--------------->8---

but that makes me a bit uncomfortable. I don't know for sure that it
works properly in all cases, but it seemed to work as an initial
attempt.

Carlo

Reply via email to