{ pkgs, lib, config, ... }:
let
  monitorModule = lib.types.submodule {
    options = {
      name = lib.mkOption {
        type = lib.types.str;
        description = "monitor name";
        example = "HDMI-1";
      };
      config = lib.mkOption {
        type = lib.types.attrs;
        description = "autorandr profile config";
      };
    };
  };
in {
  options.mods = {
    xorg.enable = lib.mkEnableOption "enables xorg";
    monitors = lib.mkOption {
      type = lib.types.attrsOf monitorModule;
      default = { };
    };
  };

  config = let
    startupTargets = [
      "systemd-user-sessions.service"
      "multi-user.target"
      "network-online.target"
    ];

  in lib.mkIf config.mods.xorg.enable {
    services.xserver.enable = true;
    services.xserver.xkb.layout = "us";
    services.xserver.xkb.options = "caps:escape";
    services.xserver.dpi = 96;

    # services.xserver.displayManager.gdm.enable = true;
    services.displayManager.sddm.enable = true;
    services.displayManager.sddm.enableHidpi = false;
    services.displayManager.autoLogin.enable = true;
    services.displayManager.autoLogin.user = config.mods.user.name;

    systemd.services.display-manager.wants = startupTargets;
    systemd.services.display-manager.after = startupTargets;
  };
}
