Skip to content

Commit

Permalink
Revert "lib/modules: Make unifyModuleSyntax key required, use setDefa…
Browse files Browse the repository at this point in the history
…ultModuleLocation"

The performance did not improve, judging by the memory statistics.

Baseline: https://github.com/NixOS/nixpkgs/pull/177157/checks?check_run_id=6828895472

Without optionalAttrs: https://github.com/NixOS/nixpkgs/pull/177157/checks?check_run_id=6829274815

So the memory cost of the reverted commit was about 0.05%.

This reverts commit bb8461b4cb05bd468e34f2191cdea28dcd01e70a.
  • Loading branch information
roberth committed Jun 13, 2022
1 parent 1d47fca commit 5bb1e0c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -455,19 +455,21 @@ 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
Expand Down
19 changes: 10 additions & 9 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -579,15 +579,16 @@ rec {
then value: value
else value: { config = value; };

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;
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;

base = evalModules {
inherit specialArgs;
Expand Down

0 comments on commit 5bb1e0c

Please sign in to comment.