Skip to content

Flake outputs

yen does not know what a flake is. The root kind declares an out sink with merge, and yen.flake gives the flake’s outputs. Each sink with an out key gives its part.

modules/fleet.nix
# The `out` sink of the root is the flake: `yen.flake` gives it.
{ yen, ... }:
{
yen.kinds.fleet = {
spawns.host = _: yen.host;
sinks.out.reduce = yen.lib.reduce.merge;
};
yen.kinds.host.sinks.services.out =
{ host, services, ... }:
{
services.${host.name} = services;
};
yen.fleet.main = { };
yen.host.web = { };
yen.host.db = { };
yen.flake = { out, ... }: out;
}

The out arg is the flake itself, read lazily. An element can build on other outputs without inputs.self:

modules/aspects.nix
{ yen, lib, ... }:
{
yen.aspects.nginx = {
at = yen.host.web;
services = "nginx";
};
yen.aspects.postgres = {
at = yen.host.db;
services = "postgres";
};
# the `out` arg: an element reads the flake outputs, lazily. No `inputs.self`.
yen.aspects.inventory = {
at = yen.kinds.fleet;
out =
{ out, ... }:
{
inventory = lib.concatLists (lib.attrValues out.services);
};
};
}
result
{
inventory = [
"postgres"
"nginx"
];
services = {
db = [
"postgres"
];
web = [
"nginx"
];
};
}

(import yen).lib.mkFlake module gives the flake outputs. (import yen).lib.eval module gives every query, and flake is one of them. mkFlake m is (eval m).flake.

Contribute Community Sponsor