Understanding nix-channels, nix-env and nix-shell

I have a custom nix-channel that I have built. It only has a small set of packages that I have created. I can install these packages just fine with nix-env -i <package-name> but I can get nix-shell or nix run to recognize them. I realize that nix-env doesn’t use the NIX_PATH. However, I can’t figure out how to call nix-shell in a way that gives it access to these packages. That severely limits the usefulness of the channel. I can’t just point nixpkgs= in NIX_PATH to that channel because it only contains a small set of packages, not the entire set of nix packages.

Also note that these are not public packages that can be added to the global nix repo.

So whats the magic incantation for nix shell to make these packages available to it?

1 Like

You could assign it a different name than nixpkgs. E.g.:

$ export NIX_PATH=$NIX_PATH:foobar=https://github.com/danieldk/nix-packages/archive/master.tar.gz
$ nix run foobar.citar
$ nix-shell -p '(import <foobar>) citar'

There might be a shorter way to do this with nix-shell. Though I generally prefer exposing a package set as an attribute through packageOverrides over using channels. See:


1 Like

Note that with the nix xxx family of commands (without the dash) it requires a recent enough version for it to use the channels in NIX_PATH like this. See "nix search" duplicate results in brand-new NixOS install. How to fix? - #35 by layus in particular, completed by the linked pages and the whole discussion.