den icon indicating copy to clipboard operation
den copied to clipboard

host.mainModule omits host content delivered through provides.to-users / provides.<user>

Open sini opened this issue 1 week ago • 1 comments

host.mainModule was missing host-class content that a host delivers to its users through provides.to-users or provides.<user>, while nixosConfigurations.<host> had it. So a config built from mainModule (the way the from-flake-to-den guide shows) silently lost those deliveries, and host.hasAspect couldn't see them either.

Repro: host igloo with user tux, an aspect x that sets environment.etc."mark-x", and den.aspects.igloo.provides.to-users.includes = [ x ]. Expected mark-x in both nixosConfigurations.igloo and a host built from host.mainModule. Actual: only nixosConfigurations.igloo had it. The table in the original write-up covers every delivery path.

Cause: the host-rooted resolve behind mainModule didn't record that its root was the host, so policies on the host found no registrant and the route carrying a user scope's host-class content back to the host never got emitted.

Fixed on main by #792 (mainModule) and #794 (hasAspect). Configs that build hosts from mainModule gain these deliveries, which is in the release notes. This one can be closed.

Original write-up

host.mainModule doesn't contain host-class content that a host aspect delivers to its users through provides.to-users or provides.<user>. nixosConfigurations.<host> does contain it, so the two disagree on the same host.

Reproduction

Host igloo with users tux and pingu, and an aspect x whose nixos sets environment.etc."mark-x". Each row delivers x one way and asks whether mark-x is present in the host's config built two ways:

  • nixosConfigurations.igloo (what den builds);
  • host.instantiate { modules = [ host.mainModule { nixpkgs.hostPlatform = lib.mkDefault host.system; } ]; } (what reference/output.mdx says den builds).
delivery nixosConfigurations.igloo via host.mainModule
den.aspects.igloo.includes true true
den.aspects.igloo.provides.to-users.includes true false
den.aspects.igloo.provides.tux.includes true false
den.aspects.tux.includes false false
den.aspects."tux@igloo".includes false false
den.schema.user.includes false false
den.default.includes true true

Users and home-manager content agree on both routes; only the two host-provided deliveries differ. Measured on main at fa26ee39.

Cause

nixosConfigurations is built from a per-host assembly over the flake-level resolve; mainModule is __resolveResult.imports, the host's own resolve. Both walk x into the user scopes. The per-host assembly then carries its host-class content up to the host, and the host-rooted assembly drops it at the user boundary. The two are meant to agree; the flat surface is documented in the materializer as "the root's bounded subtree too, so it agrees with the per-host merge".

Impact

  • guides/from-flake-to-den.mdx has you add igloo.mainModule to an existing nixosSystem. That config silently loses every provides.to-users / provides.<user> host delivery.
  • guides/debug.md inspects mainModule in the REPL, so what you inspect isn't what builds.
  • host.hasAspect reads the same host-rooted resolve, so it can't see these deliveries either. That blocks making hasAspect answer from what actually lands in the host's config.

Fix

Make the host-rooted resolve carry the same host-provided deliveries as the per-host assembly, so mainModule, nixosConfigurations and hasAspect read one answer. Tests compare the two routes across every delivery path. Configs that build hosts from mainModule will gain these deliveries; that goes in the release notes.

sini avatar Nov 24 '26 20:11 sini

Fixed by #792 (mainModule) and #794 (hasAspect), both on main. Closing.

sini avatar Dec 04 '26 23:12 sini