Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,31 @@ rec {
check ? true
}:
let
withWarnings = x:
lib.warnIf (evalModulesArgs?args) "The args argument to evalModules is deprecated. Please set config._module.args instead."
lib.warnIf (evalModulesArgs?check) "The check argument to evalModules is deprecated. Please set config._module.check instead."
x;

legacyModules =
optional (evalModulesArgs?args) {
config = {
_module.args = args;
};
}
++ optional (evalModulesArgs?check) {
config = {
_module.check = mkDefault check;
};
};
regularModules = modules ++ legacyModules;

# This internal module declare internal options under the `_module'
# attribute. These options are fragile, as they are used by the
# module system to change the interpretation of modules.
#
# When extended with extendModules or moduleType, a fresh instance of
# this module is used, to avoid conflicts and allow chaining of
# extendModules.
internalModule = rec {
_file = ./modules.nix;

Expand All @@ -125,7 +147,7 @@ rec {
_module.check = mkOption {
type = types.bool;
internal = true;
default = check;
default = true;
description = "Whether to check whether all option definitions have matching declarations.";
};

Expand All @@ -151,14 +173,14 @@ rec {
_module.args = {
inherit extendModules;
moduleType = type;
} // args;
};
};
};

merged =
let collected = collectModules
(specialArgs.modulesPath or "")
(modules ++ [ internalModule ])
(regularModules ++ [ internalModule ])
({ inherit lib options config specialArgs; } // specialArgs);
in mergeModules prefix (reverseList collected);

Expand Down Expand Up @@ -222,7 +244,7 @@ rec {
prefix ? [],
}:
evalModules (evalModulesArgs // {
modules = evalModulesArgs.modules ++ modules;
modules = regularModules ++ modules;
specialArgs = evalModulesArgs.specialArgs or {} // specialArgs;
prefix = extendArgs.prefix or evalModulesArgs.prefix;
});
Expand All @@ -231,7 +253,7 @@ rec {
inherit modules specialArgs;
};

result = {
result = withWarnings {
options = checked options;
config = checked (removeAttrs config [ "_module" ]);
_module = checked (config._module);
Expand Down
50 changes: 36 additions & 14 deletions nixos/lib/eval-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# as subcomponents (e.g. the container feature, or nixops if network
# expressions are ever made modular at the top level) can just use
# types.submodule instead of using eval-config.nix
evalConfigArgs@
{ # !!! system can be set modularly, would be nice to remove
system ? builtins.currentSystem
, # !!! is this argument needed any more? The pkgs argument can
Expand All @@ -28,7 +29,7 @@
in if e == "" then [] else [(import e)]
}:

let extraArgs_ = extraArgs; pkgs_ = pkgs;
let pkgs_ = pkgs;
in

let
Expand All @@ -51,28 +52,49 @@ let
};
};

noUserModules = lib.evalModules {
inherit prefix check;
modules = baseModules ++ extraModules ++ [ pkgsModule ];
args = extraArgs;
withWarnings = x:
lib.warnIf (evalConfigArgs?args) "The extraArgs argument to eval-config.nix is deprecated. Please set config._module.args instead."
lib.warnIf (evalConfigArgs?check) "The check argument to eval-config.nix is deprecated. Please set config._module.check instead."
x;

legacyModules =
lib.optional (evalConfigArgs?args) {
config = {
_module.args = extraArgs;
};
}
++ lib.optional (evalConfigArgs?check) {
config = {
_module.check = lib.mkDefault check;
};
};
allUserModules = modules ++ legacyModules;

noUserModules = lib.evalModules ({
inherit prefix;
modules = baseModules ++ extraModules ++ [ pkgsModule modulesModule ];
specialArgs =
{ modulesPath = builtins.toString ../modules; } // specialArgs;
};
});

# These are the extra arguments passed to every module. In
# particular, Nixpkgs is passed through the "pkgs" argument.
extraArgs = extraArgs_ // {
inherit noUserModules baseModules extraModules modules;
# Extra arguments that are useful for constructing a similar configuration.
modulesModule = {
config = {
_module.args = {
inherit noUserModules baseModules extraModules modules;
};
};
};

in rec {
nixosWithUserModules = noUserModules.extendModules { modules = allUserModules; };

in withWarnings {

# Merge the option definitions in all modules, forming the full
# system configuration.
inherit (noUserModules.extendModules { inherit modules; })
config options _module type;
inherit (nixosWithUserModules) config options _module type;

inherit extraArgs;

inherit (_module.args) pkgs;
inherit (nixosWithUserModules._module.args) pkgs;
}
20 changes: 7 additions & 13 deletions nixos/modules/misc/documentation.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
{ config, lib, pkgs, baseModules, extraModules, modules, modulesPath, ... }:
{ config, lib, pkgs, extendModules, noUserModules, ... }:

with lib;

let

cfg = config.documentation;

manualModules =
baseModules
# Modules for which to show options even when not imported
++ [ ../virtualisation/qemu-vm.nix ]
++ optionals cfg.nixos.includeAllModules (extraModules ++ modules);
/* Modules for which to show options even when not imported. */
extraDocModules = [ ../virtualisation/qemu-vm.nix ];

/* For the purpose of generating docs, evaluate options with each derivation
in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}".
Expand All @@ -24,13 +21,10 @@ let
extraSources = cfg.nixos.extraModuleSources;
options =
let
scrubbedEval = evalModules {
modules = [ { nixpkgs.localSystem = config.nixpkgs.localSystem; } ] ++ manualModules;
args = (config._module.args) // { modules = [ ]; };
specialArgs = {
pkgs = scrubDerivations "pkgs" pkgs;
inherit modulesPath;
};
extendNixOS = if cfg.nixos.includeAllModules then extendModules else noUserModules.extendModules;
scrubbedEval = extendNixOS {
modules = extraDocModules;
specialArgs.pkgs = scrubDerivations "pkgs" pkgs;
};
scrubDerivations = namePrefix: pkgSet: mapAttrs
(name: value:
Expand Down