query
On this page

toExtension

lib.toExtension

Docs pulled from | This Revision | 14 minutes ago


Convert to an extending function (overlay).

toExtension is the toFunction for extending functions (a.k.a. extensions or overlays). It converts a non-function or a single-argument function to an extending function, while returning a two-argument function as-is.

That is, it takes a value of the shape x, prev: x, or final: prev: x, and returns final: prev: x, assuming x is not a function.

This function takes care of the input to stdenv.mkDerivation's overrideAttrs function. It bridges the gap between <pkg>.overrideAttrs before and after the overlay-style support.

Inputs

f
The function or value to convert to an extending function.

Type

toExtension ::
  b' -> Any -> Any -> b'
or
toExtension ::
  (a -> b') -> Any -> a -> b'
or
toExtension ::
  (a -> a -> b) -> a -> a -> b
where b' = ! Callable

Set a = b = b' = AttrSet & ! Callable to make toExtension return an extending function.

Examples

lib.fixedPoints.toExtension usage example

fix (final: { a = 0; c = final.a; })
=> { a = 0; c = 0; };

fix (extends (toExtension { a = 1; b = 2; }) (final: { a = 0; c = final.a; }))
=> { a = 1; b = 2; c = 1; };

fix (extends (toExtension (prev: { a = 1; b = prev.a; })) (final: { a = 0; c = final.a; }))
=> { a = 1; b = 0; c = 1; };

fix (extends (toExtension (final: prev: { a = 1; b = prev.a; c = final.a + 1 })) (final: { a = 0; c = final.a; }))
=> { a = 1; b = 0; c = 2; };
(lib.fixedPoints.toExtension)

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

toExtension =
    f:
    if lib.isFunction f then
      final: prev:
      let
        fPrev = f prev;
      in
      if lib.isFunction fPrev then
        # f is (final: prev: { ... })
        f final prev
      else
        # f is (prev: { ... })
        fPrev
    else
      # f is not a function; probably { ... }
      final: prev: f;