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 lib.optional (e != "") (import e)
38 inherit (lib) optional;
40 evalModulesMinimal = (import ./default.nix {
42 # Implicit use of feature is noted in implementation.
43 featureFlags.minimalModules = { };
47 _file = ./eval-config.nix;
49 config = lib.mkMerge (
50 (optional (system != null) {
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.mkDefault system;
58 (optional (pkgs != null) {
59 # This should be default priority, so it conflicts with any user-defined pkgs.
66 lib.warnIf (evalConfigArgs?extraArgs) "The extraArgs argument to eval-config.nix is deprecated. Please set config._module.args instead."
67 lib.warnIf (evalConfigArgs?check) "The check argument to eval-config.nix is deprecated. Please set config._module.check instead."
71 lib.optional (evalConfigArgs?extraArgs) {
73 _module.args = extraArgs;
76 ++ lib.optional (evalConfigArgs?check) {
78 _module.check = lib.mkDefault check;
84 # Add the invoking file (or specified modulesLocation) as error message location
85 # for modules that don't have their own locations; presumably inline modules.
87 if modulesLocation == null then
90 map (lib.setDefaultModuleLocation modulesLocation) modules;
92 locatedModules ++ legacyModules;
94 noUserModules = evalModulesMinimal ({
95 inherit prefix specialArgs;
96 modules = baseModules ++ extraModules ++ [ pkgsModule modulesModule ];
99 # Extra arguments that are useful for constructing a similar configuration.
103 inherit noUserModules baseModules extraModules modules;
108 nixosWithUserModules = noUserModules.extendModules { modules = allUserModules; };
110 withExtraAttrs = configuration: configuration // {
112 inherit (configuration._module.args) pkgs;
113 extendModules = args: withExtraAttrs (configuration.extendModules args);
116 withWarnings (withExtraAttrs nixosWithUserModules)