Should `nix shell` make bash completions available for the package?

I’m just noticing that if I open a new bash terminal and run nix shell nixpkgs#cargo completions for cargo don’t appear to work (e.g. cargo bui<tab> doesn’t do anything).

However, if I install cargo under system packages or home-manager, close and re-open my shell, the completions do appear to work.

It appears bash looks for completions under XDG_DATA_DIRS. When I enter a nix shell, I notice that XDG_DATA_DIRS doesn’t appear to change whether or not the package has a $out/share output.

Should I not be expecting completions to work under nix shell?

nix shell and Home Manager work very differently.

Setting XDG_DATA_DIR through nix profile was recently implemented here, including relevant design discussion that provides some background:

There is also a related discussion on whether we want Nix to be clever about environment variables: nix shell: set MANPATH for installables that have a man dir by sternenseemann · Pull Request #4702 · NixOS/nix · GitHub

Summary: Eelco finds we shouldn’t get into setting environment variables, because where would you draw the boundary?

I generally agree: Environment variables exposed by or relevant to packages should be an issue of the packages themselves, and nix shell should simply stack the environments it’s explicitly given.

So while it would surely be pragmatic to just add the new nix profile behavior to nix shell as a stopgap, the sustainable thing that should happen before stabilizing those parts of the new CLI should be devising a sane interface for packages to expose environments.

4 Likes