Unable to find infinite recursion

Hello everyone,

I am trying to make my config more modular with nixos and home-manager
modules. but i got an infinate recursion on the config variable.
Its in the modules/home-manager/style/desktop.nix and the trace is as folows

       … while calling the 'pathExists' builtin
         at /nix/store/s2whbxg6alsh3g1ah412rijidmihpg7p-source/modules/home-manager/style/desktop.nix:14:9:
           13|   themeImage =
           14|     if (builtins.pathExists imagePath)
             |         ^
           15|     then imagePath

       … from call site
         at /nix/store/s2whbxg6alsh3g1ah412rijidmihpg7p-source/modules/home-manager/style/desktop.nix:10:14:
            9|
           10|   themeCfg = config.strixos.style.theme;
             |              ^
           11|   themeFile = themeCfg.themeDir + "/theme.toml";

       … while calling anonymous lambda
         at /nix/store/708n1gvb7yizlay48z15cx51ciicvv2a-source/lib/modules.nix:652:15:
          651|       extraArgs = mapAttrs (
          652|         name: _: addErrorContext (context name) (args.${name} or config._module.args.${name})
             |               ^
          653|       ) (functionArgs f);

       … while evaluating the module argument `config' in "/nix/store/s2whbxg6alsh3g1ah412rijidmihpg7p-source/modules/home-manager/style/desktop.nix":

       … while evaluating the attribute 'config'
         at /nix/store/708n1gvb7yizlay48z15cx51ciicvv2a-source/lib/modules.nix:257:21:
          256|                     options
          257|                     config
             |                     ^
          258|                     specialArgs

       error: infinite recursion encountered
       at /nix/store/708n1gvb7yizlay48z15cx51ciicvv2a-source/lib/modules.nix:257:21:
          256|                     options
          257|                     config
             |                     ^
          258|                     specialArgs

I dont understand why this happens.
I’d also like to import other modules like stylix in my module
but because stylix is branch specific i need something like

imports = [
    inputs."stylix-${config.strixos.branch}".homeManagerModule.stylix
];

but this also creates a recursion loop.
the repository where my config lives: github - nix-config

1 Like

imports cannot depend on config.
You could create a separate module arg via specialArgs argument to lib.nixosSystem.

Or add the module you want to use in the modules arg of the nixosSystem of all hosts instead of using a custom option + imports for this.

Conditional module imports always strike me as a bad idea, you can’t rely on all versions having compatible options. I’d take a step back and think about if this is necessary, too.

the idea is that i want support for stable and unstable nixpkgs,
I will indeed leave it in the flake, but this still doesn’t explain
the infinite recursion

i found the the isue: lib.throwIf.
is there any way to throw an error if a variable is null?