Infinite recursion with `den.lib.policy.when` and `<entity>.hasAspect`
I was attempting to configure a user depending whether the host contains an aspect. I attempt to do this with the <entity>.hasAspect function, but end up with infinite recursion. There is a reproduction repo at https://github.com/jadestar1864/den-sibling-bug. Don't mind the weird settings, they were supposed to be meant as markers. Here is a snippet of the reproduction test:
test-something = denTest (
{
den,
lib,
igloo, # igloo = nixosConfigurations.igloo.config
tuxHm, # tuxHm = igloo.home-manager.users.tux
...
}: {
# replace <system> if you are reporting a bug in MacOS
den.hosts.x86_64-linux.igloo.users.tux = {};
den.aspects.my-aspect.nixos.programs.git.enable = true;
den.aspects.igloo.includes = [den.aspects.my-aspect];
den.aspects.tux.includes = [
(den.lib.policy.when ({host, ...}: host.hasAspect den.aspects.git) {
nixos.programs.git.config.init.defaultBranch = "custom-main";
})
];
expr = igloo.programs.git.config.init.defaultBranch;
expected = "custom-main";
}
);
I'm aware of this issue and don't know if I have the best answer for you yet. I would really like for this to be possible. What you're asking for when you say that is "Based on the final resolution, make a decision about the resolution." which is why this particular path is infinite, and I'm not sure how to handle this.
Would it make any sense in this case, @sini, to define a boolean on the host entity that could be used to toggle the inclusion of both aspects? As a workaround at least?
I mean yeah, any pattern that avoids creating this cycle would work. hasAspect is the only property that is derived from the pipeline and creates this cycle problem.
Ok, good to know. Because I haven't done this yet, but it's something I probably totally would've done. :)
I definitely also did it during implementation and trust me I /really/ want this to work.
I may have a workaround by deferring and refiring unsatisfied policy guardfn's to later in the pipeline. It works in CI, I'll need you guys to verify if it works for you in the wild.