Nix-env

From NixOS Wiki
Jump to: navigation, search
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

The folder .nix-defexpr defines how packages are made available to nix-env.

$ 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.

Technical Background

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 <name>. Any directories above that (like test in the example above) are basically ignored, but allow you to symlink into dirs owned by other users.