nix-community / lorri

Your project’s nix-env [maintainer=@Profpatsch,@nyarly]
Apache License 2.0
638 stars 24 forks source link

lorri direnv reset `XDG_DATA_DIRS`. #48

Closed Vonfry closed 2 years ago

Vonfry commented 3 years ago

Describe the bug

XDG_DATA_DIRS is overrided which breaks actions like xdg-open with custom mimeapps.list.

To Reproduce Steps to reproduce the behavior:

  1. Enter a dir
  2. lorri init
  3. shell.nix with patchelf
  4. echo $XDG_DATA_DIRS
  5. direnv allow
  6. After shell updating, echo $XDG_DATA_DIRS

Expected behavior

Some variable should not be override or append with its old value like XDG_DATA_DIRS.

Metadata

$ lorri info
lorri version: 1.5
GC roots exist, shell_gc_root: /home/vonfry/.cache/lorri/gc_roots/c32f056103b9fc7dbad5c6b925e2be4e/gc_root/shell_gc_root
$ uname -a
Linux pc-lab-shmtu 5.10.37 #1-NixOS SMP Fri May 14 07:50:46 UTC 2021 x86_64 GNU/Linux

Additional context

nix-direnv doesn't have the problem. It do sth like this.

neumantm commented 3 years ago

Can confirm. This totally breaks xdg-open for me.

Profpatsch commented 3 years ago

It’s not done by lorri, but rather the nix-shell will set that variable and override the existing one.

We could maybe do something custom, but idk how reasonable that is.

neumantm commented 3 years ago

Ok. How does nix-shell determine how to set XDG_DATA_DIRS? Becuase inside a normal nix-shell xdg-open works just fine. (In a --pure shell it does not work as expected, but differently from inside lorri)

Also: Before updating my nixos to 21-05 I never had problems with xdg-open in lorri, so something must have changed in lorri, nix-shell or somewhere else in nixos.

Profpatsch commented 3 years ago

How does nix-shell determine how to set XDG_DATA_DIRS?

I don’t know how much nix intuition you have, but nix-shell (and by extension lorri, more or less) just goes into the nix builder scope, which sets the environment as it is declared in the nix .drv file.Actually, I’m not sure.

In your project, run

nix-shell -p haskellPackages.nix-derivation --run "pretty-derivation < $(nix-instantiate shell.nix)" | less

To see a pretty-printed version of your shell’s drv file.

However, I don’t see any mention of XDG_* in there, and it still overwrites it in lorri direnv, while prepending in nix-shell (without --pure).

So obviously it is set somewhere, but I wasn’t able to reconstruct where it comes from so far. It’s been a while since I thought about these parts of lorri and the nixpkgs stdenv. Maybe just appending it to the magic list in

https://github.com/nix-community/lorri/blob/dd45c1f0ebea90102a0fe9b5fcc701302e71f1f6/src/ops/direnv/envrc.bash#L119-L161

might do the trick.

jm-g commented 3 years ago

The resetting of XDG_DATA_DIRS also breaks git's bash-completion if it hasn't been loaded before entering the project with lorri direnv. If I move away the lorri calling .envrc and enter the a nix-shell directly, this does not happen. I.e. XDG_DATA_DIRS keeps its value. In general lorri seems to set all environment variables available during package build.

declare -x NIX_BINTOOLS="/nix/store/wp3f8kbdaw6hm6k40yp0cpxnvs6dqqk9-binutils-wrapper-2.35.1" declare -x NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu="1" declare -x NIX_BUILD_CORES="32" declare -x NIX_BUILD_TOP="/build" declare -x NIX_CC="/nix/store/gg2rq3hrl3rf92nq6dnqhdyyxaa89aqf-gcc-wrapper-10.3.0" declare -x NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu="1" declare -x NIX_CFLAGS_COMPILE=" -frandom-seed=3if9ky04z2 -isystem /nix/store/iln9cv58v7cfizsw2a6yczny2bbqxyx8-adoptopenjdk-hotspot-bin-11.0.10/include -isystem /nix/store/iln9cv58v7cfizsw2a6yczny2bbqxyx8-adoptopenjdk-hotspot-bin-11.0.10/include" declare -x NIX_ENFORCE_NO_NATIVE="1" declare -x NIX_ENFORCE_PURITY="1" declare -x NIX_HARDENING_ENABLE="fortify stackprotector pic strictoverflow format relro bindnow"

To me it seems questionable that this approach is worthwhile. lorri maintains a list of variable to not redefine. But that leads to a whack-a-mole game to filter out all environment variables that should not end up in direnv.

jsravn commented 2 years ago

Also running into this, it only started on Nixos 21.05 - was fine on 20.09. It makes lorri sort of unusable.

adrian-gierakowski commented 2 years ago

It’s not done by lorri, but rather the nix-shell will set that variable and override the existing one.

We could maybe do something custom, but idk how reasonable that is.

I'm on nix v2.9.1 and nix-shell not overwrite XDG_DATA_DIRS (it correctly adds to it), however lorri shell does

> lorri --version
lorri 1.5.0

https://github.com/nix-community/lorri/pull/61 claims to fix this but doesn't seem like there has been an official release since then and it has not been propagated to nixpkgs