Skip to content

fix(core): a policy in a den.default include registers once - #765

Merged
sini merged 1 commit into
mainfrom
fix/den-default-policy-claim
Nov 12, 2026
Merged

sini merged 1 commit into
mainfrom
fix/den-default-policy-claim

Conversation

@sini

@sini sini commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Reported, bisected and traced by @istvnurbn in #764: (den.batteries.user-shell "fish") in den.default.includes defines users.users.<name>.shell twice since v0.20.0, so no host evaluates. Their bisect to 22b2097 (#753) and their claim trace are what pointed at the cause. Thank you!

#764 fixes the battery. The same failure also hits any policy record that a { host, user } include in den.default builds inline, so this PR fixes it in core:

den.default.includes = [
  ({ host, user }: {
    includes = [{
      __isPolicy = true;
      name = "my-shell";
      fn = { host, user, ... }: [ (den.lib.policy.provide { … receiver = host; }) ];
    }];
  })
];

Cause. Since #753, a { host, user } include that the descendant also gets (den.default) is fanned out at the host scope too, once per user. R6 drops that copy's class content for an accepted user, but its policies still register at the host scope, and the user's own copy registers again. The policy-name claim (claim.nix) tells registrations apart by whole-value ==. A record built inside the include is a new value in every copy, so each copy is displaced to its own identity and delivers again: twice for one user, three times each for two. A let-bound record compares equal and collapses, which is why define-user and primary-user worked, and why #764's let fixes the battery.

Fix. A policy record now carries the include site it was written at (children.nix policySiteKey):

  • the parametric include as written;
  • the include positions below it;
  • the bound entities its fn doesn't take as arguments, so a record that captured the outer user keeps one registration per user.

Every copy of one include is walked from the same value, and == compares a function inside a container by pointer, so copies' sites are equal. The site isn't the wrapped __fn: a functor's is rebuilt on every walk (normalize.nix wrapFunctorChild).

A claim with an equal site is a copy of a registration already made, so it isn't registered again. Two different records under one name keep different sites and stay two registrations (O4). A record with no site, and a value-equal match (O5), behave as before.

Behaviour against main

Each row holds in transition and acknowledged mode.

den.default { host, user } include v0.19.0 main this PR
inline policy, unique option once defined twice once
inline policy, list option 1 2 1
two users [0 1] [3 3] [1 1]
two records under one name, separate includes [1 1] [2 2] [1 1]
two records under one name, one include [1 1] [2 2] [1 1]
record in a static aspect inside the include 1 2 1
fn reads the outer user, two users [0 1] [2 2] [1 1]
bare policy.include of host content, two users [0 1] [2 2] [1 1]
den.batteries.user-shell once defined twice once
the same include on the user aspect (control) once once once

v0.19.0's [0 1] is an older bug: a user's registration overwrote its sibling's. This PR fixes that too.

Validation

  • New cells: templates/ci/modules/deadbugs/den-default-inline-policy.nix, 10 cells, each in transition and acknowledged mode. 20/20 here, 4/20 on main.
  • Full suite (ci.bash, 4 workers): 2200/2200.
  • Every template's drvs are equal to main: 14 configurations, 9 build and 5 fail to evaluate on both.
  • Evaluator cost (NIX_SHOW_STATS) on the 9 template configurations that evaluate: at most +0.08% function calls and +0.03% thunks.
  • #764's battery passes unmodified, so its change isn't needed once this lands.

A `{ host, user }` include in den.default is also fanned out at the host
scope for each user (#753), so a policy record it builds was registered
by every copy. The claim told copies apart by whole-value `==`, and a
record built inside the include is a new value in each copy, so each one
got its own identity and delivered again: twice for one user, three times
each for two.

A policy record now carries the include site it was written at: the
parametric include as written, its include positions below, and the
bound entities its `fn` doesn't take as arguments. A claim with an equal
site is a copy of a registration already made, so it isn't registered
again. Two different records under one name stay two registrations.

Reported in GitHub #764.
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label Nov 12, 2026
@sini
sini merged commit cbe76f2 into main Nov 12, 2026
17 checks passed
@sini
sini deleted the fix/den-default-policy-claim branch November 12, 2026 22:48
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