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}:
28
29let extraArgs_ = extraArgs; pkgs_ = pkgs;
30 extraModules = let e = builtins.getEnv "NIXOS_EXTRA_MODULE_PATH";
31 in if e == "" then [] else [(import (builtins.toPath e))];
32in
33
34let
35 pkgsModule = rec {
36 _file = ./eval-config.nix;
37 key = _file;
38 config = {
39 nixpkgs.localSystem = lib.mkDefault { inherit system; };
40 _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_);
41 };
42 };
43
44in rec {
45
46 # Merge the option definitions in all modules, forming the full
47 # system configuration.
48 inherit (lib.evalModules {
49 inherit prefix check;
50 modules = modules ++ extraModules ++ baseModules ++ [ pkgsModule ];
51 args = extraArgs;
52 specialArgs = { modulesPath = ../modules; } // specialArgs;
53 }) config options;
54
55 # These are the extra arguments passed to every module. In
56 # particular, Nixpkgs is passed through the "pkgs" argument.
57 extraArgs = extraArgs_ // {
58 inherit modules baseModules;
59 };
60
61 inherit (config._module.args) pkgs;
62}