I am using the NIx package manager (without NixOS). The default channel is nixpkgs-unstable release nixpkgs-24.05pre583512.01737456dfe4. I changed it to a stable channel (nixos-20.09 release nixos-20.09.4407.1c1f5649bb9) like this:
$ 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 --list
nixos-20.09 https://nixos.org/channels/nixos-20.09
nixpkgs https://nixos.org/channels/nixpkgs-unstable
$ 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
To install GNU Hello, I tried:
$ nix-env -iA nixpkgs.hello
error: attribute 'nixpkgs' in selection path 'nixpkgs.hello' not found
I also tried:
$ nix-env -iA nixos-20.09.hello
error: attribute 'nixos-20' in selection path 'nixos-20.09.hello' not found
I finally succeeded in installing GNU Hello by running:
$ nix-env -f '<nixos-20.09>' -iA hello
I’m wondering: if I have switched the default unstable channel to a stable channel, how do I avoid the need to specify -f '<nixos-20.09>'
every time I run nix-env
to install software?