Skip to content

feat: synthesize host identity for standalone user@host homes - #605

Merged
sini merged 1 commit into
mainfrom
fix/list-returning-include-effects
Jun 10, 2026
Merged

sini merged 1 commit into
mainfrom
fix/list-returning-include-effects

Conversation

@sini

@sini sini commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

A standalone home named user@host could not resolve host-keyed config (provides.<host>, policy.when ({ host, ... }: ...)) unless the host was declared in den.hosts.<system> — and declaring it forces instantiation of the host's platform builder (e.g. inputs.darwin.lib.darwinSystem), which a home-only flake should not need.

This synthesizes a minimal { name = hostName; } host identity from the user@host name when the host isn't declared, so host-name-keyed provides and policies resolve without instantiating a real host. A declared host still wins and remains the only thing that wires osConfig.

Reproduces the original report: a darwin standalone home using provides.Bens-MacBook-Pro now resolves with no host declared and no nix-darwin import (test-darwin-home-provides-synthetic-host-grammar).

Design

  • Host-only synthesis (home.nix): only host is synthesized, never user. A lone synthetic host fires { host }-keyed policies, while { host, user } OS batteries (define-user, user-to-host, …) keep their existing null-user gating and fall back to their home-scope path.
  • Cross-policy (provide.nix): the named provides.<name> cross-policy now treats all entity args as optional and gates delivery on user != null || home != null. This reaches both user and home scopes (required-arg-based late-dispatch kind matching would otherwise restrict it to a single kind) while staying inert at a bare host scope.
  • host ? class invariant: every { host }-keyed OS-output aspect (os-class, unfree, insecure, hostname, flake-parts inputs'/self') gates OS-class routing/imports on host ? class, symmetric with the existing home ? class / user ? classes guards. A classless synthetic host produces no OS output.

Also

Fixes a related crash: an aspect includes function returning a list of effects (e.g. lib.optional cond (policy.include {...})) threw "expected a set but found a list". mkParametricNext now normalizes a list return into includes (include-effect descriptors contribute their .value, bare aspects pass through, nested lists are flattened, other effect kinds throw a clear den: error).

Tests

templates/ci/modules/deadbugs/standalone-home-host-context.nix (10 tests): synthetic-host darwin grammar, declared-host paths, both include grammars (set + list + nested-list), multi-include, non-include-effect error, the hostname battery staying inert on a synthetic host, and the no-fire plain-home path.

just ci: 889/889.

@sini
sini requested a review from vic as a code owner June 10, 2026 22:30
@github-actions github-actions Bot added the allow-ci allow all CI integration tests label Jun 10, 2026
A standalone home named `user@host` could not resolve host-keyed config
(`provides.<host>`, `policy.when ({ host, ... }: ...)`) unless the host was
declared in `den.hosts` — and declaring it forces instantiation of the
host's platform builder (e.g. nix-darwin), which a home-only flake should
not need.

Synthesize a minimal `{ name = hostName; }` host identity from the
`user@host` name when the host isn't declared, so host-name-keyed provides
and policies resolve without instantiating a real host. A declared host
still wins and remains the only thing that wires `osConfig`. Only `host` is
synthesized, never `user`: a lone synthetic host fires `{ host }`-keyed
policies (gated on `host ? class` so OS-class routing stays inert for a
classless synthetic host), while `{ host, user }` OS batteries keep their
existing null-user gating and fall back to their home-scope path.

- provide.nix: the named cross-policy now treats all entity args as optional
  and gates delivery on `user != null || home != null`. This lets it reach
  both user and home scopes (required-arg-based late-dispatch kind matching
  would otherwise restrict it to a single kind) while staying inert at a bare
  host scope.
- os-class/unfree/insecure: gate OS-class routing/imports on `host ? class`
  (mirrors the existing homeAspect guard) so a classless synthetic host
  produces no OS output.

Also fixes a related crash: an aspect `includes` function returning a list
of effects (e.g. `lib.optional cond (policy.include {...})`) threw
"expected a set but found a list". mkParametricNext now normalizes a list
return into includes — include-effect descriptors contribute their `.value`,
bare aspects pass through, other effect kinds throw a clear `den:` error.

Regression tests in deadbugs/standalone-home-host-context.nix cover the
synthetic-host darwin grammar, the list-returning include, and the
no-fire/declared-host paths.
@sini
sini force-pushed the fix/list-returning-include-effects branch from 4a29185 to 2a5358d Compare June 10, 2026 22:35
@sini
sini enabled auto-merge (squash) June 10, 2026 23:04
@sini
sini merged commit f5e79c3 into main Jun 10, 2026
29 checks passed
@sini
sini deleted the fix/list-returning-include-effects branch June 10, 2026 23:06
sini pushed a commit that referenced this pull request Jun 11, 2026
With PR #605 standalone homes have a host identity. This caused the
check to pass even though the host has no class causing the unfree
battery to fail with the following error:
```
       error: attribute 'class' missing
       at /nix/store/wnv7bc1psj89ylp29z3kabkbpwja0npn-source/modules/aspects/batteries/unfree/unfree.nix:44:28:
           43|           && host != null
           44|           && builtins.elem host.class validClasses
             |                            ^
           45|         ) { ${host.class}.unfree.packages = allowed-names; };
```
This PR changes a host existence check to the availability of its class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-ci allow all CI integration tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants