diff --git a/pkgs/lib/modules.nix b/pkgs/lib/modules.nix index 81a4c43b2a9..10667dc3ade 100644 --- a/pkgs/lib/modules.nix +++ b/pkgs/lib/modules.nix @@ -54,9 +54,10 @@ rec { removeAttrs (delayProperties m) ["require"]; in if isModule m then - m + { key = ""; } // m else { + key = ""; imports = getImportedPaths m; config = getConfig m; } // ( @@ -72,8 +73,7 @@ rec { moduleImport = m: (unifyModuleSyntax (applyIfFunction (importIfPath m) args)) // { # used by generic closure to avoid duplicated imports. - key = if isPath m then m else - /bad/developer/implies/bad/error/messages; + key = if isPath m then m else ""; }; getImports = m: attrByPath ["imports"] [] m; @@ -188,9 +188,25 @@ rec { moduleZip { options = lib.zip (name: values: if any isOption values then - addOptionMakeUp - { name = addName name; recurseInto = recurseForOption; } - (mergeOptionDecls values) + let + # locations to sub-options declarations + decls = + map (m: + mapSubOptions (subModule: + let module = lib.applyIfFunction subModule {}; in + if lib.isModule module then + { inherit (m) key; } // subModule + else + args: { + inherit (m) key; + options = lib.applyIfFunction subModule args; + } + ) m.options + ) (declarationsOf name); + in + addOptionMakeUp + { name = addName name; recurseInto = recurseForOption; } + (mergeOptionDecls decls) else if all isAttrs values then (recurseInto name modules).options else diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix index 37d092ef3c5..6aad285b7ac 100644 --- a/pkgs/lib/options.nix +++ b/pkgs/lib/options.nix @@ -27,6 +27,14 @@ rec { # options (set of sub-options declarations & definitions) }; + mapSubOptions = f: opt: + if opt ? options then + opt // { + options = map f (toList opt.options); + } + else + opt; + # Make the option declaration more user-friendly by adding default # settings and some verifications based on the declaration content (like # type correctness). @@ -68,20 +76,6 @@ rec { } else opt; - convertOptionsToModules = opt: - if opt ? options then - opt // { - options = map (decl: - let module = lib.applyIfFunction decl {}; in - if lib.isModule module then - decl - else - arg: { options = lib.applyIfFunction decl arg; } - ) opt.options; - } - else - opt; - handleOptionSets = opt: if decl ? type && decl.type.hasOptions then let @@ -119,7 +113,6 @@ rec { # override settings ensureMergeInputType ensureDefaultType - convertOptionsToModules handleOptionSets ];