BUG: provides.packages leaks aspect fields into flake packages after #678
After #678, including an aspect with provides.packages exports the child aspect's fields into flake.packages. The child is not package output content.
This passes on d50f0fce and fails on its immediate successor, 85b4e520 (#678). It also fails on 20d1e76d, with Nixpkgs unchanged.
Reproduction
Save as repro.nix:
Standalone Nix expression
{ denRev ? "20d1e76dfa805cec5e477234fbca21ac9c8522f4" }:
let
denPath = (builtins.getFlake ("github:denful/den/" + denRev)).outPath;
nixpkgsPath = (builtins.getFlake "github:NixOS/nixpkgs/d6524aaca2ff07876657ae2b323f24be4874944b").outPath;
lib = import (nixpkgsPath + "/lib");
inputs.den = import (denPath + "/nix");
inputs.nixpkgs = { legacyPackages.x86_64-linux = import nixpkgsPath { system = "x86_64-linux"; }; };
evaluated = lib.evalModules {
specialArgs = { inherit inputs; };
modules = [
inputs.den.flakeModule
inputs.den.flakeOutputs.packages
({ config, den, ... }: let __findFile = den.lib.__findFile; in {
den.hosts.x86_64-linux.probe = {};
den.aspects.probe.includes = [ <group/tools> ];
den.aspects.group.provides.tools = {
includes = [ <group/tools/packages> ];
provides.packages = {
homeManager = { pkgs, ... }: { home.packages = []; };
darwin.homebrew.casks = [ "example-app" ];
};
};
})
];
};
den = evaluated.config.den;
original = den.lib.__findFile [] "group/tools";
remerged = den.lib.aspects.types.providerType.merge [ "probe" ] [{ file = "probe"; value = original; }];
in {
functionArgs = lib.functionArgs original;
isSubmoduleFunction = den.lib.aspects.isSubmoduleFn original;
exportedNames = builtins.attrNames (evaluated.config.flake.packages.x86_64-linux or {});
originalForwarded = original.__providesForwarded or [];
remergedForwarded = remerged.__providesForwarded or [];
originalClasses = den.lib.aspects.fx.keyClassification.classifyKeys "packages" original;
remergedClasses = den.lib.aspects.fx.keyClassification.classifyKeys "packages" remerged;
}
# Passes: true, exit 0
nix eval --accept-flake-config --impure --json \
--expr 'import ./repro.nix { denRev = "d50f0fce6fc1a8ba00fd0d310746d0e8ecc2f70d"; }' \
--apply 'r: assert r.exportedNames == []; assert r.remergedForwarded == r.originalForwarded; true'
# Fails: assertion error, exit 1
nix eval --accept-flake-config --impure --json \
--expr 'import ./repro.nix { denRev = "85b4e520e65a729685f69978fa758e15536ede15"; }' \
--apply 'r: assert r.exportedNames == []; assert r.remergedForwarded == r.originalForwarded; true'
Expected: no package outputs. Actual: 14 fields, including name, includes, homeManager, and darwin. With a derivation-typed package schema, these cause evaluation errors.
Where it breaks
Before providerType.merge, the aspect has __providesForwarded = [ "packages" ]. Afterwards, it has [], and the classifier treats packages as class content.
In mergeFunctions:
unshadowedProvides = builtins.filter (k: !(normalizedFn ? ${k})) (builtins.attrNames forwardable);
normalizedFn.packages already exists because Den forwarded it during the first merge. This check mistakes the alias for a direct definition and clears its forwarding marker.
Ironically this is probably actually a fix rather than a regression, as flake 'packages' is a reserved class term. I'll look a bit more closely at your report and try and figure out if we should disable packages as a by-default class export.
I'll land a fix for you shortly. :)
Feel free to re-open if you're still experiencing issues.