Skip to content

The cycle form

Each key of an aspect gives one element. For 0 to n elements, or to ask the tree for data, write a component under cycle. As in Cycle.js, a component is a function from sources to sinks. Its sources are tree, scope and one source for each sink. It returns sinks by name, and tree requests.

modules/network.nix
# A component: it reads sources (the tree, the sinks) and writes sinks. It gives 0 to n elements.
{ yen, ... }:
{
yen.aspects.vm-network = {
at = yen.lib.has yen.kinds.guest; # every host with a guest
cycle =
{ tree, ... }:
{
tree = [
{
category = "vms";
children = yen.kinds.guest;
}
]; # a request: the guest children
bridges = map (g: "br-${g.name}") (builtins.head (tree.select "vms")); # one element per guest
errors = [ ];
};
};
}

The host has two guests, so the component gives two bridges:

result
{
server = [
"br-ci"
"br-db"
];
}

A request has a category and one question. tree.select category gives the answers.

RequestAnswer
nearest = yen.kinds.environmentthe nearest scope of that kind
parent = truethe parent scope
children = predicatethe children where the predicate holds
scopesOf = instanceevery scope of an instance
holds = predicatetrue or false at this scope
Contribute Community Sponsor