den icon indicating copy to clipboard operation
den copied to clipboard

gen submodule mismatch with extraSpecialArgs and nixpkgs modules

Open unazikx opened this issue 2 months ago • 4 comments

https://github.com/denful/den/commit/6c11a13d555347c7928ea18fab5ef73dae4c3840

how i tested recursion started from this commit, idk why but my repo https://github.com/unazikx/flake with this lock file

lock.txt

flake.txt

gives this output

error:
       … while calling the 'seq' builtin
         at «string»:35:3:
           34| in
           35|   builtins.seq scope builtins.trace motd scope
             |   ^
           36|

       … in the condition of the assert statement
         at «string»:26:5:
           25|   scope =
           26|     assert system._type or null == "configuration";
             |     ^
           27|     assert system.class or "nixos" == "nixos";

       … while evaluating the option `processedFlake':

       … while evaluating the option `flake':

       … while evaluating definitions from `/nix/store/s1s7q9n9547y9gm2yjdh6f1chql63ank-source/modules/outputs.nix':

       … while evaluating the option `den.classes':

       … while evaluating definitions from `/nix/store/s1s7q9n9547y9gm2yjdh6f1chql63ank-source/modules/aspect-schema.nix':

       … while evaluating the option `den.aspects':

       … while evaluating definitions from `/nix/store/s1s7q9n9547y9gm2yjdh6f1chql63ank-source/modules/aspects/definition.nix':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: infinite recursion encountered

unazikx avatar Sep 21 '26 12:09 unazikx

Confirmed, and it is a regression in den. Thanks for the lock and flake — I reproduced it end to end against your repo.

What broke

6c11a13d moved schema-kind evaluation from nixpkgs' module system onto gen-schema/gen-merge. nixpkgs hands every module function lib as a base argument; gen's module system deliberately ships no nixpkgs lib, so den compensated with

# modules/options.nix
config.den.schema.conf._module.args.lib = lib;

That is not the same channel. _module.args is fixpoint-derived, and gen-merge resolves it by folding over every module's config to find _module definitions. So a schema module that forces lib while producing its own top-level attrset asks for the fold, and the fold has to force that same module — infinite recursion.

The trigger in your tree is lib.mkIf in body position, with lib taken as a module argument:

# modules/custom/instantiate/nixos.nix
({ lib, config, host, ... }:
  lib.mkIf (config.class == "nixos") { aspect = zen.hosts.${host.hostName}; … })

Forcing the module to WHNF forces lib.mkIf, which forces lib, which forces the fold. A lib read in a lazy position (inside an option value) is fine and still works.

Affected files in your repo: modules/custom/instantiate/{nixos,finix,homeManager}.nix. user.nix is fine — it takes no lib.

Workaround

Take lib from the enclosing flake-parts module instead of from the inner schema module. flake-parts supplies it as a specialArg, so it is a plain closure capture with no fold involved:

{
  self,
  inputs,
  zen,
  lib,          # ← hoisted here
  ...
}:

{
  den.schema.host.imports = [
    (
      { config, host, ... }:   # ← `lib` dropped from the formals
      lib.mkIf (config.class == "nixos") {
        aspect = zen.hosts.${host.hostName};
        # … unchanged, including the `lib` used inside `instantiate`
      }
    )
  ];
}

Nothing else changes — the lib reads inside instantiate and _lib.nix keep working, because they were never the problem.

Verified on your repo with that edit applied to the three files, against den main:

$ nix eval .#nixosConfigurations --apply builtins.attrNames
[ "blackmamba" "desyowo" "jetpure" "phenix" "spaceship" ]

$ nix eval .#nixosConfigurations.blackmamba.config.system.build.toplevel.drvPath
"/nix/store/617sa1iw7z9cbd3sd7i5khgh7b56g6wm-nixos-system-blackmamba-blackmamba-26.11.20260911.eaad089.drv"

So it is not just the flake-output spine clearing — a host evaluates all the way to a derivation.

The actual fix

lib needs to reach gen-merge's base args rather than _module.args, which means a specialArgs channel through gen-schema's mkInstanceType down to gen-merge's submodule type. That lands in gen-merge first; den then passes { inherit lib; } and drops the _module.args.lib line. Tracking it here — this issue stays open until the pin bump lands, and the reduction is already written as a regression cell.

Worth noting for anyone else hitting this: the same shape with host, user or home in body position recursed before this commit too, and does on nixpkgs as well. Only lib is new.

sini avatar Sep 21 '26 17:09 sini

I'll have the real fix landed in a couple hours.

sini avatar Sep 21 '26 18:09 sini

I confirmed that #689 fixes the regression with your config; feel free to re-open if you identify any new defects.

sini avatar Sep 22 '26 02:09 sini

cool ye its works

unazikx avatar Sep 22 '26 06:09 unazikx