den icon indicating copy to clipboard operation
den copied to clipboard

BUG: Dynamic home/host forwarding no longer work

Open musjj opened this issue 6 months ago • 8 comments

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.

musjj avatar May 29 '26 23:05 musjj

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.

sini avatar May 29 '26 23:05 sini

I'll fix the shim, have you verify it, and then provide you the dropin policy to replace it. :)

sini avatar May 29 '26 23:05 sini

Can you tell me if the branch from 578 resolves this for you?

sini avatar May 30 '26 18:05 sini

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

musjj avatar May 30 '26 19:05 musjj

Ah, it's because I'm passing you ["class", "host", "system"] and it's checking == [ "host" ] -- will update internally to compute the intersection.

sini avatar May 30 '26 20:05 sini

That should work.

sini avatar May 30 '26 21:05 sini

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.

musjj avatar May 30 '26 23:05 musjj

I'll let the merge close it.

sini avatar May 31 '26 01:05 sini