nixpkgs/pkgs/top-level/default.nix
Nicolas B. Pierron f5dfe78a1e Add overlays mechanism to Nixpkgs.
This patch add a new argument to Nixpkgs default expression named "overlays".

By default, the value of the argument is either taken from the environment variable `NIXPKGS_OVERLAYS`,
or from the directory `~/.nixpkgs/overlays/`.  If the environment variable does not name a valid directory
then this mechanism would fallback on the home directory.  If the home directory does not exists it will
fallback on an empty list of overlays.

The overlays directory should contain the list of extra Nixpkgs stages which would be used to extend the
content of Nixpkgs, with additional set of packages.  The overlays, i-e directory, files, symbolic links
are used in alphabetical order.

The simplest overlay which extends Nixpkgs with nothing looks like:

```nix
self: super: {
}
```

More refined overlays can use `super` as the basis for building new packages, and `self` as a way to query
the final result of the fix-point.

An example of overlay which extends Nixpkgs with a small set of packages can be found at:
  https://github.com/nbp/nixpkgs-mozilla/blob/nixpkgs-overlay/moz-overlay.nix

To use this file, checkout the repository and add a symbolic link to
the `moz-overlay.nix` file in `~/.nixpkgs/overlays` directory.
2017-01-16 01:17:33 +01:00

91 lines
3.2 KiB
Nix

/* This function composes the Nix Packages collection. It:
1. Applies the final stage to the given `config` if it is a function
2. Infers an appropriate `platform` based on the `system` if none is
provided
3. Defaults to no non-standard config and no cross-compilation target
4. Uses the above to infer the default standard environment's (stdenv's)
stages if no stdenv's are provided
5. Folds the stages to yield the final fully booted package set for the
chosen stdenv
Use `impure.nix` to also infer the `system` based on the one on which
evaluation is taking place, and the configuration from environment variables
or dot-files. */
{ # The system (e.g., `i686-linux') for which to build the packages.
system
, # Allow a configuration attribute set to be passed in as an argument.
config ? {}
, # List of overlays layers used to extend Nixpkgs.
overlays ? []
, # A function booting the final package set for a specific standard
# environment. See below for the arguments given to that function,
# the type of list it returns.
stdenvStages ? import ../stdenv
, crossSystem ? null
, platform ? assert false; null
} @ args:
let # Rename the function arguments
configExpr = config;
in let
lib = import ../../lib;
# Allow both:
# { /* the config */ } and
# { pkgs, ... } : { /* the config */ }
config =
if builtins.isFunction configExpr
then configExpr { inherit pkgs; }
else configExpr;
# Allow setting the platform in the config file. Otherwise, let's use a
# reasonable default.
platform =
args.platform
or ( config.platform
or ((import ./platforms.nix).selectPlatformBySystem system) );
# A few packages make a new package set to draw their dependencies from.
# (Currently to get a cross tool chain, or forced-i686 package.) Rather than
# give `all-packages.nix` all the arguments to this function, even ones that
# don't concern it, we give it this function to "re-call" nixpkgs, inheriting
# whatever arguments it doesn't explicitly provide. This way,
# `all-packages.nix` doesn't know more than it needs too.
#
# It's OK that `args` doesn't include default arguemtns from this file:
# they'll be deterministically inferred. In fact we must *not* include them,
# because it's important that if some parameter which affects the default is
# substituted with a different argument, the default is re-inferred.
#
# To put this in concrete terms, this function is basically just used today to
# use package for a different platform for the current platform (namely cross
# compiling toolchains and 32-bit packages on x86_64). In both those cases we
# want the provided non-native `system` argument to affect the stdenv chosen.
nixpkgsFun = newArgs: import ./. (args // newArgs);
# Partially apply some arguments for building bootstraping stage pkgs
# sets. Only apply arguments which no stdenv would want to override.
allPackages = newArgs: import ./stage.nix ({
inherit lib nixpkgsFun;
} // newArgs);
boot = import ../stdenv/booter.nix { inherit lib allPackages; };
stages = stdenvStages {
inherit lib system platform crossSystem config overlays;
};
pkgs = boot stages;
in pkgs