$ nix-channel --list # Show the default channel.
nixpkgs https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --add https://nixos.org/channels/nixos-20.09 # Add stable channel.
$ nix-channel --update
unpacking channels...
created 2 symlinks in user environment
$ nix-channel --remove nixpkgs # Remove the default channel.
uninstalling 'nixpkgs-21.05pre272788.870dbb751f4'
building '/nix/store/h11za3c6ja8hgrlkcs8nznib02wlp9cs-user-environment.drv'...
$ nix-channel --list
nixos-20.09 https://nixos.org/channels/nixos-20.09
Now I encounter an error when I try to use nix-shell:
$ nix-shell --pure --packages htop hello
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:13
It appears that nix-shell expects a nixpkgs channel. I no longer have a channel named nixpkgs because I deleted it when I switched to a stable channel. How can I run nix-shell in this case?
Edit: Aah, but that’s not what you’re after, is it? What I’ve shown you allows you to use specific versions of nixpkgs, but I think you want to use the channels for their automatic update. As I avoid channels precisely because they change implicitly, I don’t know how to do what you want off the top of my head … and my vague recollections aren’t borne out by the docs: I thought you had to add the nixpkgs at the end with something like this:
There is no expectation of any channels, though instead it assumes that the path<nixpkgs> resolves. Read more about the resolution process in man nix, somewhere near the -I and NIX_PATH.
You might be able to use nix-shell -p '"nixos-20.09".hello' in your current situation.