mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-26 02:56:36 +03:00
modules.nix: Generate the extra argument set from the configuration
This allows for module arguments to be handled modularly, in particular allowing the nixpkgs module to handle the nixpkgs import internally. This creates the __internal option namespace, which should only be added to by the module system itself.
This commit is contained in:
parent
4f5c6330c9
commit
1d62ad4746
3 changed files with 36 additions and 8 deletions
|
@ -12,8 +12,26 @@ rec {
|
||||||
and ‘config’: the nested set of all option values. */
|
and ‘config’: the nested set of all option values. */
|
||||||
evalModules = { modules, prefix ? [], args ? {}, check ? true }:
|
evalModules = { modules, prefix ? [], args ? {}, check ? true }:
|
||||||
let
|
let
|
||||||
args' = args // { lib = import ./.; } // result;
|
internalModule = {
|
||||||
closed = closeModules modules args';
|
_file = ./modules.nix;
|
||||||
|
|
||||||
|
key = ./modules.nix;
|
||||||
|
|
||||||
|
options = {
|
||||||
|
__internal.args = mkOption {
|
||||||
|
description = "Arguments passed to each module.";
|
||||||
|
|
||||||
|
type = types.attrsOf types.unspecified;
|
||||||
|
|
||||||
|
internal = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
__internal.args = args;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
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.
|
||||||
|
@ -74,7 +92,16 @@ rec {
|
||||||
config = removeAttrs m ["key" "_file" "require" "imports"];
|
config = removeAttrs m ["key" "_file" "require" "imports"];
|
||||||
};
|
};
|
||||||
|
|
||||||
applyIfFunction = f: arg: if isFunction f then f arg else f;
|
applyIfFunction = f: arg@{ config, options, lib }: if isFunction f then
|
||||||
|
let
|
||||||
|
requiredArgs = builtins.attrNames (builtins.functionArgs f);
|
||||||
|
extraArgs = builtins.listToAttrs (map (name: {
|
||||||
|
inherit name;
|
||||||
|
value = config.__internal.args.${name};
|
||||||
|
}) requiredArgs);
|
||||||
|
in f (extraArgs // arg)
|
||||||
|
else
|
||||||
|
f;
|
||||||
|
|
||||||
/* Merge a list of modules. This will recurse over the option
|
/* Merge a list of modules. This will recurse over the option
|
||||||
declarations in all modules, combining them into a single set.
|
declarations in all modules, combining them into a single set.
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
parentConfig = config;
|
||||||
|
|
||||||
pamOpts = args: {
|
pamOpts = { config, name, ... }: let cfg = config; in let config = parentConfig; in {
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
|
@ -180,8 +181,8 @@ let
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = let cfg = args.config; in {
|
config = {
|
||||||
name = mkDefault args.name;
|
name = mkDefault name;
|
||||||
setLoginUid = mkDefault cfg.startSession;
|
setLoginUid = mkDefault cfg.startSession;
|
||||||
limits = mkDefault config.security.pam.loginLimits;
|
limits = mkDefault config.security.pam.loginLimits;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# of the virtual consoles. The latter is useful for the installation
|
# of the virtual consoles. The latter is useful for the installation
|
||||||
# CD.
|
# CD.
|
||||||
|
|
||||||
{ config, lib, pkgs, baseModules, ... } @ extraArgs:
|
{ config, lib, pkgs, baseModules, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ let
|
||||||
|
|
||||||
eval = evalModules {
|
eval = evalModules {
|
||||||
modules = [ versionModule ] ++ baseModules;
|
modules = [ versionModule ] ++ baseModules;
|
||||||
args = (removeAttrs extraArgs ["config" "options"]) // { modules = [ ]; };
|
args = (config.__internal.args) // { modules = [ ]; };
|
||||||
};
|
};
|
||||||
|
|
||||||
manual = import ../../../doc/manual {
|
manual = import ../../../doc/manual {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue