"Infinite recursion encountered" by making module configurable

I’ve been changing my NixOS config to parameterize my config modules using options declarations. This has been working fine, except for my XServer config. The below is a minimal version of the offending module:

{ config, pkgs, lib, ... }:

with lib;
{
  options.os.xorg = {
    enable = pkgs.lib.mkOption {
      default = false;
      type = types.bool;
    };
  };

  config = mkIf config.os.xorg.enable {
    services.xserver = {
      enable = true;

      displayManager.lightdm = {
        enable = true;
        greeters.enso = {
          enable = true;
          blur = true;
        };
      };

      displayManager.defaultSession = "xsession";
      displayManager.session = [
        {
          manage = "desktop";
          name = "xsession";
          start = ''exec $HOME/.xsession'';
        }
      ];
    };
  };
}

When I include that module from my NixOS config, and set os.xorg.enable = true; from another module, I get the following error when I sudo nixos-rebuild test --flake '.':

error: infinite recursion encountered

       at /nix/store/kmy3yfc596gvfm5lkxzbq37kxizdj78r-source/lib/types.nix:461:58:

          460|         # Push down position info.
          461|         (map (def: mapAttrs (n: v: { inherit (def) file; value = v; }) def.value) defs);
             |                                                          ^
          462|       emptyValue = { value = {}; };

--show-trace does not seem to produce any useful results; I can attach those if wanted.

If I comment out enable = true and the LightDM config block, it seems to move forwards. Similarly, if I comment out the options block, the config = mkIf ... line, and the corresponding ending curly brace, it works fine.

Expected outcome

I’d expect to be able to parameterize this module, like I’ve done with others.

Other information

  • NixOS 22.05
  • Nix v2.8.1
1 Like