Disabling channels breaks NIX_PATH resolution

If one sets the nix.channel.enable option to false on NixOS, then nix-instantiate (and other similar commands) no longer properly handle $NIX_PATH (but strangely, -I still works). For example,

NIX_PATH="hi=bye" nix-instantiate --eval -E "builtins.nixPath"

evaluates to

[ ]

but

nix-instantiate -I "hi=bye" --eval -E "builtins.nixPath"

evaluates to

[ { path = "bye"; prefix = "hi"; } ]

I read nix-channel.nix and the Nix Pill on Nix Search Paths but I’m still not quite sure why this happens. The changes to NIX_PATH/nix.nixPath/nix.settings.nix-path shouldn’t matter when the environmental variable is overwritten since the environmental variable should take priority, so I think it must be a side effect of not having a nix-channel binary.

Does anyone know why disabling channels prevents $NIX_PATH from resolving correctly and why $NIX_PATH and -I behave differently? Thanks!

(I discovered this while filing an issue about nix-info but I think it is of independent interest.)

2 Likes

Can confirm. The issue is still here.

This is a known issue in Nix itself: Broken `NIX_PATH` tracking issue · Issue #9574 · NixOS/nix · GitHub

See also nix-channel: do not set empty nix-path when disabling channels by oxalica · Pull Request #273170 · NixOS/nixpkgs · GitHub

2 Likes