Skip to content

fix(core): fan only the class module that needs a descendant entity - #761

Merged
sini merged 1 commit into
mainfrom
fix/userless-class-fanout
Nov 11, 2026
Merged

sini merged 1 commit into
mainfrom
fix/userless-class-fanout

Conversation

@sini

@sini sini commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Since v0.19.0, an aspect that has any class module requiring user loses all its content on a host with no users, and duplicates its static content on a host with several. Reported in Matrix by vipultyagi:

den.hosts.x86_64-linux.glacier = { };
den.aspects.feature = {
  nixos.services.openssh.enable = true;
  homeManager = { user, ... }: { };
};
den.aspects.glacier.includes = [ den.aspects.feature ];
# glacier.services.openssh.enable: true on v0.18.0, false on v0.19.0 and v0.20.0

Cause. #634, the fix for #629, made nixos = { user, ... }: at host scope fan out per user, rather than be dropped. It did that by promoting the whole aspect to be parametric on user (handlers/compile.nix). So everything in the aspect was applied once per user:

  • other class keys, so static content was duplicated with two users;
  • its includes, policies, provides and pipe keys;
  • with no users, nothing at all.

Bisected: 99cc0c5 fails, and its parent passes.

Fix. The fan-out moves from the aspect to the class module that needs it:

  • compile.nix is restored to its pre-fix: fan class-module entity args over scope descendants (#629) #634 form.
  • handlers/emit-classes.nix emits a class module that requires a strict-descendant entity kind missing from ctx once per instance of that kind, with the instance bound in ctx. Kinds fan shallowest first, as bind.nix does. With no instance, the module emits nothing.
  • A copy of content that the descendant kind also includes is marked __sharedFanOutFor, as bind.nix marks it (User aspects deliver host-class content (nixos/darwin/os) to their hosts by default #694 §11a R6).
  • A class key defined more than once, where one definition names a kind an ancestor scope fans, is emitted per definition. Before, the definitions were merged into one module, which hid the one needing user. This applies at the fanning scope and at the kind's own scope, so the two copies are keyed alike.
  • Two readers of such a key's aspect identity drop the definition index (identity.stripDefIndex): pipe.to targeting, and den.default matching in complex forwards.
  • The User aspects deliver host-class content (nixos/darwin/os) to their hosts by default #694 transition warning lists such a key per definition (common[0], common[1]), as main already lists a list-valued key (<policy:…>[1]). Its index is left as is, because existing cells pin it.

Behaviour against main

shape v0.18.0 main this PR
host with no users: the aspect's static content and includes kept lost kept
two users: static content beside a { user } module once twice once
nixos = { user, ... }: at host scope, two users (#629) dropped per user per user
nixos = { user ? null, ... }: (optional) once, no user per user once, no user
a source in both schema.host.includes and schema.user.includes n/a twice per user once per user
den.default.nixos = { user, ... }: (a key defined more than once) n/a error once per user
a key defined twice, statically and { user } n/a error, or static twice static once, the other per user

The behaviour changes against main:

  • An aspect's includes, policies, provides and pipe keys apply once at the host, as on v0.18, not once per user.
  • An optional user ? null is applied once, without a user. It is not required, so it is not fanned.

Validation

  • New cells:
    • templates/ci/modules/public/c1-aspects-schema/userless-host-class-fan.nix: 11/11 here, 2/11 on main.
    • userless-host-class-fan-readers.nix (pipe.to with a key defined twice): 4/4 here. Its two-definition host fan errors on main. With the wrap-classes.nix edit reverted, its user-scope and host-fan cells error.
  • The existing can't request user inside an aspect's nixos class module #629 cell and relationship-fanout.nix pass.
  • Full suite (ci.bash, 4 workers): 2161/2161 at 686eacc.
  • The drv comparison was run before the last edit, which reverted only the transition warning text and no module; the warning does not reach drvs.
  • Every template's drvs are equal to main: 14 configurations, 9 build and 5 fail to evaluate on both.
  • Self-review: three adversarial review rounds.
    • Round 1 rejected a first design that split the fanned keys into a synthetic child include; it was replaced.
    • Round 2's predicted shared-source loss did not reproduce (measured).
    • Round 3's pipe-targeting finding is fixed above, with cells. Its warning finding is disclosed above, not changed.

Not covered: standalone homes with a multiply-defined key that names user.

A class module requiring `user` at host scope (#629) promoted its whole
aspect to be parametric on `user`, so the aspect's other content and its
includes were applied once per user: duplicated with several users, and lost
on a host with none. The module now emits once per instance of the kind it
requires, at emission, and the rest of the aspect stays at the host.

A class key defined more than once, one definition naming a fanned kind,
emits per definition; pipe.to targeting and den.default matching read the
aspect's identity without the definition index.

Reported in Matrix.
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label Nov 11, 2026
@sini
sini merged commit c8e0340 into main Nov 11, 2026
17 checks passed
@sini
sini deleted the fix/userless-class-fanout branch November 11, 2026 19:50
sini added a commit that referenced this pull request Nov 17, 2026
…ance (#772)

## Summary

Reported by @minhtrancccp in Matrix, with a repo that reproduces it:
since #761, a host-class module in `den.default` that takes `user` is
lost from a host that accepts that user.

```nix
den.hosts.x86_64-linux.laptop.users.admin.userName = "usercccp";
den.aspects.kanata.nixos = { config, user, ... }: {
  services.kanata.enable = true;
  users.groups.uinput.members = [ user.userName ];
};
den.default.includes = [ den.batteries.define-user den.aspects.kanata ];
# services.kanata.enable: true on 1ebb7de, false on c8e0340 and main
```

A host accepts its users in transition mode, which is the default until
a config sets `den.migrations.user-host-content.acknowledged`, and under
an explicit `den.batteries.user-aspects`. Both lose the module.
Acknowledging the migration without `user-aspects` hides it, which is
why acknowledging fixed it for the reporter.

**Cause.** #761 fans a host-scope `nixos = { user, ... }:` module once
per user, in `handlers/emit-classes.nix`. It marked each fanned copy as
a shared fan-out, for #694's R6 rule: when the host accepts the user,
the user's own copy is lifted to the host, so the host's copy is
dropped. The drop in `edges/materialize-unified.nix` matches modules by
their location key. emit-classes gives the fanned copy the same key as
the user's own copy, deliberately, so the two dedup, and the drop
removed both.

**Fix.** A class module that fans per user isn't marked as a shared
fan-out. Its copy and the user's own carry one key, so the module system
applies them once without the drop. Aspect-level fan-out, which bind.nix
marks, is unchanged. The helpers that only served the mark
(`sharedWith`, `hostIdHash`, the include-root lookup) go with it.

This was missed because den's suite runs every cell with the transition
defaults off (`templates/ci/modules/test-support/end-state.nix`), and
#761's cells never accepted a user explicitly.

## Validation

- New cells,
`templates/ci/modules/deadbugs/accepted-user-class-fan.nix`. Each checks
the module's per-user content lands and lands once:
  - transition default, one user and two users;
- explicit `user-aspects`, with the transition defaults off and with the
migration acknowledged;
  - controls with no acceptance: acknowledged, and the end state.

  | den | result |
  |---|---|
  | 1ebb7de (before #761) | 6/6 |
  | c8e0340 (#761) and main | 2/6 (the two controls) |
  | this PR | 6/6 |

- The reporter's repo, evaluated against this branch:
`services.kanata.enable = true`, `uinput.members = [ "root" "usercccp"
]`, as on 36c499a.
- Full suite (`ci.bash`, 4 workers): 2214/2214.
- Every template's drvs are identical to main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-ci allow all CI integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant