1 /* Impure default args for `pkgs/top-level/default.nix`. See that file
2 for the meaning of each argument. */
8 homeDir = builtins.getEnv "HOME";
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;
15 { # We put legacy `system` into `localSystem`, if `localSystem` was not passed.
16 # If neither is passed, assume we are building packages on the current
17 # (build, in GNU Autotools parlance) platform.
18 localSystem ? { system = args.system or builtins.currentSystem; }
20 # These are needed only because nix's `--arg` command-line logic doesn't work
21 # with unnamed parameters allowed by ...
22 , system ? localSystem.system
23 , crossSystem ? localSystem
25 , # Fallback: The contents of the configuration file found at $NIXPKGS_CONFIG or
26 # $HOME/.config/nixpkgs/config.nix.
28 configFile = getEnv "NIXPKGS_CONFIG";
29 configFile2 = homeDir + "/.config/nixpkgs/config.nix";
30 configFile3 = homeDir + "/.nixpkgs/config.nix"; # obsolete
32 if configFile != "" && pathExists configFile then import configFile
33 else if homeDir != "" && pathExists configFile2 then import configFile2
34 else if homeDir != "" && pathExists configFile3 then import configFile3
37 , # Overlays are used to extend Nixpkgs collection with additional
38 # collections of packages. These collection of packages are part of the
39 # fix-point made by Nixpkgs.
41 isDir = path: pathExists (path + "/.");
42 pathOverlays = try (toString <nixpkgs-overlays>) "";
43 homeOverlaysFile = homeDir + "/.config/nixpkgs/overlays.nix";
44 homeOverlaysDir = homeDir + "/.config/nixpkgs/overlays";
46 # check if the path is a directory or a file
48 # it's a directory, so the set of overlays from the directory, ordered lexicographically
49 let content = readDir path; in
50 map (n: import (path + ("/" + n)))
51 (builtins.filter (n: builtins.match ".*\\.nix" n != null || pathExists (path + ("/" + n + "/default.nix")))
54 # it's a file, so the result is the contents of the file itself
57 if pathOverlays != "" && pathExists pathOverlays then overlays pathOverlays
58 else if pathExists homeOverlaysFile && pathExists homeOverlaysDir then
60 Nixpkgs overlays can be specified with ${homeOverlaysFile} or ${homeOverlaysDir}, but not both.
61 Please remove one of them and try again.
63 else if pathExists homeOverlaysFile then
64 if isDir homeOverlaysFile then
65 throw (homeOverlaysFile + " should be a file")
66 else overlays homeOverlaysFile
67 else if pathExists homeOverlaysDir then
68 if !(isDir homeOverlaysDir) then
69 throw (homeOverlaysDir + " should be a directory")
70 else overlays homeOverlaysDir
78 # If `localSystem` was explicitly passed, legacy `system` should
79 # not be passed, and vice-versa.
80 assert args ? localSystem -> !(args ? system);
81 assert args ? system -> !(args ? localSystem);
83 import ./. (builtins.removeAttrs args [ "system" ] // {
84 inherit config overlays localSystem;