Hello,
I’m writing a helper home manager module using a flake.
Here is minimal code that shows the issue:
# flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs = {...}: {
homeManagerModule = import ./module.nix;
};
}
# module.nix
{ lib, config, ... }: {
imports = [
./example-module.nix
];
options.myModule.enable = lib.mkEnableOption "myModule";
config.lib.myLib = {
mkModule = cfg: lib.mkIf config.myModule.enable cfg;
};
}
# example-module.nix
{config, ...}:
config.lib.myLib.mkModule {
config.programs.alacritty.enable = true;
}
In this module, I expect to write lots of sub-modules with the pattern
lib.mkIf config.myModule.enable {...}
So I isolated it into a function. But, when calling mkModule
, I’m getting infinite recursion errors with config
:
error:
… while evaluating a branch condition
at /nix/store/rhn4fkh7hqjlqs9j6naaq623qpl62yz0-source/lib/lists.nix:125:9:
124| fold' = n:
125| if n == len
| ^
126| then nul
… while calling the 'length' builtin
at /nix/store/rhn4fkh7hqjlqs9j6naaq623qpl62yz0-source/lib/lists.nix:123:13:
122| let
123| len = length list;
| ^
124| fold' = n:
… while evaluating the module argument `config' in "/nix/store/nks2pia0n6s2kxwssfm4ildp4yirpc57-source/example-module.nix":
(stack trace truncated; use '--show-trace' to show the full, detailed trace)
error: infinite recursion encountered
at /nix/store/rhn4fkh7hqjlqs9j6naaq623qpl62yz0-source/lib/modules.nix:245:34:
244| (regularModules ++ [ internalModule ])
245| ({ inherit lib options config specialArgs; } // specialArgs);
| ^
246| in mergeModules prefix (reverseList collected);
How can I solve this? On a related note, is this how I would make global helper functions?
Thanks in advance