Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/modules: Make unifyModuleSyntax key optional, remove extensionOffset #177157

Closed
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
lib/modules: Make unifyModuleSyntax key required, use setDefaultModul…
…eLocation

This should be equivalent and perhaps perform better.
roberth committed Jun 13, 2022
commit 1d47fcaee584268f38249e500903bb85aedfc025
6 changes: 2 additions & 4 deletions lib/modules.nix
Original file line number Diff line number Diff line change
@@ -455,21 +455,19 @@ rec {
throw "Module `${key}' has an unsupported attribute `${head (attrNames badAttrs)}'. This is caused by introducing a top-level `config' or `options' attribute. Add configuration attributes immediately on the top level instead, or move all of them (namely: ${toString (attrNames badAttrs)}) into the explicit `config' attribute."
else
{ _file = toString m._file or file;
key = toString m.key or key;
disabledModules = m.disabledModules or [];
imports = m.imports or [];
options = m.options or {};
config = addFreeformType (addMeta (m.config or {}));
} // optionalAttrs (m?key || key != null) {
key = toString m.key or key;
}
else
{ _file = toString m._file or file;
key = toString m.key or key;
disabledModules = m.disabledModules or [];
imports = m.require or [] ++ m.imports or [];
options = {};
config = addFreeformType (addMeta (removeAttrs m ["_file" "key" "disabledModules" "require" "imports" "freeformType"]));
} // optionalAttrs (m?key || key != null) {
key = toString m.key or key;
};

applyModuleArgsIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then
19 changes: 9 additions & 10 deletions lib/types.nix
Original file line number Diff line number Diff line change
@@ -579,16 +579,15 @@ rec {
then value: value
else value: { config = value; };

allModules = defs: map ({ value, file }:
if isFunction value
then setFunctionArgs
(args: lib.modules.unifyModuleSyntax file null (value args))
(functionArgs value)
else if isAttrs value
then
lib.modules.unifyModuleSyntax file null (shorthandToModule value)
else value
) defs;
allModules = defs:
map
({ value, file }:
if isAttrs value
then { _file = file; imports = [ (shorthandToModule value) ]; }
else if isFunction value
then { _file = file; imports = [ value ]; }
else value)
defs;

base = evalModules {
inherit specialArgs;