Repository navigation
pipe.transform for local config-dependent quirks #713
|
Hey, I'm trying to emit config-dependent thunks into a quirk, pipe.transform those, and then using them in my host configs. This works really well when the aspect that's emitting the config-dependent thunks is on a different host than the one using the quirk values (i.e. through pipe.collectAll), but not when the quirk is emitted and used on the same host. I can't find anything in the documentation regarding this, just seems like a weird edgecase. Here's a denTest showing this based on pipe-scope.test-pipe-collect-fleet: test-pipe-collect-and-transform-fleet = denTest (
{
den,
igloo,
lib,
...
}:
{
den.hosts.x86_64-linux.igloo.users.tux = { };
den.hosts.x86_64-linux.iceberg.users.alice = { };
den.quirks.http-backends = {
description = "HTTP backends";
};
# Fleet entity: groups all hosts under a fleet parent scope.
den.policies.to-fleet = _: [
(den.lib.policy.resolve.to "fleet" {
fleet = {
name = "fleet";
};
})
];
den.policies.fleet-to-hosts =
{ fleet, ... }:
lib.concatMap (
system:
lib.concatMap (
hostName:
let
host = den.hosts.${system}.${hostName};
in
[
(den.lib.policy.resolve.to "host" { inherit host; })
(den.lib.policy.instantiate host)
]
) (builtins.attrNames (den.hosts.${system} or { }))
) (builtins.attrNames (den.hosts or { }));
den.schema.flake.includes = [ den.policies.to-fleet ];
den.schema.fleet.includes = [ den.policies.fleet-to-hosts ];
# Collect policy: each host collects from fleet peers.
den.policies.fleet-backends =
{ host, ... }:
let
inherit (den.lib.policy) pipe;
in
[
(pipe.from "http-backends" [
(pipe.collectAll ({ host, ... }: true))
(pipe.transform (b: b // { url = "http://${b.addr}:${toString b.port}"; }))
])
];
den.schema.host.includes = [ den.policies.fleet-backends ];
# Config-dependent thunk emits (like a real config reading config.my.services.*).
# The `{ config, ... }` signature is what triggers the bug.
den.aspects.iceberg = {
http-backends =
{ config, ... }:
{
addr = "10.0.0.2";
port = 80;
};
};
den.aspects.igloo = {
includes = [ den.aspects.haproxy ];
http-backends =
{ config, ... }:
{
addr = "10.0.0.1";
port = 80;
};
};
den.aspects.haproxy = {
nixos =
{ http-backends, ... }:
{
networking.hostName = toString (
# this fails due to url not being defined
builtins.length (builtins.filter (b: builtins.isString b.url) http-backends)
);
};
};
expr = igloo.networking.hostName;
expected = "2";
}
);For now I'm just not using config-dependent thunks, but I'd still like to know if this is expected behavior or just a bug (and if this is mentioned in some documentation that I missed) Note on AIThis issue was reproduced as a denTest using AI (DeepSeek V4 Flash), but the discussion itself is written by a human. |
Fixed with #723