Search code examples
nixnixosnixpkgs

What is the nix-expression "<nixpkgs>"?


When querying for hackage packages, the manual suggests using the command:

$ nix-env -f "<nixpkgs>" -qaP -A haskellPackages

Thus we define the 'active Nix expression' to be "<nixpkgs>" when searching for Haskell packages.

What does this expression "<nixpkgs>" mean and where is it defined? I do not have a channel by that name, nor do I see it occurring in my /etc/nixos/configuration.nix file.


Solution

  • From man nix-env (and likely other sources):

       NIX_PATH
           A colon-separated list of directories used to look up Nix
           expressions enclosed in angle brackets (i.e., <path>). For
           instance, the value
    
               /home/eelco/Dev:/etc/nixos
    
           will cause Nix to look for paths relative to /home/eelco/Dev and
           /etc/nixos, in that order. It is also possible to match paths
           against a prefix. For example, the value
    
               nixpkgs=/home/eelco/Dev/nixpkgs-branch:/etc/nixos
    
           will cause Nix to search for <nixpkgs/path> in
           /home/eelco/Dev/nixpkgs-branch/path and /etc/nixos/nixpkgs/path.
    

    On my machine, NIX_PATH is nixpkgs=/Users/me/.nix-defexpr/channels/nixpkgs, so <nixpkgs> refers to the nixpkgs channel that I am subscribed to.

    In general, <...> causes a path to be treated not literally, but as found in some directory specified by your NIX_PATH.