den icon indicating copy to clipboard operation
den copied to clipboard

Aspect includes fail when aspects are defined in different files loaded by import-tree

Open philipp-baumann opened this issue 2 months ago • 5 comments

Summary

When den.aspects.X and den.aspects.Y are defined in different files loaded by import-tree, an includes = [ den.aspects.Y ] reference in X's definition does not resolve Y's homeManager content. The same include works when both aspects are defined in the same file.

Reproduction

My home-manager configuration (696 tables, 45 aspects) with homes.nix split across files:

https://codefloe.com/philipp-baumann/agentic-tooling-and-configs

Monolithic (works):

# modules/homes.nix
{ inputs, den, mypkgs, ... }: {
  imports = [ inputs.den.flakeModule ];

  den.aspects.home.homeManager = {
    home.stateVersion = "26.05";
  };

  den.aspects.philipp = {
    includes = [ den.aspects.home den.aspects.sops /* ... 40 more */ ];
  };

  den.homes.aarch64-darwin.philipp = { ... };
  den.homes.x86_64-linux.philipp-linux = { ... };
}

nix eval .#homeConfigurations.spectral-cockpit.activationPackage.drvPath — succeeds, home.stateVersion resolves.

Split (fails):

# modules/homes.nix — thin wiring only
{
  inputs, den, mypkgs, ...
}: {
  imports = [ inputs.den.flakeModule ];
  den.homes.aarch64-darwin.philipp = { ... };
  den.homes.x86_64-linux.philipp-linux = { ... };
  den.homes.x86_64-linux.spectral-cockpit = { ... };
}

# modules/homes-philipp.nix — separate file
{ den, ... }: {
  den.aspects.philipp = {
    includes = [ den.aspects.home den.aspects.sops /* ... */ ];
  };
}

# modules/base.nix — unchanged
{ den, ... }: {
  den.aspects.home.homeManager = {
    home.stateVersion = "26.05";
  };
}

nix eval .#homeConfigurations.spectral-cockpit.activationPackage.drvPath — fails with:

error: The option `home.stateVersion' was accessed but has no value defined.
Try setting the option.

What was tested

  • Both files exist in the same modules/ directory, loaded by (denful-import-tree ./modules) in the flake output.
  • den.aspects.home is defined in base.nix as den.aspects.home.homeManager = { home.stateVersion = "26.05"; ... }.
  • den.aspects.philipp in the separate file includes den.aspects.home — but the stateVersion does not reach the home-manager configuration.
  • Moving the aspect definition back into the monolithic homes.nix (and deleting the separate file) resolves the issue immediately.
  • Subdirectory placement (modules/homes/philipp.nix) vs flat (modules/homes-philipp.nix) makes no difference.
  • Adding den to the file's function signature ({ den, ... }:) vs { ... }: makes no difference.

Expected behaviour

Aspect includes should resolve references to aspects defined in other modules loaded by the same import-tree, regardless of which file each aspect is defined in.

Actual behaviour

The includes reference resolves to an empty or different aspect, so the included aspect's homeManager content (including home.stateVersion) is not contributed to the merged configuration.

philipp-baumann avatar Sep 27 '26 21:09 philipp-baumann

I understand your report -- but there's no way that it's correct. Can you ask your LLM to to reproduce using our bogus template? This report reads like an LLM mis-reading the results of failing to git stage a new file for inclusion in your local flake environment.

sini avatar Sep 27 '26 23:09 sini

Sorry for using your time for my bogous report. I will try like you suggested and trying to understand. Thanks!

philipp-baumann avatar Sep 28 '26 03:09 philipp-baumann

The maintainer's diagnosis is correct, and this report was wrong. Closing the loop with a reproduction.

What actually happened

The failing split had new files that were never git added. Nix flakes only see tracked files, so import-tree silently never loaded them — the aspects simply didn't exist, which surfaced as the misleading home.stateVersion was accessed but has no value defined error. I misread that as a cross-file include failure.

Reproduction with the bogus template

Two cells in one run, nix flake init -t github:denful/den#bogus:

  • same-file-include — control: base-same and the tux auto-aspect in modules/bug.nix, chained tux -> base-same.
  • cross-file-include — base-cross in repro/split-base.nix, consumer-cross in repro/split-consumer.nix (plain { den, ... }: modules), pulled into the test via the test module's imports. Chain: tux -> consumer-cross -> base-cross.

With everything staged:

$ nix eval --json .#tests.bogus
{"cross-file-include":{"expected":"from-base","expr":"from-base"},
 "same-file-include":{"expected":"from-base","expr":"from-base"}}

Cross-file aspect includes resolve correctly — den.aspects.consumer-cross.includes = [ den.aspects.base-cross ] delivers content from a differently-located file with no issue.

The negative control (why the original report looked plausible)

git rm --cached repro/split-base.nix (file present on disk, untracked in git):

error: getting status of '/nix/store/...-source/repro/split-base.nix': No such file or directory

With explicit imports this fails loudly. With import-tree it fails silently — the file is just absent from the module set, aspects referencing it evaluate empty, and the user only sees a downstream error (in our case the stateVersion one). That silent mode is what fooled me into filing this.

Apologies for the noise — thanks for the quick and accurate call. Happy to send the template-based repro above as a templates/bogus PR if it's useful as a regression cell for the "untracked file is silently invisible to import-tree" failure mode (possibly worth a diagnostics warning, e.g. import-tree detecting on-disk-but-untracked files when the flake source is a git tree).

philipp-baumann avatar Sep 28 '26 03:09 philipp-baumann

Glad you have a root cause. I'm not an anti-AI maintainer -- but others are. I would advise you invest some more diligence and verify you understand faults yourself before letting your agent represent itself as you and file reports. It's one thing when your agent uncovers a real edge case, and quite another when it files false reports. AI in this community is already facing an uphill battle for acceptance, please don't make it harder. :)

sini avatar Sep 28 '26 03:09 sini

Thanks for the feedback, I will next time try to fully apply and follow the bug reporting procedure :) Really love denful, it really brings nix configurations to the next level. :)

philipp-baumann avatar Sep 28 '26 04:09 philipp-baumann