nix-community / nix-direnv

A fast, persistent use_nix/use_flake implementation for direnv [maintainer=@Mic92 / @bbenne10]
MIT License
1.78k stars 101 forks source link

nix-direnv produces a different profile/profile_rc paths when executed on emacs #459

Closed korayal closed 9 months ago

korayal commented 9 months ago

I'd like to use nix_direnv_manual_reload on my project, so that I don't have to get blocked on emacs waiting for direnv to load (which sometimes takes minutes).

But, I noticed that even though there's an existing cache for nix-direnv which works fine on my shell, I always get the same warning in the *envrc* buffer, when I load the project in emacs. So, I modified the direnvrc file to output more logging, like printing the current $profile_rc and $profile values.

And then I noticed that the profile and profile_rc variables are different between the two (my terminal vs the emacs' *envrc* buffer)

So, now there are two nix-profile-* paths, and the call to nix_clear_old_gc_roots just deletes the one created (or attempted to be created) by emacs. When I tried to create those files myself, they just got deleted after the build.

So, the problem is, for some reason, I'm getting two separate $profile variables between these two use cases.

korayal commented 9 months ago

Right after posting this message, I noticed that the output of nix eval --impure --expr "<nixpkgs>" was different between my shell vs emacs. The former was correctly pointing to my local ~/.nix-defexr/channels/nixpkgs whereas the latter one was pointing to the root user's.

So, the versions were different, which caused me to get two different profiles.