Skip to content

Common Errors ​

This section lists some common errors and their possible solutions.

Conditional Imports ​

If for some reason you need to perform an import inside the Denix module, then attempting to set [nixos|home|darwin].[ifEnabled|ifDisabled].imports will cause an infinite recursion error.

This means that if you need to import, for example, a third-party library, you should first add it to [nixos|home|darwin].always.imports, and then, if necessary, set option values in [nixos|home|darwin].[always|ifEnabled|ifDisabled].

Discussion on "Conditional module imports": discourse.nixos.org

Incorrect Code ​

nix
{delib, ...}:
delib.module {
  name = "wrong";
  options = delib.singleEnableOption true;

  nixos.ifEnabled = {
    imports = [<someModule>];

    someModuleOptions.enable = true;
  };
}

Correct Code ​

nix
{delib, ...}:
delib.module {
  name = "correct";
  options = delib.singleEnableOption true;

  nixos.always.imports = [<someModule>];

  nixos.ifEnabled.someModuleOptions.enable = true;
}