nixpkgs/pkgs/top-level/impure.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

42 lines
1.5 KiB
Nix

/* Impure default args for `pkgs/top-level/default.nix`. See that file
for the meaning of each argument. */
{ # Fallback: Assume we are building packages for the current (host, in GNU
# Autotools parlance) system.
system ? builtins.currentSystem
, # Fallback: The contents of the configuration file found at $NIXPKGS_CONFIG or
# $HOME/.nixpkgs/config.nix.
config ? let
inherit (builtins) getEnv pathExists;
configFile = getEnv "NIXPKGS_CONFIG";
homeDir = getEnv "HOME";
configFile2 = homeDir + "/.nixpkgs/config.nix";
in
if configFile != "" && pathExists configFile then import configFile
else if homeDir != "" && pathExists configFile2 then import configFile2
else {}
, # Overlays are used to extend Nixpkgs collection with additional
# collections of packages. These collection of packages are part of the
# fix-point made by Nixpkgs.
overlays ? let
inherit (builtins) getEnv pathExists readDir attrNames map sort
lessThan;
dirEnv = getEnv "NIXPKGS_OVERLAYS";
dirHome = (getEnv "HOME") + "/.nixpkgs/overlays";
dirCheck = dir: dir != "" && pathExists (dir + "/.");
overlays = dir:
let content = readDir dir; in
map (n: import "${dir}/${n}") (sort lessThan (attrNames content));
in
if dirCheck dirEnv then overlays dirEnv
else if dirCheck dirHome then overlays dirHome
else []
, ...
} @ args:
import ./. (args // { inherit system config overlays; })