{ 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;

  boot.tmpOnTmpfs = true;

  environment = mkIf enable-gui {
    systemPackages = [
      #libva
    ];
  };

  system = {
    autoUpgrade.enable = true;
  };

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

      desktopManager.gnome3.enable = true;

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

      windowManager.stumpwm.enable = true;

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

    emacs = {
      enable = true;
      install = true;
      package = pkgs.emacs;
      defaultEditor = true;
    };

    trezord.enable = true;
  };

  hardware = {
    bluetooth.enable = true;

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

  sound.enable = true;
  hardware.pulseaudio.enable = true;

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

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

  fonts = mkIf enable-gui {
    enableFontDir = 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
      vistafonts
      xlibs.fontadobe100dpi
      xlibs.fontadobe75dpi
      xlibs.fontadobeutopia100dpi
      xlibs.fontadobeutopia75dpi
      xlibs.fontadobeutopiatype1
      xlibs.fontarabicmisc
      xlibs.fontbh100dpi
      xlibs.fontbh75dpi
      xlibs.fontbhlucidatypewriter100dpi
      xlibs.fontbhlucidatypewriter75dpi
      xlibs.fontbhttf
      xlibs.fontbhtype1
      xlibs.fontbitstream100dpi
      xlibs.fontbitstream75dpi
      xlibs.fontbitstreamtype1
      xlibs.fontcronyxcyrillic
      xlibs.fontcursormisc
      xlibs.fontdaewoomisc
      xlibs.fontdecmisc
      xlibs.fontibmtype1
      xlibs.fontisasmisc
      xlibs.fontjismisc
      xlibs.fontmicromisc
      xlibs.fontmisccyrillic
      xlibs.fontmiscethiopic
      xlibs.fontmiscmeltho
      xlibs.fontmiscmisc
      xlibs.fontmuttmisc
      xlibs.fontschumachermisc
      xlibs.fontscreencyrillic
      xlibs.fontsonymisc
      xlibs.fontsunmisc
      xlibs.fontwinitzkicyrillic
      xlibs.fontxfree86type1
    ];
  };
}