The command nix-env is used to manipulate Nix user environments. User environments are sets of software packages available to a user at some point in time. In other words, they are a synthesised view of the programs available in the Nix store. There may be many user environments: different users can have different environments, and individual users can switch between different environments.— From the Nix manual
.nix-defexpr defines how packages are made available to
$ cat .nix-defexpr/test/foo/default.nix import /home/clever/apps/nixpkgs
This creates a foo channel, so i can now
nix-env -iA foo.hello. All
nix-env cares about, is that it returns a function, which returns a package set, so you can import any nixpkgs you want, fetched any way you want, or have entirely custom package sets.
For a more complete explanation of how things work:
nix-env will recursively search
~/.nix-defexpr/ until it either finds <name>.nix or
<name>/default.nix, and then create a channel with
Any directories above that (like test in the example above) are basically ignored, but allow you to symlink into dirs owned by other users.