Hi,
I have some shell.nix that defines an environment. I log into it with
nix-shell
When I start emacs from within this shell, it doesn’t inherit the environment. In particular, emacs looks at the system wide PATH, and doesn’t find packages in my nix-shell. However, when I type emacs -nw, emacs correctly inherits PATH as defined in the nix-shell. Now, as some may knowemacs -nw runs emacs directly within the terminal, without GUI.
Is this behavior expected? I thought when starting emacs from within the nix-shell, the environment should be inherited, even when the GUI is used. Emacs I did not define in nix-shell, it is a system wide installation
Hmmm, that definitely seems like it should work. I don’t have an answer for you, except that emacs can’t count on being launched from a shell and so maybe can’t depend on things like $PATH always existing.
They’ve discussed it on the mailing list and wiki. I know doom emacs for one grabs its environment from the last time you ran doom sync or doom env.
As a workaround, I can thoroughly recommend nix-direnv and the associated corresponding envrc.el, but that does involve putting a minimal .envrc in all your projects.
Thanks for the reply, in fact I am using doomemacs. But I don’t think the issue is related to Doom, since it works with emacs -nw.
Interestingly, when I do export bla=BLUB in the nix shell and then open GUI emacs, it sees the variable. Also, I can change other variables defined in my shell.nix. It seems only PATH is not inherited.
Well, you were right! doom sync in the nix shell did the trick. Now GUI emacs inherits PATH. But, I have to say, this confuses me, because, since Doom’s PATH is fixed till the next sync, I now can access programs defined in shell.nix outside the nix-shell, even though I did not make it available system wide. Is that a bug? Or a feature? I’m not sure.
Still confusing that emacs -nw worked without doom sync