1 # From an end-user configuration file (`configuration.nix'), build a NixOS
2 # configuration object (`config') from which we can retrieve option
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
12 { # !!! system can be set modularly, would be nice to remove,
13 # however, removing or changing this default is too much
14 # of a breaking change. To set it modularly, pass `null`.
15 system ? builtins.currentSystem
16 , # !!! is this argument needed any more? The pkgs argument can
17 # be set modularly anyway.
19 , # !!! what do we gain by making this configurable?
20 # we can add modules that are included in specialisations, regardless
21 # of inheritParentConfig.
22 baseModules ? import ../modules/module-list.nix
23 , # !!! See comment about args in lib/modules.nix
25 , # !!! See comment about args in lib/modules.nix
28 , modulesLocation ? (builtins.unsafeGetAttrPos "modules" evalConfigArgs).file or null
29 , # !!! See comment about check in lib/modules.nix
32 , lib ? import ../../lib
33 , extraModules ? let e = builtins.getEnv "NIXOS_EXTRA_MODULE_PATH";
34 in if e == "" then [] else [(import e)]
41 evalModulesMinimal = (import ./default.nix {
43 # Implicit use of feature is noted in implementation.
44 featureFlags.minimalModules = { };
48 _file = ./eval-config.nix;
51 # Explicit `nixpkgs.system` or `nixpkgs.localSystem` should override
52 # this. Since the latter defaults to the former, the former should
53 # default to the argument. That way this new default could propagate all
54 # they way through, but has the last priority behind everything else.
55 nixpkgs.system = lib.mkIf (system != null) (lib.mkDefault system);
57 _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_);
62 lib.warnIf (evalConfigArgs?extraArgs) "The extraArgs argument to eval-config.nix is deprecated. Please set config._module.args instead."
63 lib.warnIf (evalConfigArgs?check) "The check argument to eval-config.nix is deprecated. Please set config._module.check instead."
67 lib.optional (evalConfigArgs?extraArgs) {
69 _module.args = extraArgs;
72 ++ lib.optional (evalConfigArgs?check) {
74 _module.check = lib.mkDefault check;
80 # Add the invoking file (or specified modulesLocation) as error message location
81 # for modules that don't have their own locations; presumably inline modules.
83 if modulesLocation == null then
86 map (lib.setDefaultModuleLocation modulesLocation) modules;
88 locatedModules ++ legacyModules;
90 noUserModules = evalModulesMinimal ({
91 inherit prefix specialArgs;
92 modules = baseModules ++ extraModules ++ [ pkgsModule modulesModule ];
95 # Extra arguments that are useful for constructing a similar configuration.
99 inherit noUserModules baseModules extraModules modules;
104 nixosWithUserModules = noUserModules.extendModules { modules = allUserModules; };
107 withWarnings nixosWithUserModules // {
109 inherit (nixosWithUserModules._module.args) pkgs;