fix: stop routing OS users into custom host classes#573
Conversation
| }) | ||
| ]; | ||
| lib.optional | ||
| (builtins.elem host.class [ |
There was a problem hiding this comment.
I think you might perhaps replace this with when attribute in the policy definition. To be checked.
https://den.denful.dev/explanation/policy-activation/#denlibpolicywhen-predicate-policy
There was a problem hiding this comment.
Agreed, and I verified that it's equivalent. Amended.
There was a problem hiding this comment.
I think you can add the when attribute inside the policy you want to introduce, not outside and before it.
There was a problem hiding this comment.
Oops, ignore this comment. That said, it might be an idea for @sini ?
E.g., we could do something like:
den.policies.user-to-host =
{ user, host, ... }:
[
(den.lib.policy.route {
fromClass = "user";
intoClass = host.class;
path = [
"users"
"users"
user.userName
];
adaptArgs = args: args // { osConfig = args.config; };
when = { user, host, ... }:
builtins.elem host.class [
"nixos"
"darwin"
];
})
]Guard `den.policies.user-to-host` so it only emits routes for `host.class == "nixos"` or `"darwin"`. This avoids introducing `users.users.<name>` entries on custom host classes that may not have an OS-level `users` module.
|
Can you describe the custom host usage pattern more? You can also just add this policy to den.defaults.excludes list to disable it. |
f566f97 to
42dff7f
Compare
| den.lib.policy.when | ||
| ( | ||
| { user, host, ... }: | ||
| builtins.elem host.class [ |
There was a problem hiding this comment.
this might break with wsl or some microvm configs; I would like to understand the actual problem that made this an issue before reviewing the solution to it
"custom" is a bit of a misnomer for my exact use case. I have But regardless, I think the issue pointed at by this PR is real:
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 Somewhat surprisingly though, System Manager fails with assertions like: It turns out that, as mentioned in this comment, This is surprising: |
| den.lib.policy.when | ||
| ( | ||
| { user, host, ... }: | ||
| builtins.elem host.class [ | ||
| "nixos" | ||
| "darwin" | ||
| ] | ||
| ) | ||
| ( | ||
| { user, host, ... }: | ||
| [ | ||
| (den.lib.policy.route { | ||
| fromClass = "user"; | ||
| intoClass = host.class; | ||
| path = [ | ||
| "users" | ||
| "users" | ||
| user.userName | ||
| ]; | ||
| adaptArgs = args: args // { osConfig = args.config; }; | ||
| }) | ||
| ] | ||
| ); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Bug
den.batteries.os-useris documented as forwarding theuserclass into OS-levelusers.users.<name>on NixOS/nix-Darwin hosts. However, the policy actually routes unconditionally intohost.class, so custom host classes receive ausers.users.<name>entry, even when no OS user module exists there.Changes
den.policies.user-to-hostso it only emits routes forhost.class == "nixos"or"darwin".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: