hercules-ci / flake-parts

❄️ Simplify Nix Flakes with the module system
https://flake.parts
MIT License
729 stars 41 forks source link

Attempt to import home-manager module produces recursion. #112

Closed Qualadia closed 1 year ago

Qualadia commented 1 year ago

Trying to import home-manager module for installation of nix-doom-emacs (imports = [ nix-doom-emacs.hmModule ];).

error: infinite recursion encountered

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:483:28:

          482|         builtins.addErrorContext (context name)
          483|           (args.${name} or config._module.args.${name})
             |                            ^
          484|       ) (lib.functionArgs f);
(use '--show-trace' to show detailed location information)
roberth commented 1 year ago

Where did you write the imports = attribute?

Qualadia commented 1 year ago

in module of a home-manager

roberth commented 1 year ago

I can't really tell what's going on without reading more of the sources. Did you try with --show-trace?

Qualadia commented 1 year ago
error: infinite recursion encountered

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:483:28:

          482|         builtins.addErrorContext (context name)
          483|           (args.${name} or config._module.args.${name})
             |                            ^
          484|       ) (lib.functionArgs f);

       … while evaluating the module argument `nix-doom-emacs' in "/nix/store/dz6f7k64a0zwqcl4cr9vwrnkw4nrx690-source/home/editors/emacs":

       … while calling anonymous lambda

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:481:44:

          480|       context = name: ''while evaluating the module argument `${name}' in "${key}":'';
          481|       extraArgs = builtins.mapAttrs (name: _:
             |                                            ^
          482|         builtins.addErrorContext (context name)

       … from call site

       … while calling 'isFunction'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/trivial.nix:448:16:

          447|   */
          448|   isFunction = f: builtins.isFunction f ||
             |                ^
          449|     (f ? __functor && isFunction (f.__functor f));

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:360:12:

          359|       loadModule = args: fallbackFile: fallbackKey: m:
          360|         if isFunction m || isAttrs m then
             |            ^
          361|           unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgsIfFunction fallbackKey m args)

       … while calling 'loadModule'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:359:53:

          358|       # Like unifyModuleSyntax, but also imports paths and calls functions if necessary
          359|       loadModule = args: fallbackFile: fallbackKey: m:
             |                                                     ^
          360|         if isFunction m || isAttrs m then

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:400:22:

          399|           let
          400|             module = loadModule args parentFile "${parentKey}:anon-${toString n}" x;
             |                      ^
          401|             collectedImports = collectStructuredModules module._file module.key module.imports args;

       … while evaluating the attribute 'disabled'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:395:13:

          394|           collectResults = modules: {
          395|             disabled = concatLists (catAttrs "disabled" modules);
             |             ^
          396|             inherit modules;

       … while evaluating the attribute 'disabled'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:395:13:

          394|           collectResults = modules: {
          395|             disabled = concatLists (catAttrs "disabled" modules);
             |             ^
          396|             inherit modules;

       … while evaluating the attribute 'disabled'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:395:13:

          394|           collectResults = modules: {
          395|             disabled = concatLists (catAttrs "disabled" modules);
             |             ^
          396|             inherit modules;

       … while evaluating the attribute 'disabled'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:395:13:

          394|           collectResults = modules: {
          395|             disabled = concatLists (catAttrs "disabled" modules);
             |             ^
          396|             inherit modules;

       … while calling anonymous lambda

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:419:31:

          418|           disabledKeys = map moduleKey disabled;
          419|           keyFilter = filter (attrs: ! elem attrs.key disabledKeys);
             |                               ^
          420|         in map (attrs: attrs.module) (builtins.genericClosure {

       … from call site

       … while calling 'filterModules'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:413:36:

          412|       # modules recursively. It returns the final list of unique-by-key modules
          413|       filterModules = modulesPath: { disabled, modules }:
             |                                    ^
          414|         let

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:426:7:

          425|     in modulesPath: initialModules: args:
          426|       filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args);
             |       ^
          427|

       … while calling anonymous lambda

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:425:37:

          424|
          425|     in modulesPath: initialModules: args:
             |                                     ^
          426|       filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args);

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:258:25:

          257|       merged =
          258|         let collected = collectModules
             |                         ^
          259|           (specialArgs.modulesPath or "")

       … while calling 'reverseList'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/lists.nix:394:17:

          393|   */
          394|   reverseList = xs:
             |                 ^
          395|     let l = length xs; in genList (n: elemAt xs (l - n - 1)) l;

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:262:33:

          261|           ({ inherit lib options config specialArgs; } // specialArgs);
          262|         in mergeModules prefix (reverseList collected);
             |                                 ^
          263|

       … while calling 'byName'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:542:25:

          541|       */
          542|       byName = attr: f: modules:
             |                         ^
          543|         zipAttrsWith (n: concatLists)

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:559:21:

          558|       # an attrset 'name' => list of submodules that declare ‘name’.
          559|       declsByName = byName "options" (module: option:
             |                     ^
          560|           [{ inherit (module) _file; options = option; }]

       … while evaluating the attribute 'matchedOptions'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:637:14:

          636|     in {
          637|       inherit matchedOptions;
             |              ^
          638|

       … while calling 'mapAttrsRecursiveCond'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/attrsets.nix:530:5:

          529|     # Attribute set to recursively map over.
          530|     set:
             |     ^
          531|     let

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:270:28:

          269|           # For definitions that have an associated option
          270|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
             |                            ^
          271|

       … while evaluating the attribute 'config'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:346:9:

          345|         options = checked options;
          346|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          347|         _module = checked (config._module);

       … while calling 'merge'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/types.nix:742:22:

          741|         check = x: isAttrs x || isFunction x || path.check x;
          742|         merge = loc: defs:
             |                      ^
          743|           (base.extendModules {

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:765:59:

          764|       if isDefined then
          765|         if all (def: type.check def.value) defsFinal then type.merge loc defsFinal
             |                                                           ^
          766|         else let allInvalid = filter (def: ! type.check def.value) defsFinal;

       … while evaluating the attribute 'value'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:776:27:

          775|     optionalValue =
          776|       if isDefined then { value = mergedValue; }
             |                           ^
          777|       else {};

       … while calling anonymous lambda

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/types.nix:522:22:

          521|       merge = loc: defs:
          522|         mapAttrs (n: v: v.value) (filterAttrs (n: v: v ? value) (zipAttrsWith (name: defs:
             |                      ^
          523|             (mergeDefinitions (loc ++ [name]) elemType defs).optionalValue

       … from call site

       … while calling 'flip'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/trivial.nix:138:16:

          137|   */
          138|   flip = f: a: b: f b a;
             |                ^
          139|

       … from call site

       at /nix/store/w4wfpywda12f01mnjq4z66dnxidcl3y2-source/nixos/common.nix:104:7:

          103|     assertions = flatten (flip mapAttrsToList cfg.users (user: config:
          104|       flip map config.assertions (assertion: {
             |       ^
          105|         inherit (assertion) assertion;

       … while calling anonymous lambda

       at /nix/store/w4wfpywda12f01mnjq4z66dnxidcl3y2-source/nixos/common.nix:103:64:

          102|
          103|     assertions = flatten (flip mapAttrsToList cfg.users (user: config:
             |                                                                ^
          104|       flip map config.assertions (assertion: {

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/attrsets.nix:479:16:

          478|     attrs:
          479|     map (name: f name attrs.${name}) (attrNames attrs);
             |                ^
          480|

       … while calling anonymous lambda

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/attrsets.nix:479:10:

          478|     attrs:
          479|     map (name: f name attrs.${name}) (attrNames attrs);
             |          ^
          480|

       … from call site

       … while calling 'flatten'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/lists.nix:138:13:

          137|   */
          138|   flatten = x:
             |             ^
          139|     if isList x

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/lists.nix:140:24:

          139|     if isList x
          140|     then concatMap (y: flatten y) x
             |                        ^
          141|     else [x];

       … while calling anonymous lambda

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/lists.nix:140:21:

          139|     if isList x
          140|     then concatMap (y: flatten y) x
             |                     ^
          141|     else [x];

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/lists.nix:140:10:

          139|     if isList x
          140|     then concatMap (y: flatten y) x
             |          ^
          141|     else [x];

       … while calling 'flatten'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/lists.nix:138:13:

          137|   */
          138|   flatten = x:
             |             ^
          139|     if isList x

       … from call site

       at /nix/store/w4wfpywda12f01mnjq4z66dnxidcl3y2-source/nixos/common.nix:103:18:

          102|
          103|     assertions = flatten (flip mapAttrsToList cfg.users (user: config:
             |                  ^
          104|       flip map config.assertions (assertion: {

       … while evaluating the attribute 'content'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:886:14:

          885|     { _type = "if";
          886|       inherit condition content;
             |              ^
          887|     };

       … while calling 'dischargeProperties'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:815:25:

          814|   */
          815|   dischargeProperties = def:
             |                         ^
          816|     if def._type or "" == "merge" then

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:821:11:

          820|         if def.condition then
          821|           dischargeProperties def.content
             |           ^
          822|         else

       … while calling 'dischargeProperties'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:815:25:

          814|   */
          815|   dischargeProperties = def:
             |                         ^
          816|     if def._type or "" == "merge" then

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:744:137:

          743|         defs' = concatMap (m:
          744|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
             |                                                                                                                                         ^
          745|         ) defs;

       … while evaluating definitions from `/nix/store/w4wfpywda12f01mnjq4z66dnxidcl3y2-source/nixos/common.nix':

       … while calling anonymous lambda

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:743:28:

          742|         # Process mkMerge and mkIf properties.
          743|         defs' = concatMap (m:
             |                            ^
          744|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:743:17:

          742|         # Process mkMerge and mkIf properties.
          743|         defs' = concatMap (m:
             |                 ^
          744|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

       … while evaluating the attribute 'values'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:856:7:

          855|     in {
          856|       values = concatMap (def: if getPrio def == highestPrio then [(strip def)] else []) defs;
             |       ^
          857|       inherit highestPrio;

       … while evaluating the attribute 'values'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:757:9:

          756|       in {
          757|         values = defs''';
             |         ^
          758|         inherit (defs'') highestPrio;

       … while evaluating the attribute 'mergedValue'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:763:5:

          762|     # Type-check the remaining definitions, and merge them. Or throw if no definitions.
          763|     mergedValue =
             |     ^
          764|       if isDefined then

       … while evaluating the option `assertions':

       … while evaluating the attribute 'value'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:728:9:

          727|     in warnDeprecation opt //
          728|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          729|         inherit (res.defsFinal') highestPrio;

       … while calling anonymous lambda

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:270:72:

          269|           # For definitions that have an associated option
          270|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
             |                                                                        ^
          271|

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/attrsets.nix:538:20:

          537|               then recurse (path ++ [name]) value
          538|               else f (path ++ [name]) value;
             |                    ^
          539|         in mapAttrs g;

       … while calling 'g'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/attrsets.nix:535:19:

          534|           g =
          535|             name: value:
             |                   ^
          536|             if isAttrs value && cond value

       … from call site

       … while calling 'fold''

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/lists.nix:56:15:

           55|       len = length list;
           56|       fold' = n:
             |               ^
           57|         if n == len

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/lists.nix:60:8:

           59|         else op (elemAt list n) (fold' (n + 1));
           60|     in fold' 0;
             |        ^
           61|

       … while calling 'foldr'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/lists.nix:53:20:

           52|   */
           53|   foldr = op: nul: list:
             |                    ^
           54|     let

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/nixos/modules/system/activation/top-level.nix:129:12:

          128|   # Replace runtime dependencies
          129|   system = foldr ({ oldDependency, newDependency }: drv:
             |            ^
          130|       pkgs.replaceDependency { inherit oldDependency newDependency drv; }

       … while evaluating the attribute 'value'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:568:44:

          567|       defnsByName' = byName "config" (module: value:
          568|           [{ inherit (module) file; inherit value; }]
             |                                            ^
          569|         ) configs;

       … while calling 'dischargeProperties'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:815:25:

          814|   */
          815|   dischargeProperties = def:
             |                         ^
          816|     if def._type or "" == "merge" then

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:744:137:

          743|         defs' = concatMap (m:
          744|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
             |                                                                                                                                         ^
          745|         ) defs;

       … while evaluating definitions from `/nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/nixos/modules/system/activation/top-level.nix':

       … while calling anonymous lambda

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:743:28:

          742|         # Process mkMerge and mkIf properties.
          743|         defs' = concatMap (m:
             |                            ^
          744|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:743:17:

          742|         # Process mkMerge and mkIf properties.
          743|         defs' = concatMap (m:
             |                 ^
          744|           map (value: { inherit (m) file; inherit value; }) (builtins.addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))

       … while evaluating the attribute 'values'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:856:7:

          855|     in {
          856|       values = concatMap (def: if getPrio def == highestPrio then [(strip def)] else []) defs;
             |       ^
          857|       inherit highestPrio;

       … while evaluating the attribute 'values'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:757:9:

          756|       in {
          757|         values = defs''';
             |         ^
          758|         inherit (defs'') highestPrio;

       … while evaluating the attribute 'mergedValue'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:763:5:

          762|     # Type-check the remaining definitions, and merge them. Or throw if no definitions.
          763|     mergedValue =
             |     ^
          764|       if isDefined then

       … while evaluating the option `system.build.toplevel':

       … while evaluating the attribute 'value'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:728:9:

          727|     in warnDeprecation opt //
          728|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          729|         inherit (res.defsFinal') highestPrio;

       … while calling anonymous lambda

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/modules.nix:270:72:

          269|           # For definitions that have an associated option
          270|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
             |                                                                        ^
          271|

       … from call site

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/attrsets.nix:538:20:

          537|               then recurse (path ++ [name]) value
          538|               else f (path ++ [name]) value;
             |                    ^
          539|         in mapAttrs g;

       … while calling 'g'

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/attrsets.nix:535:19:

          534|           g =
          535|             name: value:
             |                   ^
          536|             if isAttrs value && cond value

       … from call site

       … while calling anonymous lambda

       at /nix/store/714kd9iay1f89hspfp62f6xhch67n733-source/lib/attrsets.nix:716:24:

          715|     let f = attrPath:
          716|       zipAttrsWith (n: values:
             |                        ^
          717|         let here = attrPath ++ [n]; in

       … from call site

here's full log

roberth commented 1 year ago

It looks like you need to add nix-doom-emacs to specialArgs in nixpkgs.lib.nixosSystem. Flake-parts doesn't seem to be involved in the recursion.

Qualadia commented 1 year ago

You're right. I needed to put this into the home-manager modules. The code was quite messy after refactor for transition to flake-parts. Issue solved. Thanks