den icon indicating copy to clipboard operation
den copied to clipboard

Bug: homeManager content on host-included aspects is silently dropped unless the aspect is user-parametric

Open xfo-0 opened this issue 5 months ago • 6 comments

Summary

homeManager class content on an aspect included at host scope is silently discarded — unless the aspect (or sub-aspect) is parametric taking { user, ... }, in which case it is projected per-user and delivered. Plain attrset aspects and parametric aspects taking only { host, ... } lose their homeManager content with no diagnostic.

If this is the intended routing model (homeManager only collects at user scope; user-parametric aspects at host scope act as per-user projection), the silent half is still a footgun: an aspect mixing nixos + homeManager classes included at host scope applies its nixos half and silently drops the rest. In a real config this cost an hour of bisecting, because parametric sibling sub-aspects delivered fine while one plain sub-aspect didn't — same includes list, no error, no warning.

Repro (self-contained flake)

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-parts.url = "github:hercules-ci/flake-parts";
    den.url = "github:denful/den";
    home-manager.url = "github:nix-community/home-manager";
  };

  outputs =
    inputs:
    inputs.flake-parts.lib.mkFlake { inherit inputs; } {
      systems = [ "x86_64-linux" ];
      imports = [
        inputs.den.flakeModule
        (
          { den, ... }:
          {
            den.schema.user.classes = [ "homeManager" ];
            den.default.homeManager.home.stateVersion = "25.05";
            den.hosts.x86_64-linux.igloo.users.tux = { };

            den.aspects.igloo = {
              includes = [
                den.aspects.plain-feature
                den.aspects.user-param-feature
              ];
              nixos = {
                boot.loader.grub.enable = false;
                fileSystems."/".device = "/dev/noboot";
                fileSystems."/".fsType = "auto";
              };
            };

            den.aspects.tux.includes = [
              den._.define-user
              den._.primary-user
            ];

            den.aspects.plain-feature.homeManager =
              { pkgs, ... }:
              {
                home.packages = [ pkgs.hello ];
              };

            den.aspects.user-param-feature = (
              { user, ... }:
              {
                homeManager =
                  { pkgs, ... }:
                  {
                    home.packages = [ pkgs.cowsay ];
                  };
              }
            );
          }
        )
      ];
    };
}
$ nix eval .#nixosConfigurations.igloo.config.home-manager.users.tux.home.packages \
    --apply 'ps: builtins.filter (n: builtins.match ".*(hello|cowsay).*" n != null) (map (p: p.name) ps)'
[ "cowsay-3.8.4" ]

cowsay (user-parametric) is delivered; hello (plain) is gone, with no diagnostic.

Variants tested

include scope aspect shape homeManager reaches user?
host plain attrset no (silent)
host parametric { host, ... } no (silent)
host parametric { user, ... } yes (per-user projection)
host nested sub-aspect, plain no (silent)
host nested sub-aspect, parametric { user, ... } yes
user plain attrset yes
user parametric { user, ... } yes

Nesting depth doesn't matter — only the include scope and whether the aspect declares a user context arg.

Verified identical on denful/den main (f5e79c37) and sini/den feat/entity-gen-schema-port (8e64984).

Ask

Either deliver host-scope homeManager content with defined semantics (e.g. to all of the host's users), or make the drop loud — a warning or abort naming the aspect and the unroutable class. For den v2, the class-modules/classify step seems like the natural place to pin this with a test either way.

xfo-0 avatar Jun 11 '26 19:06 xfo-0

Hello,

Thanks for the report... do you think you could use this template to build a reproducer ?

drupol avatar Jun 11 '26 19:06 drupol

This is good enough to reproduce. I'll look into it.

sini avatar Jun 11 '26 20:06 sini

Bogus-template reproducer (den fe63b4b): 2/3 — both user-parametric variants deliver, the plain attrset gets MISSING. Ready for templates/ci/modules/deadbugs/ alongside a fix.

{ denTest, ... }:
{
  flake.tests.bogus = {

    # plain attrset aspect included at host scope: homeManager silently dropped
    test-host-plain-hm-delivered = denTest (
      { den, tuxHm, ... }:
      {
        den.schema.user.classes = [ "homeManager" ];
        den.default.homeManager.home.stateVersion = "25.05";
        den.hosts.x86_64-linux.igloo.users.tux = { };

        den.aspects.tux.includes = [
          den._.define-user
          den._.primary-user
        ];

        den.aspects.igloo.includes = [ den.aspects.feature ];
        den.aspects.feature.homeManager.home.sessionVariables.MARKER = "plain";

        expr = tuxHm.home.sessionVariables.MARKER or "MISSING";
        expected = "plain";
      }
    );

    # user-parametric aspect included directly at host scope
    test-host-user-parametric-hm-delivered = denTest (
      { den, tuxHm, ... }:
      {
        den.schema.user.classes = [ "homeManager" ];
        den.default.homeManager.home.stateVersion = "25.05";
        den.hosts.x86_64-linux.igloo.users.tux = { };

        den.aspects.tux.includes = [
          den._.define-user
          den._.primary-user
        ];

        den.aspects.igloo.includes = [ den.aspects.feature ];
        den.aspects.feature = (
          { user, ... }:
          {
            homeManager.home.sessionVariables.MARKER = "param";
          }
        );

        expr = tuxHm.home.sessionVariables.MARKER or "MISSING";
        expected = "param";
      }
    );

    # user-parametric SUB-aspect under a host-included parent
    test-host-nested-user-parametric-hm-delivered = denTest (
      { den, tuxHm, ... }:
      {
        den.schema.user.classes = [ "homeManager" ];
        den.default.homeManager.home.stateVersion = "25.05";
        den.hosts.x86_64-linux.igloo.users.tux = { };

        den.aspects.tux.includes = [
          den._.define-user
          den._.primary-user
        ];

        den.aspects.igloo.includes = [ den.aspects.feature ];
        den.aspects.feature.includes = [ den.aspects.feature.sub ];
        den.aspects.feature.sub = (
          { user, ... }:
          {
            homeManager.home.sessionVariables.MARKER = "nested-param";
          }
        );

        expr = tuxHm.home.sessionVariables.MARKER or "MISSING";
        expected = "nested-param";
      }
    );

  };
}

xfo-0 avatar Jun 11 '26 23:06 xfo-0

So the the correct behavior here would be that user-param-feature wouldn't fire; it's accidentally collecting in the user scope because it's parametric. It's not in the user's includes tree; and the user doesn't use the host-aspects battery.

So a real bug, but I believe it's the inverse of your expectation.

sini avatar Jun 11 '26 23:06 sini

Makes sense — inverted from my read: the parametric variants are the accident (collecting at user scope without being in the user includes tree), plain-drop is consistent with homeManager-routes-via-user-scope, and den._.host-aspects is the blessed projection.

~~Worth flagging: configs (ours included) lean on the accidental parametric projection for host-scope user content — e.g. window-manager sub-aspects reading { user, ... } context, which the battery cannot cover since they never resolve host-side.~~ Correction below: the battery does cover those carriers — its post-walk spawn resolves with both host and user bindings. A heads-up or deprecation note when the fix lands would still help configs that rely on the projection without the battery opt-in.

xfo-0 avatar Jun 12 '26 05:06 xfo-0

Correction to my last claim, tested via the same bogus harness: den._.host-aspects DOES cover { user, ... } carriers — its post-walk spawn resolves with both host and user bindings. On current main, battery + parametric = delivered twice (accidental projection + battery; home.packages marker shows count 2), battery + plain = exactly once. So after removing the accidental projection the battery alone yields single delivery for both shapes — migration is just "opt users into the battery", no carrier rewrites needed.

xfo-0 avatar Jun 12 '26 05:06 xfo-0