Repository navigation
fix(core): fan only the class module that needs a descendant entity - #761
Merged
Merged
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since v0.19.0, an aspect that has any class module requiring
userloses all its content on a host with no users, and duplicates its static content on a host with several. Reported in Matrix by vipultyagi: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 onuser(handlers/compile.nix). So everything in the aspect was applied once per user:Bisected: 99cc0c5 fails, and its parent passes.
Fix. The fan-out moves from the aspect to the class module that needs it:
compile.nixis restored to its pre-fix: fan class-module entity args over scope descendants (#629) #634 form.handlers/emit-classes.nixemits 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, asbind.nixdoes. With no instance, the module emits nothing.__sharedFanOutFor, asbind.nixmarks it (User aspects deliver host-class content (nixos/darwin/os) to their hosts by default #694 §11a R6).user. This applies at the fanning scope and at the kind's own scope, so the two copies are keyed alike.identity.stripDefIndex):pipe.totargeting, andden.defaultmatching in complex forwards.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
{ user }modulenixos = { user, ... }:at host scope, two users (#629)nixos = { user ? null, ... }:(optional)schema.host.includesandschema.user.includesden.default.nixos = { user, ... }:(a key defined more than once){ user }The behaviour changes against main:
user ? nullis applied once, without a user. It is not required, so it is not fanned.Validation
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.towith a key defined twice): 4/4 here. Its two-definition host fan errors on main. With thewrap-classes.nixedit reverted, its user-scope and host-fan cells error.userinside an aspect'snixosclass module #629 cell andrelationship-fanout.nixpass.ci.bash, 4 workers): 2161/2161 at 686eacc.Not covered: standalone homes with a multiply-defined key that names
user.