Skip to content

Infinite recursion with den.lib.policy.when and <entity>.hasAspect #525

Closed

Description

@jadestar1864

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";
  }
);

Activity

  1. added
    bug
    on May 12, 2026
  2. sini commented on May 13, 2026

    @sini
    Collaborator

    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.

  3. theutz commented on May 13, 2026

    @theutz
    Collaborator

    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?

  4. sini commented on May 13, 2026

    @sini
    Collaborator

    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.

  5. theutz commented on May 13, 2026

    @theutz
    Collaborator

    Ok, good to know. Because I haven't done this yet, but it's something I probably totally would've done. :)

  6. sini commented on May 13, 2026

    @sini
    Collaborator

    I definitely also did it during implementation and trust me I /really/ want this to work.

  7. sini commented on May 13, 2026

    @sini
    Collaborator

    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.

  8. added 2 commits that reference this issue on May 16, 2026
    15bc741
    75cc09b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions