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

with lib;
let
  hostname = config.instance.hostname;
  enable-gui = config.fudo.hosts.${hostname}.enable-gui;

in {
  imports = [ ./common.nix ];

  boot = {
    plymouth.enable = false;
    tmpOnTmpfs = true;
  };

  services = {
    xserver = mkIf enable-gui {
      enable = true;

      desktopManager.gnome.enable = true;

      displayManager.gdm = {
        enable = true;
        wayland = false;
        autoSuspend = false;
      };

      windowManager.stumpwm.enable = true;

      # windowManager.session = pkgs.lib.singleton {
      #   name = "stumpwm";
      #   start = ''
      #     ${pkgs.lispPackages.stumpwm}/bin/stumpwm &
      #     waidPID=$!
      #   '';
      # };
    };

    trezord.enable = true;
  };

  hardware = {
    bluetooth.enable = true;

    opengl = mkIf enable-gui {
      enable = true;
      driSupport = true;
      driSupport32Bit = true;
    };
  };

  sound.enable = true;
  hardware.pulseaudio = {
    enable = true;
    support32Bit = config.hardware.pulseaudio.enable;
  };

  # console.font =
  #   lib.mkDefault "${pkgs.terminus_font}/share/consolefonts/ter-g18n.psf.gz";

  services.gnome = mkIf enable-gui {
    evolution-data-server.enable = mkForce false;
    gnome-user-share.enable = mkForce false;
  };

  services.flatpak.enable = enable-gui;

  fonts = mkIf enable-gui {
    fontDir.enable = true;
    fontconfig.enable = true;
    #fontconfig.antialias = true;
    #fontconfig.penultimate.enable = true;
    #fontconfig.subpixel.lcdfilter = "default";

    fonts = with pkgs; [
      cantarell_fonts
      dejavu_fonts
      dina-font
      dosemu_fonts
      fira-code
      fira-code-symbols
      freefont_ttf
      liberation_ttf
      mplus-outline-fonts
      nerdfonts
      noto-fonts
      noto-fonts-cjk
      noto-fonts-emoji
      proggyfonts
      terminus_font
      ubuntu_font_family
      ucsFonts
      ultimate-oldschool-pc-font-pack
      unifont
      xorg.fontadobe100dpi
      xorg.fontadobe75dpi
      xorg.fontadobeutopia100dpi
      xorg.fontadobeutopia75dpi
      xorg.fontadobeutopiatype1
      xorg.fontarabicmisc
      xorg.fontbh100dpi
      xorg.fontbh75dpi
      xorg.fontbhlucidatypewriter100dpi
      xorg.fontbhlucidatypewriter75dpi
      xorg.fontbhttf
      xorg.fontbhtype1
      xorg.fontbitstream100dpi
      xorg.fontbitstream75dpi
      xorg.fontbitstreamtype1
      xorg.fontcronyxcyrillic
      xorg.fontcursormisc
      xorg.fontdaewoomisc
      xorg.fontdecmisc
      xorg.fontibmtype1
      xorg.fontisasmisc
      xorg.fontjismisc
      xorg.fontmicromisc
      xorg.fontmisccyrillic
      xorg.fontmiscethiopic
      xorg.fontmiscmeltho
      xorg.fontmiscmisc
      xorg.fontmuttmisc
      xorg.fontschumachermisc
      xorg.fontscreencyrillic
      xorg.fontsonymisc
      xorg.fontsunmisc
      xorg.fontwinitzkicyrillic
      xorg.fontxfree86type1
    ];
  };
}