Repository navigation
Conversation
With `(den.batteries.user-shell "<shell>")` in `den.default.includes`,
`users.users.<name>.shell` is defined twice and the host does not
evaluate:
```
error: The option `users.users.tux.shell' is defined multiple times while it's expected to be unique.
Definition values:
- In `nixos@<provide>/': <derivation fish-4.7.1>
- In `nixos@<provide>/': <derivation fish-4.7.1>
```
This worked on v0.19.0. The battery on a user aspect, on a host aspect
or in `den.schema.user.includes` still works.
## Reproduction
`templates/ci/modules/deadbugs/user-shell-den-default.nix`: one host,
one user, `define-user` and `user-shell "fish"` in
`den.default.includes`, plus a control with the battery on the user.
```
expected: { fish = true; shell = "fish"; }
actual: error: The option `users.users.tux.shell' is defined multiple times
```
The same test as a bogus `bug.nix` passes on v0.19.0 and fails on
v0.20.0 as released (36c499a) and on main. Bisecting with it names
22b2097 (denful#753) as the first bad commit.
## Cause
Since denful#746 the battery hands the shell to the host through a policy
record that `userShell shell` builds inside its `{ host, user }`
include. Each evaluation of that include gives a new record with a new
`fn` closure. Since denful#753 the `{ host, user }` includes of `den.default`
are registered at the host scope and again at the user scope (traced
for `define-user` and `user-shell`). The policy-name claim
(`registerPolicy`, moved to `claim.nix` by denful#756) tells registrations
apart by `==`. The second record is not equal to the first, so it gets
the identity `user-shell/tux@igloo/user-shell-host/fish#1`.
`dedupProvides` keys on that identity, so both deliveries land.
`define-user` and `primary-user` put a `let`-bound `fn` in their
records. Those compare equal, keep one identity and are delivered once.
## Fix
Build the record once per `user-shell` call, in a `let` around the
battery, so every scope its include reaches registers the same record.
The second claim then compares equal and keeps the first identity
(O5 in `claim.nix`). Nothing under `nix/lib` changes.
Two separate calls, `user-shell` on a host aspect and again on its
user, still define the shell twice, as on v0.19.0.
## Checked
On NixOS with Nix 2.34.9, against main at a66a778:
| Check | main | main + fix |
| --- | --- | --- |
| `just test user-shell-den-default` | fails | passes |
| `just ci user-shell-den-default` | fails | passes |
| `just ci-deep` | 2178/2178 pass | 2180/2180 pass (+ the 2 new cells) |
| `just fmt` | | no changes |
| `just unit` (checkmate) | | passes |
`ci-deep` and `unit` ran while the suite was still nested as
`deadbugs.user-shell-den-default`. Moving it to the top level changed
only that key, and `just fmt` changes nothing after it.
With the fix, the bogus `bug.nix` passes on main and on 36c499a.
`user-shell` on a host aspect alone or in `den.schema.user.includes`
still passes, and `define-user` with `primary-user` in `den.default`
still applies once.
Also tested locally on my own config.
AI-assisted: the analysis and the patch were drafted with Claude. I
reproduced and checked everything above on my own machine.
sini
added a commit
that referenced
this pull request
Nov 12, 2026
## 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: ```nix 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.
Contributor
Author
|
#765 fixes the root cause |
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.
(den.batteries.user-shell "<shell>")inden.default.includesshould set each user's shell once, as it did on v0.19.0. The v0.20.0 release notes say that upgrading "changes nothing for your systems today", and #750 lists shells and "Anything inden.default" among the things that keep working unchanged. Since v0.20.0,users.users.<name>.shellis defined twice, both times atnixos@<provide>/(darwin@<provide>/on nix-darwin), so no host evaluates.The battery still works on a user aspect, on a host aspect or in
den.schema.user.includes.Reproduction
templates/ci/modules/deadbugs/user-shell-den-default.nix. The same tests also run as a bogusbug.nix:The control in the same file,
test-user-shell-on-user, puts the battery onden.aspects.tuxinstead.test-user-shell-in-den-defaulttest-user-shell-on-user(control)The fix also makes the test pass on 36c499a. The v0.20.0 tag now points at a66a778, the same commit as main. 36c499a was main's head when the release was published.
First bad commit: 22b2097, "feat(core): an entity's content stays in its entity, with transition defaults (#694, 3/3) (#753)".
git bisectran from v0.19.0 (good) to 36c499a (bad), with the bogus test as the check, and skipped no commit. The parent, f2ec96b (#747), passes, even though the battery already had its current form there (#746).Cause
Since #746 the battery hands the shell to the host through a policy record that
userShell shellbuilds inside the battery's{ host, user }include:So each evaluation of that include gives a new record with a new closure,
fn = hostShell shell.Since #753,
den.default's{ host, user }includes are registered at the host scope and again at the user scope. I traced this fordefine-useranduser-shell. The policy-name claim (registerPolicy, moved toclaim.nixby #756) tells registrations apart by==. The seconduser-shellrecord is not equal to the first, so it gets a displaced identity.dedupProvideskeys on that identity, so the two keys differ and both deliveries land.A temporary
builtins.tracein the claim and indedupProvides, on 36c499a, for the test above (user hash shortened):On f2ec96b the same test claims
user-shell-host/fishonly once, at the user scope. On 22b2097 it is claimed at both scopes, as above.define-userandprimary-usertake the same path, but their records hold alet-boundfn(fn = account;,fn = hostSettings;). Their second claim is equal to the first (equalToAnEarlierClaim=yes), keeps its identity and gives one key. That is why they still work fromden.default.Fix
Build the record once per
user-shellcall, in aletaround the battery, so every scope its include reaches registers the same record. The second claim then compares equal and keeps the first identity, which is O5 inclaim.nix. With the fix, the same trace showsequalToAnEarlierClaim=yes identity=user-shell-host/fishat the user scope and a singleuser-shell-host/fishkey. Nothing undernix/libchanges.Ignoring whitespace (
git diff -w):Full diff (the rest of the battery is only re-indented, as
just fmtlays out alet)Two separate calls, one on a host aspect and one on its user, still define the shell twice. They did on v0.19.0 too, so that is not a regression and this PR leaves it alone.
Checked
On NixOS with Nix 2.34.9, against main at a66a778:
just test user-shell-den-defaultjust ci user-shell-den-defaultjust ci-deepjust fmtjust unit(checkmate)ci-deepandunitran while the suite was still nested asdeadbugs.user-shell-den-default. Moving it to the top level changed only that key, andjust fmtchanges nothing after it.Also checked with the bogus template:
bug.nixpasses with the fix on main and on 36c499a.user-shellon a host aspect alone, or inden.schema.user.includes, passes on v0.19.0, on 36c499a and with the fix.define-userandprimary-userinden.defaultapply once (extraGroups = [ "wheel" "networkmanager" ]) on v0.19.0, on 36c499a and with the fix.On my own config: three NixOS hosts and one nix-darwin host, with Den locked to the v0.20.0 tag (a66a778).
user-shellinden.default.includes, every host fails with the error above (darwin@<provide>/on the darwin host). With the fix, every host evaluates.user-shellinden.schema.user.includes, my current workaround, the fix leaves all four system derivations unchanged.user-shellback toden.defaultchanges only the flake's own registry entry on three hosts (etc-nix-registry.json, oretc-registry.jsonon darwin). It changes nothing on the fourth host, which has no registry entry for the flake: that host doesn't include the aspect that adds the entry. That is a gap in my config, unrelated to Den and to this fix.Discussion: #750, which asks for breakage reports there or on #694.
AI-assisted: the analysis and the patch were drafted with Claude. I reproduced and checked everything above on my own machine.