diff --git a/pkgs/lib/modules.nix b/pkgs/lib/modules.nix index 19b04bd827f4..4de12e1a07c5 100644 --- a/pkgs/lib/modules.nix +++ b/pkgs/lib/modules.nix @@ -230,10 +230,14 @@ rec { }" ); - config = lib.zipWithNames (modulesNames modules) (name: values: + config = lib.zipWithNames (modulesNames modules) (name: values_: let hasOpt = builtins.hasAttr name result.options; opt = lib.getAttr name result.options; + values = values_ ++ + optionals + (hasOpt && isOption opt && opt ? extraConfigs) + opt.extraConfigs; in if hasOpt && isOption opt then let defs = evalProperties values; in diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix index c1c6a64d6d58..6f1b1afe12aa 100644 --- a/pkgs/lib/options.nix +++ b/pkgs/lib/options.nix @@ -25,6 +25,7 @@ rec { # merge (function used to merge definitions into one definition: [ /type/ ] -> /type/) # apply (convert the option value to ease the manipulation of the option result) # options (set of sub-options declarations & definitions) + # extraConfigs (list of possible configurations) }; mapSubOptions = f: opt: @@ -138,14 +139,17 @@ rec { assert opt1 ? merge -> ! opt2 ? merge; assert opt1 ? apply -> ! opt2 ? apply; assert opt1 ? type -> ! opt2 ? type; - if opt1 ? options || opt2 ? options then - opt1 // opt2 // { + opt1 // opt2 + // optionalAttrs (opt1 ? options || opt2 ? options) { options = (toList (attrByPath ["options"] [] opt1)) ++ (toList (attrByPath ["options"] [] opt2)); } - else - opt1 // opt2 + // optionalAttrs (opt1 ? extraConfigs || opt2 ? extraConfigs) { + extraConfigs = + (attrByPath ["extraConfigs"] [] opt1) + ++ (attrByPath ["extraConfigs"] [] opt2); + } )) {} opts;