mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-12 04:35:41 +03:00
lib.modules: Add mergeAttrDefinitionsWithPrio
This will let us make assertions involving _module.args.pkgs, which is not an option but a value attribute, and therefore doesn't have its own highestPrio to inspect. The new function gives us that info.
This commit is contained in:
parent
a742767baf
commit
36ea2bbfe8
3 changed files with 65 additions and 0 deletions
|
@ -910,6 +910,47 @@ let
|
|||
else opt // { type = opt.type.substSubModules opt.options; options = []; };
|
||||
|
||||
|
||||
/*
|
||||
Merge an option's definitions in a way that preserves the priority of the
|
||||
individual attributes in the option value.
|
||||
|
||||
This does not account for all option semantics, such as readOnly.
|
||||
|
||||
Type:
|
||||
option -> attrsOf { highestPrio, value }
|
||||
*/
|
||||
mergeAttrDefinitionsWithPrio = opt:
|
||||
let subAttrDefs =
|
||||
lib.concatMap
|
||||
({ value, ... }@def:
|
||||
map
|
||||
(value: def // { inherit value; })
|
||||
(lib.pushDownProperties value)
|
||||
)
|
||||
opt.definitionsWithLocations;
|
||||
defsByAttr =
|
||||
lib.zipAttrs (
|
||||
lib.concatLists (
|
||||
lib.concatMap
|
||||
({ value, ... }@def:
|
||||
map
|
||||
(lib.mapAttrsToList (k: value: { ${k} = def // { inherit value; }; }))
|
||||
(lib.pushDownProperties value)
|
||||
)
|
||||
opt.definitionsWithLocations
|
||||
)
|
||||
);
|
||||
in
|
||||
assert opt.type.name == "attrsOf" || opt.type.name == "lazyAttrsOf";
|
||||
lib.mapAttrs
|
||||
(k: v:
|
||||
let merging = lib.mergeDefinitions (opt.loc ++ [k]) opt.type.nestedTypes.elemType v;
|
||||
in {
|
||||
value = merging.mergedValue;
|
||||
inherit (merging.defsFinal') highestPrio;
|
||||
})
|
||||
defsByAttr;
|
||||
|
||||
/* Properties. */
|
||||
|
||||
mkIf = condition: content:
|
||||
|
@ -1256,6 +1297,7 @@ private //
|
|||
importJSON
|
||||
importTOML
|
||||
mergeDefinitions
|
||||
mergeAttrDefinitionsWithPrio
|
||||
mergeOptionDecls # should be private?
|
||||
mkAfter
|
||||
mkAliasAndWrapDefinitions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue