Document and rename internal option of modules.

This commit is contained in:
Nicolas B. Pierron 2015-03-12 23:19:23 +01:00
parent ed91474e9b
commit 05e8a48fb4
7 changed files with 23 additions and 24 deletions

View file

@ -17,51 +17,51 @@ rec {
evalModules) and the less declarative the module set is. */ evalModules) and the less declarative the module set is. */
evalModules = { modules evalModules = { modules
, prefix ? [] , prefix ? []
, # !!! This can be specified modularly now, can we remove it? , # This would be remove in the future, Prefer _module.args option instead.
args ? {} args ? {}
, # !!! This can be specified modularly now, can we remove it? , # This would be remove in the future, Prefer _module.check option instead.
check ? true check ? true
}: }:
let let
# 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.
internalModule = rec { internalModule = rec {
_file = ./modules.nix; _file = ./modules.nix;
key = _file; key = _file;
options = { options = {
__internal.args = mkOption { _module.args = mkOption {
description = "Arguments passed to each module.";
# !!! Should this be types.uniq types.unspecified?
type = types.attrsOf types.unspecified; type = types.attrsOf types.unspecified;
internal = true; internal = true;
description = "Arguments passed to each module.";
}; };
__internal.check = mkOption { _module.check = mkOption {
description = "Whether to check whether all option definitions have matching declarations.";
type = types.uniq types.bool; type = types.uniq types.bool;
internal = true; internal = true;
default = check; default = check;
description = "Whether to check whether all option definitions have matching declarations.";
}; };
}; };
config = { config = {
__internal.args = args; _module.args = args;
}; };
}; };
closed = closeModules (modules ++ [ internalModule ]) { inherit config options; lib = import ./.; }; closed = closeModules (modules ++ [ internalModule ]) { inherit config options; lib = import ./.; };
# Note: the list of modules is reversed to maintain backward # Note: the list of modules is reversed to maintain backward
# compatibility with the old module system. Not sure if this is # compatibility with the old module system. Not sure if this is
# the most sensible policy. # the most sensible policy.
options = mergeModules prefix (reverseList closed); options = mergeModules prefix (reverseList closed);
# Traverse options and extract the option values into the final # Traverse options and extract the option values into the final
# config set. At the same time, check whether all option # config set. At the same time, check whether all option
# definitions have matching declarations. # definitions have matching declarations.
# !!! __internal.check's value can't depend on any other config values # !!! _module.check's value can't depend on any other config values
# without an infinite recursion. One way around this is to make the # without an infinite recursion. One way around this is to make the
# 'config' passed around to the modules be unconditionally unchecked, # 'config' passed around to the modules be unconditionally unchecked,
# and only do the check in 'result'. # and only do the check in 'result'.
@ -71,7 +71,7 @@ rec {
if isOption v then v.value if isOption v then v.value
else yieldConfig (prefix ++ [n]) v) set) ["_definedNames"]; else yieldConfig (prefix ++ [n]) v) set) ["_definedNames"];
in in
if options.__internal.check.value && set ? _definedNames then if options._module.check.value && set ? _definedNames then
fold (m: res: fold (m: res:
fold (name: res: fold (name: res:
if set ? ${name} then res else throw "The option `${showOption (prefix ++ [name])}' defined in `${m.file}' does not exist.") if set ? ${name} then res else throw "The option `${showOption (prefix ++ [name])}' defined in `${m.file}' does not exist.")
@ -122,7 +122,7 @@ rec {
let let
# Module arguments are resolved in a strict manner when attribute set # Module arguments are resolved in a strict manner when attribute set
# deconstruction is used. As the arguments are now defined with the # deconstruction is used. As the arguments are now defined with the
# config.__interanl.args option, the strictness used on the attribute # config._module.args option, the strictness used on the attribute
# set argument would cause an infinite loop, if the result of the # set argument would cause an infinite loop, if the result of the
# option is given as argument. # option is given as argument.
# #
@ -135,7 +135,7 @@ rec {
requiredArgs = builtins.attrNames (builtins.functionArgs f); requiredArgs = builtins.attrNames (builtins.functionArgs f);
extraArgs = builtins.listToAttrs (map (name: { extraArgs = builtins.listToAttrs (map (name: {
inherit name; inherit name;
value = config.__internal.args.${name}; value = config._module.args.${name};
}) requiredArgs); }) requiredArgs);
in f (extraArgs // arg) in f (extraArgs // arg)
else else

View file

@ -200,7 +200,6 @@ rec {
modules = opts' ++ map (def: { _file = def.file; imports = [(coerce def.value)]; }) defs; modules = opts' ++ map (def: { _file = def.file; imports = [(coerce def.value)]; }) defs;
in (evalModules { in (evalModules {
inherit modules; inherit modules;
# !!! See comment about args in lib/modules.nix
args.name = last loc; args.name = last loc;
prefix = loc; prefix = loc;
}).config; }).config;

View file

@ -35,7 +35,7 @@ let
key = _file; key = _file;
config = { config = {
nixpkgs.system = lib.mkDefault system_; nixpkgs.system = lib.mkDefault system_;
__internal.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_); _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_);
}; };
}; };
@ -60,5 +60,5 @@ in rec {
inherit modules baseModules; inherit modules baseModules;
}; };
inherit (config.__internal.args) pkgs; inherit (config._module.args) pkgs;
} }

View file

@ -1,7 +1,7 @@
{ lib, pkgs, config, ... }: { lib, pkgs, config, ... }:
{ {
__internal.args = { _module.args = {
modulesPath = ../.; modulesPath = ../.;
pkgs_i686 = import ../../lib/nixpkgs.nix { pkgs_i686 = import ../../lib/nixpkgs.nix {

View file

@ -72,7 +72,7 @@ in
}; };
config = { config = {
__internal.args.pkgs = import ../../lib/nixpkgs.nix { _module.args.pkgs = import ../../lib/nixpkgs.nix {
system = config.nixpkgs.system; system = config.nixpkgs.system;
inherit (config.nixpkgs) config; inherit (config.nixpkgs) config;

View file

@ -136,7 +136,7 @@ in zipModules ([]
++ obsolete [ "services" "mysql55" ] [ "services" "mysql" ] ++ obsolete [ "services" "mysql55" ] [ "services" "mysql" ]
++ obsolete [ "environment" "checkConfigurationOptions" ] [ "__internal" "check" ] ++ obsolete [ "environment" "checkConfigurationOptions" ] [ "_module" "check" ]
# Options that are obsolete and have no replacement. # Options that are obsolete and have no replacement.
++ obsolete' [ "boot" "loader" "grub" "bootDevice" ] ++ obsolete' [ "boot" "loader" "grub" "bootDevice" ]

View file

@ -18,7 +18,7 @@ let
eval = evalModules { eval = evalModules {
modules = [ versionModule ] ++ baseModules; modules = [ versionModule ] ++ baseModules;
args = (config.__internal.args) // { modules = [ ]; }; args = (config._module.args) // { modules = [ ]; };
}; };
manual = import ../../../doc/manual { manual = import ../../../doc/manual {