nix-bash-completions
nix-bash-completions copied to clipboard
Fix completion with Nix 2.4+ on non-NixOS
Nix 2.4+ stopped setting NIX_PATH in the environment and instead uses a
built-in default in the C++ code (not exposed to shell processes). That
means this completion codes sees $override as empty and runs NIX_PATH= nix-instantiate ...
.
Setting NIX_PATH to an empty string means Nix
won't use its default built-in value and completion breaks (assuming
the completion depends on <nixpkgs>
or similar search path entries).
NixOS isn't affected because there NIX_PATH is still set (by the OS, not by code from the Nix repo).
The fix is to not pass NIX_PATH unless we have a value for it. That works for both old and new Nix, on NixOS and non-NixOS.