Skip to content

Parametric Aspects

import { Aside } from ‘@astrojs/starlight/components’;

A parametric aspect uses a __functor that forwards its received context to functions in .includes. Den provides several parametric functors in den.lib.parametric.

The most common functor. Alias for parametric.withOwn parametric.atLeast:

den.aspects.foo = den.lib.parametric {
nixos.networking.hostName = "owned"; # always included
includes = [
({ host, ... }: { nixos.time.timeZone = "UTC"; })
];
};

When applied with { host = ...; user = ...; }:

  1. Owned configs (nixos.networking.hostName) are included
  2. Static includes are included
  3. Functions matching atLeast the context args are called

Only dispatches to functions — does not include owned configs:

F = parametric.atLeast { includes = [ a b c ]; };

Applied with { x = 1; y = 2; }:

  • { x, ... }: ... → called (has at least x)
  • { x, y }: ... → called (has exactly x, y)
  • { z }: ... → skipped (needs z)

Like atLeast, but only calls functions with exactly matching args:

F = parametric.exactly { includes = [ a b c ]; };

Applied with { x = 1; y = 2; }:

  • { x, ... }: ... → skipped (has ...)
  • { x, y }: ... → called (exact match)
  • { z }: ... → skipped

Use exactly to prevent duplicate configs when the same function would match multiple context stages.

Replaces the context entirely:

foo = parametric.fixedTo { planet = "Earth"; } {
includes = [
({ planet, ... }: { nixos.setting = planet; })
];
};

No matter what context foo receives, its includes always get { planet = "Earth"; }.

Adds attributes to the received context:

foo = parametric.expands { planet = "Earth"; } {
includes = [
({ host, planet, ... }: {
nixos.setting = "${host.name}/${planet}";
})
];
};

Applied with { host = ...; }, the includes receive { host = ...; planet = "Earth"; }.

Combinator that adds owned config and static includes on top of any dispatch functor:

parametric.withOwn parametric.atLeast {
nixos.foo = "owned"; # included always
includes = [
{ nixos.bar = "static"; } # included always
({ host, ... }: { ... }) # dispatched via atLeast
];
}
FunctorOwnedStaticsFunctions
parametric (default)atLeast
parametric.atLeastatLeast
parametric.exactlyexactly
parametric.withOwn Fuses F
parametric.fixedTo ctxfixed ctx
parametric.expands ctxctx + received

For individual functions (not whole aspects), use den.lib.take:

den.default.includes = [
(den.lib.take.exactly ({ host }: { nixos.x = 1; }))
];

This prevents the function from matching { host, user } contexts, avoiding duplicate config values.