Native user registry: `den.users`, with `host.users` kept compatible
den has registries for hosts and standalone homes, but a user only exists inside a host, as den.hosts.<system>.<host>.users.<name>. There's no way to describe one person who logs into several machines and also has a standalone home somewhere, so configs build their own registry (the ACL environments guide pattern, fleet-demo), and standalone homes can't reach it at all. #649 and #779 both run into this.
This adds den.users.<name>, a user registry next to den.hosts and den.homes, built from den.schema.user. Declaring users on a host with den.hosts.<s>.<h>.users.<n> keeps working as it does today.
Where it stands now:
- #796 (draft) adds
den.users. Registry definitions go into each host'susers.<n>as normal definitions, so Nix's own priorities decide. Write a registry field withlib.mkDefaultif hosts should be able to override it. - #798 (draft) lets you assign a user from their own side with
den.users.<n>.hosts: host names,den.lib.condconditions, or named predicates. - #799 (draft) binds standalone homes to the registry user. A home attached to a host keeps that host's
user.classes. fleet-demo's own registry is renamed tofleet.users. If you copied that pattern, rename it the same way.
The plan below changed in a few places while building it: no per-host specificity rule, no precedence bands, no assignment stage, and no warning for configs that assign users from policies. What changed and why is in the two update comments, here and here. The original spec is still in the gist, but those comments win where they disagree.
Original write-up
Overview
den has registries for hosts (den.hosts) and standalone homes (den.homes), but a user only exists inside a host, as den.hosts.<system>.<host>.users.<name>. Nothing describes one person who logs into several machines and also has a standalone home somewhere else. Configs that need that build their own registry (the pattern in the ACL environments guide and the fleet-demo template), and standalone homes can't reach it at all; #649 and #779 both run into this.
This adds a native user registry to den v1. A user becomes one entity, and being on a host becomes a relation between that user and the host. Every way of declaring users through den's own options keeps working.
The full design, decisions and test plan are in the specification: https://gist.github.com/sini/26625fc7b8d19fd8cec1f0fe42810d28
Changes
den.users.<name>: the user registry, alongsideden.hostsandden.homes, built fromden.schema.user.den.hosts.<s>.<h>.users.<n>is unchanged. It assigns<n>to<h>, its fields are the per-host override for<n>@<h>(the spellingden.aspectsandden.homesalready use), and it registersden.users.<n>if absent. No warning, no edit.- Per-host fields win by specificity. On a host,
<n>@<h>beatsden.users.<n>field by field within a priority tier (mkForce, plain,mkDefault), so a globalmkDefaultnever overrides a per-host value. Aspects and class content keep ordinary module merging. den.users.<n>.hosts: assign from the user's side, by declared host name, by a condition (den.lib.cond, for exampleeq [ "host" "environment" ] "prod"), or by a named predicate (den.predicates.<name>). Read by a new builtinden.policies.user-to-hosts, which a config can exclude, as ACL-style setups that assign through their own policies will. Every source of assignment emits the same user-on-host relation, so overlaps collapse instead of conflicting.- Standalone homes bind the registry user the same way a host user does, so one include reading
userserves host users and homes alike. Atux@<h>home whose host is declared also sees that host'stux@<h>override. - Follow-up, separate change: den's existing lambda predicate sites (
includeIf,policy.when,filterBy) accept the same conditions and named predicates, and anonymous lambdas there get a warning, silenced byden.migrations.anonymous-predicates.suppressWarnings. Lambdas keep working, and no removal date is set.
Who is affected
- Configs with their own
options.den.users.registry(thefleet-demopattern): the option collides withden.users, and evaluation fails with a nixpkgs error. The migration is a rename toden.users.<name>. Watch for readers written asconfig.den.users.registry or { }: those don't fail; they silently read no users. - Standalone homes: a home's
usergainsden.schema.userfields, and a home attached to a declared host user now reportsuser.classes = [ home.class ]. What the home builds doesn't change. Both are called out in the release notes. - Everyone else: no change.
Until this lands, #780 documents how to read a home's own fields today, and #779 shows a single-include workaround using a declared host that den doesn't build (intoAttr = [ ]).
The specification is revised (https://gist.github.com/sini/26625fc7b8d19fd8cec1f0fe42810d28). It adds an assignment stage: assignment runs before hosts are resolved, over declared facts, so everything that reads host.users (home-manager detection, stub aspects, host-to-users, your own code) sees every assigned user. Policies can assign users in that stage with den.lib.policy.assign. Policies that assign during resolution keep working, with a warning pointing to the registry. Precedence bands, the replace/append fold and den.lib.cond now build on gen's libraries rather than re-implementing them.
Work is underway: #784 bumps the gen pin it builds on, and #785 pins today's standalone-home behaviour before it changes.
Update on where the implementation (#796) has moved from the plan above, and why:
- No "per-host fields win within a priority tier". At an exact tie there's no reliable way to tell a registry definition from a host one -- file names can be faked -- so registry definitions now go into the host's
users.<n>as normal definitions and Nix's own priorities decide. If a registry field is meant to be overridden per host, write it withlib.mkDefault. Two plain definitions that disagree are refused, same as anywhere else in a module. - No precedence bands or replace/append fold. With normal priorities deciding, there's nothing left for them to do. Lists merge the way the option says, and
mkForce/mkDefaultmean what they always mean. - fleet-demo's registry becomes
fleet.users, notden.users.<name>. Its users are picked by policy and aren't listed on any host, so moving them intoden.userswouldn't deliver them anywhere. There's also a guard: if the template grants groups andfleet.usersisn't defined, evaluation stops with a message instead of quietly building hosts with no users. If you copied that pattern, rename the same way. - Reading
den.users.<n>.<field>gives the registry's own value, resolved among its own definitions -- it isn't a host's view. The docs list where they differ (fields only a host sets aren't there, function-form fields that needhostcan't be read, and so on). - The assignment stage,
den.users.<n>.hostsand the standalone-home binding (#797–#799) were built on the old delivery model and need redoing on this one, so they'll come after #796.
Second update, for the redone #798 (assigning users from their own side) and #799 (standalone homes), both on top of #796:
- No assignment stage, facts,
den.lib.policy.assignoruser-to-hostspolicy. With Nix's own priorities deciding, a user listed from either side is just another definition of the host'susers.<n>, so there's nothing left for a separate stage to do.den.users.<n>.hosts(names,den.lib.condconditions, named predicates) is still the user-side spelling. - No warning for configs that assign users from policies. It would have fired on fleet-demo and on the ACL guide's pattern, both of which are fine as they are.
- A registry entry that is itself broken now fails every host, with an error naming the user, instead of staying hidden until a host uses it. Finding who's assigned where means reading each entry once; a broken config is a broken config.
- A home attached to a host keeps that host's
user.classes, rather than switching to[ home.class ]as planned. Switching would change what existinguser@hosthomes match. Homes without a host get a typed user from the registry, as planned.