Nix (not NixOS) "error: attribute 'nixos' in selection path"

I installed Nix on Darwin on macOS Catalina 10.15.6 (19G73).

Using nix-env, every package results in the error code:
error: attribute ‘nixos’ in selection path ‘nixos.some-package-name’ not found.

I believe it’s a path error but I do not know how to correct it.

The nixos. prefix there refers to a channel registered via nix-channel

nix-channel --list will show the channels you have registered
nix-channel --update will update them

This page in the manual helps a bit, though we should extend it to show an explicit nix-env example. Introduction

Execution of:

nix-channel --list

outputs: nixpkgs nixpkgs-unstable release nixpkgs-21.11pre326916.7053541084b

I did not grasp why that command would be relevant to solving this issue. Regardless, I re-executed a nix-env -iA nixos.some-package. I received the same error.

Also, I read the chapter, but I did not find anything that addresses the issue I am raising above. Perhaps I am overlooking something. I have read a fair bit of the documentation and have not come across anything explicitly that raises or resolves this issue.

Basically you are supposed to use <channel-name>.<package>. Since the listing shows that you have nixpkgs channel (which is default on non-NixOS) you should be using nix-env -iA nixpkgs.some-package, not nixos.some-package.

It’s a bit confusing, but the difference is largely historic. For nix-env, you can use nix-env -f '<nixpkgs>' -iA some-package if you want your command to work on both setups. I have this alias set up:

alias nixpkgs="nix-env -f '<nixpkgs>'"

The new command nix, IIRC, nixpkgs.some-packages works for both NixOS and just Nix, however it’s still lacking in features and doesn’t do what nix-env does yet so you still have to use nix-env for now.

1 Like

Your suggestion worked. Thank you!