fix: stop routing OS users into custom host classes
Bug
den.batteries.os-user is documented as forwarding the user class into OS-level users.users.<name> on NixOS/nix-Darwin hosts. However, the policy actually routes unconditionally into host.class, so custom host classes receive a users.users.<name> entry, even when no OS user module exists there.
Changes
- Guard
den.policies.user-to-hostso it only emits routes forhost.class == "nixos"or"darwin". - Add a regression test covering the custom host class case
AI Assistance
Codex with GPT-5.5 xhigh was used to identify the issue, prepare this patch, draft the commit message, and draft this PR description. The work was guided, reviewed, and accepted by myself.
I, Scott Guest, explicitly acknowledge the following:
- [x] My contribution is AI generated and I mention which models/mcp-servers/tools were used.
- [x] I recognize AI generated contribution as my own and am myself legally accountable for it.
- [x] My contribution aligns with Den LICENSE and does not violate any other projects licenses (e.g. GPL)
- [x] I will truthfully answer and provide any requested details on how contribution was generated.
Can you describe the custom host usage pattern more? You can also just add this policy to den.defaults.excludes list to disable it.
Can you describe the custom host usage pattern more? You can also just add this policy to den.defaults.excludes list to disable it.
"custom" is a bit of a misnomer for my exact use case. I have host.class = "systemManager", and System Manager does actually support users.users. Disabling the policy is fine as a workaround.
But regardless, I think the issue pointed at by this PR is real:
os-userhas documentation (here and here) implying it's for NixOS/nix-Darwin hosts.user-to-hostroutes into whateverhost.classis, so it can emitusers.users.<name>even ifhost.classis some custom class that does not supportusers.users.- From what I can gather, other batteries guard config to the specific supported classes, avoiding this sort of issue.
Looking at this deeper, my actual usage is running into a related issue that's closer to a UX bug, which this PR doesn't address. Say I have:
{
den.hosts.x86_64-linux.workstation = {
class = "systemManager";
users.tux.classes = [ ]
};
}
This config does not provide any explicit den.aspects.tux.user = { ... }, and it opts out of the defaulted classes = [ "user" ], so I would expect to only get the Den-level user entity. I would not expect an OS-level users.users.tux entry.
Somewhat surprisingly though, System Manager fails with assertions like:
Failed assertions:
- Exactly one of users.users.tux.isSystemUser and users.users.tux.isNormalUser must be set.
- users.users.tux.group is unset. This used to default to nogroup, but this is unsafe.
It turns out that, as mentioned in this comment, user-to-host can create an empty placeholder OS-level users.users.tux = { }; even when there is no real user class content to forward. This is useful for integrated Home Manager on NixOS/nix-Darwin because HM reads config.users.users.<name>.name / .home from the parent OS config.
This is surprising: user-to-host can silently add an OS-level users.users.<name> option (and an empty/incomplete one at that), solely from the existence of a Den user entity, even outside the HM-integrated-with-NixOS/nix-Darwin case where it may be necessary.