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