lib/modules: Recursive disabledModules
With this change, disabledModules applies recursively, meaning if you have a module "foo.nix" with imports = [ ./bar.nix ]; then setting disabledModules = [ "foo.nix" ]; will disable both "foo.nix" and "bar.nix", whereas previously only "foo.nix" would be disabled. This change along with https://github.com/NixOS/nixpkgs/pull/61570 allows modules to be fully disabled even when they have some `mkRenamedOption` imports.
This commit is contained in:
parent
845e92835d
commit
de5f73d434
@ -101,7 +101,7 @@ let
|
|||||||
cleanSource sourceByRegex sourceFilesBySuffices
|
cleanSource sourceByRegex sourceFilesBySuffices
|
||||||
commitIdFromGitRepo cleanSourceWith pathHasContext
|
commitIdFromGitRepo cleanSourceWith pathHasContext
|
||||||
canCleanSource;
|
canCleanSource;
|
||||||
inherit (modules) evalModules closeModules unifyModuleSyntax
|
inherit (modules) evalModules unifyModuleSyntax
|
||||||
applyIfFunction mergeModules
|
applyIfFunction mergeModules
|
||||||
mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions
|
mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions
|
||||||
pushDownProperties dischargeProperties filterOverrides
|
pushDownProperties dischargeProperties filterOverrides
|
||||||
@ -110,7 +110,7 @@ let
|
|||||||
mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions
|
mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions
|
||||||
mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule
|
mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule
|
||||||
mkRenamedOptionModule mkMergedOptionModule mkChangedOptionModule
|
mkRenamedOptionModule mkMergedOptionModule mkChangedOptionModule
|
||||||
mkAliasOptionModule doRename filterModules;
|
mkAliasOptionModule doRename;
|
||||||
inherit (options) isOption mkEnableOption mkSinkUndeclaredOptions
|
inherit (options) isOption mkEnableOption mkSinkUndeclaredOptions
|
||||||
mergeDefaultOption mergeOneOption mergeEqualOption getValues
|
mergeDefaultOption mergeOneOption mergeEqualOption getValues
|
||||||
getFiles optionAttrSetToDocList optionAttrSetToDocList'
|
getFiles optionAttrSetToDocList optionAttrSetToDocList'
|
||||||
|
@ -59,9 +59,12 @@ rec {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
closed = closeModules (modules ++ [ internalModule ]) ({ inherit config options lib; } // specialArgs);
|
collected = collectModules
|
||||||
|
(specialArgs.modulesPath or "")
|
||||||
|
(modules ++ [ internalModule ])
|
||||||
|
({ inherit config options lib; } // specialArgs);
|
||||||
|
|
||||||
options = mergeModules prefix (reverseList (filterModules (specialArgs.modulesPath or "") closed));
|
options = mergeModules prefix (reverseList collected);
|
||||||
|
|
||||||
# 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
|
||||||
@ -87,31 +90,76 @@ rec {
|
|||||||
result = { inherit options config; };
|
result = { inherit options config; };
|
||||||
in result;
|
in result;
|
||||||
|
|
||||||
|
# collectModules :: (modulesPath: String) -> (modules: [ Module ]) -> (args: Attrs) -> [ Module ]
|
||||||
|
#
|
||||||
|
# Collects all modules recursively through `import` statements, filtering out
|
||||||
|
# all modules in disabledModules.
|
||||||
|
collectModules = let
|
||||||
|
|
||||||
# Filter disabled modules. Modules can be disabled allowing
|
# Like unifyModuleSyntax, but also imports paths and calls functions if necessary
|
||||||
# their implementation to be replaced.
|
loadModule = args: fallbackFile: fallbackKey: m:
|
||||||
filterModules = modulesPath: modules:
|
if isFunction m || isAttrs m then
|
||||||
|
unifyModuleSyntax fallbackFile fallbackKey (applyIfFunction fallbackKey m args)
|
||||||
|
else unifyModuleSyntax (toString m) (toString m) (applyIfFunction (toString m) (import m) args);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Collects all modules recursively into the form
|
||||||
|
|
||||||
|
{
|
||||||
|
disabled = [ <list of disabled modules> ];
|
||||||
|
# All modules of the main module list
|
||||||
|
modules = [
|
||||||
|
{
|
||||||
|
key = <key1>;
|
||||||
|
module = <module for key1>;
|
||||||
|
# All modules imported by the module for key1
|
||||||
|
modules = [
|
||||||
|
{
|
||||||
|
key = <key1-1>;
|
||||||
|
module = <module for key1-1>;
|
||||||
|
# All modules imported by the module for key1-1
|
||||||
|
modules = [ ... ];
|
||||||
|
}
|
||||||
|
...
|
||||||
|
];
|
||||||
|
}
|
||||||
|
...
|
||||||
|
];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
collectStructuredModules =
|
||||||
|
let
|
||||||
|
collectResults = modules: {
|
||||||
|
disabled = concatLists (catAttrs "disabled" modules);
|
||||||
|
inherit modules;
|
||||||
|
};
|
||||||
|
in parentFile: parentKey: initialModules: args: collectResults (imap1 (n: x:
|
||||||
|
let
|
||||||
|
module = loadModule args parentFile "${parentKey}:anon-${toString n}" x;
|
||||||
|
collectedImports = collectStructuredModules module._file module.key module.imports args;
|
||||||
|
in {
|
||||||
|
key = module.key;
|
||||||
|
module = module;
|
||||||
|
modules = collectedImports.modules;
|
||||||
|
disabled = module.disabledModules ++ collectedImports.disabled;
|
||||||
|
}) initialModules);
|
||||||
|
|
||||||
|
# filterModules :: String -> { disabled, modules } -> [ Module ]
|
||||||
|
#
|
||||||
|
# Filters a structure as emitted by collectStructuredModules by removing all disabled
|
||||||
|
# modules recursively. It returns the final list of unique-by-key modules
|
||||||
|
filterModules = modulesPath: { disabled, modules }:
|
||||||
let
|
let
|
||||||
moduleKey = m: if isString m then toString modulesPath + "/" + m else toString m;
|
moduleKey = m: if isString m then toString modulesPath + "/" + m else toString m;
|
||||||
disabledKeys = map moduleKey (concatMap (m: m.disabledModules) modules);
|
disabledKeys = listToAttrs (map (k: nameValuePair (moduleKey k) null) disabled);
|
||||||
in
|
keyFilter = filter (attrs: ! disabledKeys ? ${attrs.key});
|
||||||
filter (m: !(elem m.key disabledKeys)) modules;
|
in map (attrs: attrs.module) (builtins.genericClosure {
|
||||||
|
startSet = keyFilter modules;
|
||||||
|
operator = attrs: keyFilter attrs.modules;
|
||||||
|
});
|
||||||
|
|
||||||
/* Close a set of modules under the ‘imports’ relation. */
|
in modulesPath: initialModules: args:
|
||||||
closeModules = modules: args:
|
filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args);
|
||||||
let
|
|
||||||
toClosureList = file: parentKey: imap1 (n: x:
|
|
||||||
if isAttrs x || isFunction x then
|
|
||||||
let key = "${parentKey}:anon-${toString n}"; in
|
|
||||||
unifyModuleSyntax file key (applyIfFunction key x args)
|
|
||||||
else
|
|
||||||
let file = toString x; key = toString x; in
|
|
||||||
unifyModuleSyntax file key (applyIfFunction key (import x) args));
|
|
||||||
in
|
|
||||||
builtins.genericClosure {
|
|
||||||
startSet = toClosureList unknownModule "" modules;
|
|
||||||
operator = m: toClosureList m._file m.key m.imports;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Massage a module into canonical form, that is, a set consisting
|
/* Massage a module into canonical form, that is, a set consisting
|
||||||
of ‘options’, ‘config’ and ‘imports’ attributes. */
|
of ‘options’, ‘config’ and ‘imports’ attributes. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user