xzfc / cached-nix-shell

Instant startup time for nix-shell
https://xzfc.github.io/cached-nix-shell/cached-nix-shell.1
The Unlicense
195 stars 16 forks source link

git autocomplete does not work in cached-nix-shell #19

Closed Zimmi48 closed 3 years ago

Zimmi48 commented 3 years ago

Hi,

I've observed the following problematic difference between nix-shell and cached-nix-shell. In the latter, the autocompletion of git doesn't work while it does in the former.

My version of cached-nix-shell is 0.1.4, I've installed both cached-nix-shell and git system-wide with nixpkgs-unstable version b6bca3d80619f1565ba0ea635b0d38234e41c6bd, and I've got programs.bash.enableCompletion = true in my NixOS configuration.

Thanks in advance for your help!

xzfc commented 3 years ago

Bash checks its completion scripts in $XDG_DATA_DIRS, and in a recent change in Nixpkgs, it became non-empty in the default pure nix-shell.

$ nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'; nix-shell --pure -p --run 'echo XDG_DATA_DIRS=$XDG_DATA_DIRS'
"21.03pre252388.069f183f16c"
XDG_DATA_DIRS=

$ nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'; nix-shell --pure -p --run 'echo XDG_DATA_DIRS=$XDG_DATA_DIRS'
"21.03pre257780.e9158eca70a"
XDG_DATA_DIRS=/nix/store/i7kr24hdryyvcjj1aag9j8dy0dy8za4a-patchelf-0.12/share

Cached-nix-shell overrides ambient $XDG_DATA_DIRS with this one instead of prepending to it. It's a limitation of how c-n-s currently works.


As a temporary workaround, I recommend you to run cached-nix-shell with the --keep XDG_DATA_DIRS option. E.g.

alias cached-nix-shell='cached-nix-shell --keep XDG_DATA_DIRS'
Zimmi48 commented 3 years ago

Thanks a lot for your advice! From my side, the problem is resolved, so should I close this?

xzfc commented 3 years ago

Sure, I close it then.