1 /* Impure default args for `pkgs/top-level/default.nix`. See that file
2 for the meaning of each argument. */
7 homeDir = builtins.getEnv "HOME";
9 # Return ‘x’ if it evaluates, or ‘def’ if it throws an exception.
10 try = x: def: let res = builtins.tryEval x; in if res.success then res.value else def;
14 { # We put legacy `system` into `localSystem`, if `localSystem` was not passed.
15 # If neither is passed, assume we are building packages on the current
16 # (build, in GNU Autotools parlance) platform.
17 localSystem ? { system = args.system or builtins.currentSystem; }
19 # These are needed only because nix's `--arg` command-line logic doesn't work
20 # with unnamed parameters allowed by ...
21 , system ? localSystem.system
22 , crossSystem ? localSystem
24 , # Fallback: The contents of the configuration file found at $NIXPKGS_CONFIG or
25 # $HOME/.config/nixpkgs/config.nix.
27 configFile = builtins.getEnv "NIXPKGS_CONFIG";
28 configFile2 = homeDir + "/.config/nixpkgs/config.nix";
29 configFile3 = homeDir + "/.nixpkgs/config.nix"; # obsolete
31 if configFile != "" && builtins.pathExists configFile then import configFile
32 else if homeDir != "" && builtins.pathExists configFile2 then import configFile2
33 else if homeDir != "" && builtins.pathExists configFile3 then import configFile3
36 , # Overlays are used to extend Nixpkgs collection with additional
37 # collections of packages. These collection of packages are part of the
38 # fix-point made by Nixpkgs.
40 isDir = path: builtins.pathExists (path + "/.");
41 pathOverlays = try (toString <nixpkgs-overlays>) "";
42 homeOverlaysFile = homeDir + "/.config/nixpkgs/overlays.nix";
43 homeOverlaysDir = homeDir + "/.config/nixpkgs/overlays";
45 # check if the path is a directory or a file
47 # it's a directory, so the set of overlays from the directory, ordered lexicographically
48 let content = builtins.readDir path; in
49 map (n: import (path + ("/" + n)))
52 (builtins.match ".*\\.nix" n != null &&
53 # ignore Emacs lock files (.#foo.nix)
54 builtins.match "\\.#.*" n == null) ||
55 builtins.pathExists (path + ("/" + n + "/default.nix")))
56 (builtins.attrNames content))
58 # it's a file, so the result is the contents of the file itself
61 if pathOverlays != "" && builtins.pathExists pathOverlays then overlays pathOverlays
62 else if builtins.pathExists homeOverlaysFile && builtins.pathExists homeOverlaysDir then
64 Nixpkgs overlays can be specified with ${homeOverlaysFile} or ${homeOverlaysDir}, but not both.
65 Please remove one of them and try again.
67 else if builtins.pathExists homeOverlaysFile then
68 if isDir homeOverlaysFile then
69 throw (homeOverlaysFile + " should be a file")
70 else overlays homeOverlaysFile
71 else if builtins.pathExists homeOverlaysDir then
72 if !(isDir homeOverlaysDir) then
73 throw (homeOverlaysDir + " should be a directory")
74 else overlays homeOverlaysDir
82 # If `localSystem` was explicitly passed, legacy `system` should
83 # not be passed, and vice-versa.
84 assert args ? localSystem -> !(args ? system);
85 assert args ? system -> !(args ? localSystem);
87 import ./. (builtins.removeAttrs args [ "system" ] // {
88 inherit config overlays localSystem;