direnv icon indicating copy to clipboard operation
direnv copied to clipboard

use nix replaces environment variables instead of appending

Open andre-krueger opened this issue 3 years ago • 3 comments

Describe the bug I noticed today that for example XDG_DATA_DIRS gets replaced with the nix path (/nix/SOME_HASH-patchelf-0.12/share) when using the .envrc with use nix. This resulted in a crashing Emacs for me, as some icons couldn't be found. I'm using Emacs inside a Fedora Toolbox and Emacs was installed via dnf. When I added the keep flag to the .envrc file, it worked again.

To Reproduce Setup nix inside a Fedora Toolbox. Install Emacs and direnv inside the Fedora Toolbox via dnf. Create a .envrc and a shell.nix inside a directory with use nix and allow it. Launch Emacs inside the directory with the .envrc.

You should get something like this:

(emacs:89820): GLib-GIO-CRITICAL **: 12:38:20.196: g_settings_schema_source_lookup: assertion 'source != NULL' failed

(emacs:89820): Gtk-WARNING **: 12:38:20.369: Could not load a pixbuf from /org/gtk/libgtk/icons/32x32/status/image-missing.png.
This may indicate that pixbuf loaders or the mime database could not be found.
**
Gtk:ERROR:gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unrecognized image file format (gdk-pixbuf-error-quark, 3)
Bail out! Gtk:ERROR:gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unrecognized image file format (gdk-pixbuf-error-quark, 3)
Fatal error 6: Unknown signal

The issue can be resolved by either adding --keep XDG_DATA_DIRS to .envrc, or by launching the shell with nix-shell without any direnv involvement.

Expected behavior Direnv's use nix should work like normal nix-shell and rather append environment variables instead of replacing them (when possible, of course).

Environment

  • OS: [Fedora Silverblue 33]
  • Shell: [bash]
  • Direnv version [2.27.0]

Additional context Add any other context about the problem here.

andre-krueger avatar Mar 15 '21 11:03 andre-krueger

I suffer from the same behaviour, though it's not as bad as my editor crashing, instead it's xdg-open that fails due to $XDG_DATA_DIRS not pointing to the system .desktop files.

A separate question, @akrger, where did you find out about the --keep flag? I can't find any mention of it in any documentation for direnv :thinking:

magthe avatar Apr 12 '21 10:04 magthe

The flag is for nix-shell. https://nixos.org/manual/nix/unstable/command-ref/nix-shell.html

andre-krueger avatar Apr 12 '21 17:04 andre-krueger

Perhaps a list of special "append/prepend only" environment variables is in order? Such a solution may scale much better than PATH_add

pbsds avatar Feb 16 '22 00:02 pbsds

Ran into this with use flake, which doesn't take --keep (since nix print-dev-env doesn't know about that flag). Worked around as follows:

_saved_xdg_dta=$XDG_DATA_DIRS
use flake
export XDG_DATA_DIRS=$XDG_DATA_DIRS:$_saved_xdg_dta

rimmington avatar Dec 28 '22 04:12 rimmington