mirror of
https://github.com/aviallon/nixos-lib.git
synced 2026-04-06 09:47:52 +00:00
[Lib/Attrsets]: add support for merging with priority overrides
This commit is contained in:
parent
2e6e4b53b2
commit
d7d489674f
1 changed files with 23 additions and 2 deletions
|
|
@ -1,7 +1,28 @@
|
|||
{lib, myLib, ...}:
|
||||
with lib;
|
||||
rec {
|
||||
mergeAttrsRecursive = a: b: foldAttrs (item: acc:
|
||||
getPriority = x:
|
||||
if isAttrs x && (attrByPath [ "_type" ] "" x) == "override" then
|
||||
getAttr "priority" x
|
||||
else
|
||||
lib.modules.defaultOverridePriority
|
||||
;
|
||||
comparePriority = a: b: (getPriority a) - (getPriority b);
|
||||
mergeAttrsRecursiveWithPriority = a: b:
|
||||
let
|
||||
_prio = comparePriority a b;
|
||||
in
|
||||
if _prio == 0 then
|
||||
_mergeAttrsRecursive mergeAttrsRecursiveWithPriority a b
|
||||
else if _prio > 0 then
|
||||
a
|
||||
else
|
||||
b
|
||||
;
|
||||
|
||||
mergeAttrsRecursive = a: b: _mergeAttrsRecursive _mergeAttrsRecursive a b;
|
||||
|
||||
_mergeAttrsRecursive = self: a: b: foldAttrs (item: acc:
|
||||
if (isNull acc) then
|
||||
item
|
||||
else if (isList item) then
|
||||
|
|
@ -11,7 +32,7 @@ rec {
|
|||
else if (isString item) then
|
||||
acc + item
|
||||
else if (isAttrs item) then
|
||||
mergeAttrsRecursive acc item
|
||||
self acc item
|
||||
else item
|
||||
) null [ b a ];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue