at 23.05-pre 3.9 kB view raw
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 11evalConfigArgs@ 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. 18 pkgs ? null 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 24 extraArgs ? {} 25, # !!! See comment about args in lib/modules.nix 26 specialArgs ? {} 27, modules 28, modulesLocation ? (builtins.unsafeGetAttrPos "modules" evalConfigArgs).file or null 29, # !!! See comment about check in lib/modules.nix 30 check ? true 31, prefix ? [] 32, lib ? import ../../lib 33, extraModules ? let e = builtins.getEnv "NIXOS_EXTRA_MODULE_PATH"; 34 in if e == "" then [] else [(import e)] 35}: 36 37let pkgs_ = pkgs; 38in 39 40let 41 evalModulesMinimal = (import ./default.nix { 42 inherit lib; 43 # Implicit use of feature is noted in implementation. 44 featureFlags.minimalModules = { }; 45 }).evalModules; 46 47 pkgsModule = rec { 48 _file = ./eval-config.nix; 49 key = _file; 50 config = { 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); 56 57 _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_); 58 }; 59 }; 60 61 withWarnings = x: 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." 64 x; 65 66 legacyModules = 67 lib.optional (evalConfigArgs?extraArgs) { 68 config = { 69 _module.args = extraArgs; 70 }; 71 } 72 ++ lib.optional (evalConfigArgs?check) { 73 config = { 74 _module.check = lib.mkDefault check; 75 }; 76 }; 77 78 allUserModules = 79 let 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. 82 locatedModules = 83 if modulesLocation == null then 84 modules 85 else 86 map (lib.setDefaultModuleLocation modulesLocation) modules; 87 in 88 locatedModules ++ legacyModules; 89 90 noUserModules = evalModulesMinimal ({ 91 inherit prefix specialArgs; 92 modules = baseModules ++ extraModules ++ [ pkgsModule modulesModule ]; 93 }); 94 95 # Extra arguments that are useful for constructing a similar configuration. 96 modulesModule = { 97 config = { 98 _module.args = { 99 inherit noUserModules baseModules extraModules modules; 100 }; 101 }; 102 }; 103 104 nixosWithUserModules = noUserModules.extendModules { modules = allUserModules; }; 105 106in 107withWarnings nixosWithUserModules // { 108 inherit extraArgs; 109 inherit (nixosWithUserModules._module.args) pkgs; 110}