{ config, lib, pkgs, ... }:
{
  environment.systemPackages = [
    #pkgs.tigervnc
    pkgs.turbovnc
    pkgs.x11vnc
    pkgs.xscreensaver
  ];

  security.polkit = {
    enable = true;
    extraConfig = ''
      polkit.addRule(function(action, subject) {
        if (
          subject.isInGroup("users")
            && (
              action.id == "org.freedesktop.login1.reboot" ||
              action.id == "org.freedesktop.login1.reboot-multiple-sessions" ||
              action.id == "org.freedesktop.login1.power-off" ||
              action.id == "org.freedesktop.login1.power-off-multiple-sessions"
            )
          )
        {
          return polkit.Result.YES;
        }
      })
    '';
  };

  services = {
    displayManager = lib.mkIf (config.networking.hostName != "fangorn") {
      defaultSession = "xsession";
    };
    picom.enable = true;
    xserver = {
      displayManager.lightdm = lib.mkMerge [
        (lib.mkIf (config.networking.hostName == "fangorn") {
          enable = true;
        })
        (lib.mkIf (config.networking.hostName != "fangorn") {
          enable = true;
          extraSeatDefaults = ''greeter-hide-users=true'';
        })
      ];
  
      displayManager.session = lib.mkIf (config.networking.hostName != "fangorn") [
        {
          manage = "desktop";
          name = "xsession";
          start = ''exec $HOME/.xsession'';
        }
      ];
  
      enable = true;
      xkb.layout = "us";
      xkb.options = "caps:super,compose:ralt";
    };
  };
}
