composeManyExtensions
lib.composeManyExtensions
Docs pulled from | This Revision | 34 minutes ago
Composes a list of overlays
and returns a single overlay function that combines them.
The result is produced by using the update operator //
.
This means nested values of previous overlays are not merged recursively.
In other words, previously defined attributes are replaced, ignoring the previous value, unless referenced by the overlay; for example final: prev: { foo = final.foo + 1; }
.
Inputs
extensions
-
A list of overlay functions
The order of the overlays in the list is important.
-
Each overlay function takes two arguments, by convention
final
andprev
, and returns an attribute set.final
is the result of the fixed-point function, with all overlays applied.prev
is the result of the previous overlay function(s).
Type
# Pseudo code
let
# final prev
# ↓ ↓
OverlayFn = { ... } -> { ... } -> { ... };
in
composeManyExtensions :: ListOf OverlayFn -> OverlayFn
Examples
lib.fixedPoints.composeManyExtensions
usage example
let
# The "original function" that is extended by the overlays.
# Note that it doesn't have prev: as argument since no overlay function precedes it.
original = final: { a = 1; };
# Each overlay function has 'final' and 'prev' as arguments.
overlayA = final: prev: { b = final.c; c = 3; };
overlayB = final: prev: { c = 10; x = prev.c or 5; };
extensions = composeManyExtensions [ overlayA overlayB ];
# Caluculate the fixed point of all composed overlays.
fixedpoint = lib.fix (lib.extends extensions original );
in fixedpoint
=>
{
a = 1;
b = 10;
c = 10;
x = 3;
}