Search code examples
nixnixos

What does the <nixpkgs> string / value mean in Nix?


For example in the following (which I assume is a nix expression):

(import <nixpkgs> {}).haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [
    lens
    aeson
    turtle
])

What does <nixpkgs> reference? I also see it used in other contexts for example:

nix-shell '<nixpkgs>' -A linuxPackages.kernel

Solution

  • <nixpkgs> is a Nix expression that is evaluated by looking at the Nix search path in the NIX_PATH environment variable and/or -I option.

    It is described in more detail in the Nix manual.

    Note that the Nix search path is impractical in many situations. You can only pass it from the outside, and it easily creates impurity. In my experience, problems are better solved with explicit argument passing or the functions relating to fix-points like callPackage and the overlay system.

    As an example, NixOS has only one extra search path parameter, and it is only read once in nixos/default.nix if no explicit configuration is given. This way, you have the flexibility to provide your own configuration, which is why you (nix-build) and hydra can confidently build the NixOS VM tests, bootable images, docker images, etc.