I am using the NIx package manager (without NixOS). The default channel is nixpkgs-unstable release nixpkgs-21.11pre326916.7053541084b. I have changed it to a stable channel (nixos-20.09 release nixos-20.09.4407.1c1f5649bb9) like this:
$ nix-channel --list # Show the default channel.
$ nix-channel --add https://nixos.org/channels/nixos-20.09 # Add stable channel.
$ nix-channel --update
created 2 symlinks in user environment
$ nix-channel --remove nixpkgs # Remove the default channel.
$ nix-channel --list
Now I encounter an error when I try to use
$ 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?
Here’s a couple of ways:
You could get a hash from https://status.nixos.org/ and then use it like this
nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/15a64b2facc1b91f4361bdd101576e8886ef834b.tar.gz -p cowsay
You could clone GitHub - NixOS/nixpkgs: Nix Packages collection and then use it like this
nix-shell -I nixpkgs=path/to/your/clone/of/nixpkgs -p cowsay
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:
nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
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
You might be able to use
nix-shell -p '"nixos-20.09".hello' in your current situation.
Though the better way is probably to “rename” your current
nixos-20.09 channel to
nixpkgs as briefly described in How to switch to a stable channel and install using nix-env without needing the -f option? - #3 by NobbZ.