lol
1/*
2 Impure default args for `pkgs/top-level/default.nix`. See that file
3 for the meaning of each argument.
4*/
5
6let
7
8 homeDir = builtins.getEnv "HOME";
9
10 # Return ‘x’ if it evaluates, or ‘def’ if it throws an exception.
11 try =
12 x: def:
13 let
14 res = builtins.tryEval x;
15 in
16 if res.success then res.value else def;
17
18in
19
20{
21 # We put legacy `system` into `localSystem`, if `localSystem` was not passed.
22 # If neither is passed, assume we are building packages on the current
23 # (build, in GNU Autotools parlance) platform.
24 localSystem ? {
25 system = args.system or builtins.currentSystem;
26 },
27
28 # These are needed only because nix's `--arg` command-line logic doesn't work
29 # with unnamed parameters allowed by ...
30 system ? localSystem.system,
31 crossSystem ? localSystem,
32
33 # Fallback: The contents of the configuration file found at $NIXPKGS_CONFIG or
34 # $HOME/.config/nixpkgs/config.nix.
35 config ?
36 let
37 configFile = builtins.getEnv "NIXPKGS_CONFIG";
38 configFile2 = homeDir + "/.config/nixpkgs/config.nix";
39 configFile3 = homeDir + "/.nixpkgs/config.nix"; # obsolete
40 in
41 if configFile != "" && builtins.pathExists configFile then
42 import configFile
43 else if homeDir != "" && builtins.pathExists configFile2 then
44 import configFile2
45 else if homeDir != "" && builtins.pathExists configFile3 then
46 import configFile3
47 else
48 { },
49
50 # Overlays are used to extend Nixpkgs collection with additional
51 # collections of packages. These collection of packages are part of the
52 # fix-point made by Nixpkgs.
53 overlays ?
54 let
55 isDir = path: builtins.pathExists (path + "/.");
56 pathOverlays = try (toString <nixpkgs-overlays>) "";
57 homeOverlaysFile = homeDir + "/.config/nixpkgs/overlays.nix";
58 homeOverlaysDir = homeDir + "/.config/nixpkgs/overlays";
59 overlays =
60 path:
61 # check if the path is a directory or a file
62 if isDir path then
63 # it's a directory, so the set of overlays from the directory, ordered lexicographically
64 let
65 content = builtins.readDir path;
66 in
67 map (n: import (path + ("/" + n))) (
68 builtins.filter (
69 n:
70 (
71 builtins.match ".*\\.nix" n != null
72 &&
73 # ignore Emacs lock files (.#foo.nix)
74 builtins.match "\\.#.*" n == null
75 )
76 || builtins.pathExists (path + ("/" + n + "/default.nix"))
77 ) (builtins.attrNames content)
78 )
79 else
80 # it's a file, so the result is the contents of the file itself
81 import path;
82 in
83 if pathOverlays != "" && builtins.pathExists pathOverlays then
84 overlays pathOverlays
85 else if builtins.pathExists homeOverlaysFile && builtins.pathExists homeOverlaysDir then
86 throw ''
87 Nixpkgs overlays can be specified with ${homeOverlaysFile} or ${homeOverlaysDir}, but not both.
88 Please remove one of them and try again.
89 ''
90 else if builtins.pathExists homeOverlaysFile then
91 if isDir homeOverlaysFile then
92 throw (homeOverlaysFile + " should be a file")
93 else
94 overlays homeOverlaysFile
95 else if builtins.pathExists homeOverlaysDir then
96 if !(isDir homeOverlaysDir) then
97 throw (homeOverlaysDir + " should be a directory")
98 else
99 overlays homeOverlaysDir
100 else
101 [ ],
102
103 crossOverlays ? [ ],
104
105 ...
106}@args:
107
108# If `localSystem` was explicitly passed, legacy `system` should
109# not be passed, and vice-versa.
110assert args ? localSystem -> !(args ? system);
111assert args ? system -> !(args ? localSystem);
112
113import ./. (
114 builtins.removeAttrs args [ "system" ]
115 // {
116 inherit config overlays localSystem;
117 }
118)