BUG: Dynamic home/host forwarding no longer work
Description
Failing test: https://github.com/musjj/nixpkgs-forward-bug/blob/main/modules/bug.nix Regression report: https://github.com/musjj/nixpkgs-forward-bug/actions/runs/26666119204
Dynamically forwarding to home/host attributes no longer work:
{ den, lib, ... }:
let
nixpkgsClass =
ctx:
lib.optionalAttrs
(lib.elem (lib.attrNames ctx) [
[ "home" ]
[ "host" ]
])
(
{ class, aspect-chain }:
den._.forward {
each = [ (ctx.home or ctx.host) ];
fromClass = _: "nixpkgs";
intoClass = { class, ... }: class;
intoPath = _: [ "nixpkgs" ];
fromAspect = _: lib.head aspect-chain;
adaptArgs = lib.id;
}
);
in
{
den.hosts.x86_64-linux.igloo.users.tux = { };
den.default.includes = [
den._.mutual-provider
nixpkgsClass
];
den.aspects.tux.provides.igloo = {
nixpkgs.overlays = [
(final: prev: {
cowsay = prev.cowsay.overrideAttrs (oldAttrs: {
passthru = oldAttrs.passthru or { } // {
hello = "world";
};
});
})
];
nixos =
{ pkgs, ... }:
{
users.users.tux.description = pkgs.cowsay.hello;
};
};
}
On v0.16.0, the overlay will be correctly applied, setting tux.description to "world".
On v0.17.0/latest, the overlay will be ignored resulting into an attribute 'hello' missing error on pkgs.cowsay.hello.
The idea behind this forwarder is to only forward either on a host or home level, but never on a host, user level. This is so that home-manager can consume the nixpkgs+overlay from the host using useGlobalPkgs, instead of evaluating nixpkgs twice.
If there are better ways to achieve this for v0.17.0, I'm open to alternatives.
Thank you. This should be achievable by the policy system that replaces forwards, but I'll attempt to fix the backwards compat shim for you.
I'll fix the shim, have you verify it, and then provide you the dropin policy to replace it. :)
Can you tell me if the branch from 578 resolves this for you?
Thank you for the PR. I've updated my test to use your fix, but it still fails unfortunately:
https://github.com/musjj/nixpkgs-forward-bug/actions/runs/26692561900
Ah, it's because I'm passing you ["class", "host", "system"] and it's checking == [ "host" ] -- will update internally to compute the intersection.
That should work.
Thank you! The test now passes: https://github.com/musjj/nixpkgs-forward-bug/actions/runs/26692561900
I still can't test it on my real config yet, because there's still one more (hopefully last) forwarding bug and this one is pretty weird. I'll open another issue for it.
I'll let the merge close it.