1# From an end-user configuration file (`configuration.nix'), build a NixOS
2# configuration object (`config') from which we can retrieve option
3# values.
4
5# !!! Please think twice before adding to this argument list!
6# Ideally eval-config.nix would be an extremely thin wrapper
7# around lib.evalModules, so that modular systems that have nixos configs
8# as subcomponents (e.g. the container feature, or nixops if network
9# expressions are ever made modular at the top level) can just use
10# types.submodule instead of using eval-config.nix
11{ # !!! system can be set modularly, would be nice to remove
12 system ? builtins.currentSystem
13, # !!! is this argument needed any more? The pkgs argument can
14 # be set modularly anyway.
15 pkgs ? null
16, # !!! what do we gain by making this configurable?
17 baseModules ? import ../modules/module-list.nix
18, # !!! See comment about args in lib/modules.nix
19 extraArgs ? {}
20, # !!! See comment about args in lib/modules.nix
21 specialArgs ? {}
22, modules
23, # !!! See comment about check in lib/modules.nix
24 check ? true
25, prefix ? []
26, lib ? import ../../lib
27, extraModules ? let e = builtins.getEnv "NIXOS_EXTRA_MODULE_PATH";
28 in if e == "" then [] else [(import e)]
29}:
30
31let extraArgs_ = extraArgs; pkgs_ = pkgs;
32in
33
34let
35 pkgsModule = rec {
36 _file = ./eval-config.nix;
37 key = _file;
38 config = {
39 # Explicit `nixpkgs.system` or `nixpkgs.localSystem` should override
40 # this. Since the latter defaults to the former, the former should
41 # default to the argument. That way this new default could propagate all
42 # they way through, but has the last priority behind everything else.
43 nixpkgs.system = lib.mkDefault system;
44
45 # Stash the value of the `system` argument. When using `nesting.children`
46 # we want to have the same default value behavior (immediately above)
47 # without any interference from the user's configuration.
48 nixpkgs.initialSystem = system;
49
50 _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_);
51 };
52 };
53
54in rec {
55
56 # Merge the option definitions in all modules, forming the full
57 # system configuration.
58 inherit (lib.evalModules {
59 inherit prefix check;
60 modules = baseModules ++ extraModules ++ [ pkgsModule ] ++ modules;
61 args = extraArgs;
62 specialArgs =
63 { modulesPath = builtins.toString ../modules; } // specialArgs;
64 }) config options _module type;
65
66 # These are the extra arguments passed to every module. In
67 # particular, Nixpkgs is passed through the "pkgs" argument.
68 extraArgs = extraArgs_ // {
69 inherit baseModules extraModules modules;
70 };
71
72 inherit (_module.args) pkgs;
73}