lib/modules.nix: Apply argument attr of old byName

This commit is contained in:
Robert Hensing 2023-07-11 11:43:16 +02:00
parent d1e18a369a
commit c70a5e9223

View File

@ -540,34 +540,26 @@ let
mergeModules' = prefix: options: configs: mergeModules' = prefix: options: configs:
let let
# an attrset 'name' => list of submodules that declare name. # an attrset 'name' => list of submodules that declare name.
declsByName = (attr: f: modules: declsByName = (f: modules:
zipAttrsWith (n: concatLists) zipAttrsWith (n: concatLists)
(map (module: let subtree = module.${attr}; in (map (module: let subtree = module.options; in
if !(builtins.isAttrs subtree) then if !(builtins.isAttrs subtree) then
throw (if attr == "config" then '' throw ''
You're trying to define a value of type `${builtins.typeOf subtree}'
rather than an attribute set for the option
`${builtins.concatStringsSep "." prefix}'!
This usually happens if `${builtins.concatStringsSep "." prefix}' has option
definitions inside that are not matched. Please check how to properly define
this option by e.g. referring to `man 5 configuration.nix'!
'' else ''
An option declaration for `${builtins.concatStringsSep "." prefix}' has type An option declaration for `${builtins.concatStringsSep "." prefix}' has type
`${builtins.typeOf subtree}' rather than an attribute set. `${builtins.typeOf subtree}' rather than an attribute set.
Did you mean to define this outside of `options'? Did you mean to define this outside of `options'?
'') ''
else else
mapAttrs (n: f module) subtree mapAttrs (n: f module) subtree
) modules)) "options" (module: option: ) modules)) (module: option:
[{ inherit (module) _file; options = option; }] [{ inherit (module) _file; options = option; }]
) options; ) options;
# an attrset 'name' => list of submodules that define name. # an attrset 'name' => list of submodules that define name.
defnsByName = (attr: f: modules: defnsByName = (f: modules:
zipAttrsWith (n: concatLists) zipAttrsWith (n: concatLists)
(map (module: let subtree = module.${attr}; in (map (module: let subtree = module.config; in
if !(builtins.isAttrs subtree) then if !(builtins.isAttrs subtree) then
throw (if attr == "config" then '' throw ''
You're trying to define a value of type `${builtins.typeOf subtree}' You're trying to define a value of type `${builtins.typeOf subtree}'
rather than an attribute set for the option rather than an attribute set for the option
`${builtins.concatStringsSep "." prefix}'! `${builtins.concatStringsSep "." prefix}'!
@ -575,22 +567,18 @@ let
This usually happens if `${builtins.concatStringsSep "." prefix}' has option This usually happens if `${builtins.concatStringsSep "." prefix}' has option
definitions inside that are not matched. Please check how to properly define definitions inside that are not matched. Please check how to properly define
this option by e.g. referring to `man 5 configuration.nix'! this option by e.g. referring to `man 5 configuration.nix'!
'' else '' ''
An option declaration for `${builtins.concatStringsSep "." prefix}' has type
`${builtins.typeOf subtree}' rather than an attribute set.
Did you mean to define this outside of `options'?
'')
else else
mapAttrs (n: f module) subtree mapAttrs (n: f module) subtree
) modules)) "config" (module: value: ) modules)) (module: value:
map (config: { inherit (module) file; inherit config; }) (pushDownProperties value) map (config: { inherit (module) file; inherit config; }) (pushDownProperties value)
) configs; ) configs;
# extract the definitions for each loc # extract the definitions for each loc
defnsByName' = (attr: f: modules: defnsByName' = (f: modules:
zipAttrsWith (n: concatLists) zipAttrsWith (n: concatLists)
(map (module: let subtree = module.${attr}; in (map (module: let subtree = module.config; in
if !(builtins.isAttrs subtree) then if !(builtins.isAttrs subtree) then
throw (if attr == "config" then '' throw ''
You're trying to define a value of type `${builtins.typeOf subtree}' You're trying to define a value of type `${builtins.typeOf subtree}'
rather than an attribute set for the option rather than an attribute set for the option
`${builtins.concatStringsSep "." prefix}'! `${builtins.concatStringsSep "." prefix}'!
@ -598,14 +586,10 @@ let
This usually happens if `${builtins.concatStringsSep "." prefix}' has option This usually happens if `${builtins.concatStringsSep "." prefix}' has option
definitions inside that are not matched. Please check how to properly define definitions inside that are not matched. Please check how to properly define
this option by e.g. referring to `man 5 configuration.nix'! this option by e.g. referring to `man 5 configuration.nix'!
'' else '' ''
An option declaration for `${builtins.concatStringsSep "." prefix}' has type
`${builtins.typeOf subtree}' rather than an attribute set.
Did you mean to define this outside of `options'?
'')
else else
mapAttrs (n: f module) subtree mapAttrs (n: f module) subtree
) modules)) "config" (module: value: ) modules)) (module: value:
[{ inherit (module) file; inherit value; }] [{ inherit (module) file; inherit value; }]
) configs; ) configs;