{ config, pkgs, ... }:

{
  imports = [
    ./pipewire.nix
  ];

  i18n.inputMethod = {
    enabled = "fcitx";
    fcitx.engines = with pkgs.fcitx-engines; [ mozc anthy table-other m17n ];
  };

  fonts = {
    enableDefaultFonts = false;
    fontconfig = {
      allowBitmaps = false;
    };
    fonts = with pkgs; [
      # xorg.fontbhlucidatypewriter100dpi
      # xorg.fontbhlucidatypewriter75dpi
      freefont_ttf
      gyre-fonts # TrueType substitutes for standard PostScript fonts
      # xorg.fontbh100dpi
      xorg.fontmiscmisc
      xorg.fontcursormisc
      unifont

      noto-fonts-emoji
      noto-fonts-cjk

      cantarell_fonts # from gnome3 module

      merriweather
      merriweather-sans
      open-sans
      # libertine # breaks 

      dejavu_fonts
      liberation_ttf
      ubuntu_font_family

      wqy_microhei
      ipafont
      ipaexfont
      source-han-serif
      source-han-sans

      inconsolata
      iosevka
      fira fira-mono fira-code
      source-code-pro

      font-awesome_5
    ];
  };

  environment.systemPackages = with pkgs; [
    (writeScriptBin "gsd-xsettings"
      ''
        #!/bin/sh
        exec ${gnome3.gnome-settings-daemon}/libexec/gsd-xsettings "$@"
      '')

    libinput
    libnotify
  ];

  # prevent satanic torture
  programs.qt5ct.enable = true;

  hardware.uinput.enable = true;
  users.extraUsers.gebner.extraGroups = [ "input" "tty" "audio" "video" "uinput" ];

  services.dbus.packages = with pkgs; [ gnome3.gcr ];
  services.udev.packages = [ pkgs.gnome3.gnome-settings-daemon ];

  # copied from gnome3 module
  security.polkit.enable = true;
  services.udisks2.enable = true;
  services.accounts-daemon.enable = true;
  services.geoclue2.enable = true;
  services.gnome3.at-spi2-core.enable = true;
  services.gnome3.gnome-keyring.enable = true;
  services.gvfs.enable = true;
  programs.seahorse.enable = true;
  services.gnome3.sushi.enable = true;
  services.gnome3.gnome-settings-daemon.enable = true;
  services.telepathy.enable = true;
  networking.networkmanager.enable = true;
  services.upower.enable = config.powerManagement.enable;
  programs.dconf.enable = true;
  services.flatpak.enable = true;
  xdg.portal = {
    enable = true;
    extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
  };
  # Needed for themes and backgrounds
  environment.pathsToLink = [ "/share" ];
  environment.variables.GIO_EXTRA_MODULES = with pkgs.gnome3; [
    "${pkgs.lib.getLib dconf}/lib/gio/modules"
    "${glib_networking.out}/lib/gio/modules"
    "${gvfs}/lib/gio/modules" ];

  hardware.bluetooth = {
    enable = true;
    package = pkgs.bluezFull;
  };
  services.blueman.enable = true;

  programs.gnupg = {
    agent.enable = true;
    agent.pinentryFlavor = "gnome3";
  };

  # https://github.com/NixOS/nixpkgs/pull/54083
  environment.extraSetup = ''
    if [ -d  $out/share/gsettings-schemas/ ]; then
      # Create the standard schemas directory
      mkdir -p $out/share/glib-2.0/schemas
      # symlink any schema files to the standard schema directory
      for d in $out/share/gsettings-schemas/*; do
        # Force symlink, in case there are duplicates
        ln -fs $d/glib-2.0/schemas/*.xml $out/share/glib-2.0/schemas
      done
      # and compile them
      if [ -w $out/share/glib-2.0/schemas ]; then
        ${pkgs.glib.dev}/bin/glib-compile-schemas $out/share/glib-2.0/schemas
      fi
    fi
  '';

}