summary refs log tree commit diff
path: root/pkgs/top-level/impure.nix
blob: 60a55c657c0c021141b3d43a50e85eff1c8d4118 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* 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 dirEnv != "" then
        if dirCheck dirEnv then overlays dirEnv
        else throw "The environment variable NIXPKGS_OVERLAYS does not name a valid directory."
      else if dirCheck dirHome then overlays dirHome
      else []

, ...
} @ args:

import ./. (args // { inherit system config overlays; })