{ pkgs, lib, ... }:

{
  imports = [
    ../comfy
    ./bashrc.d
    ./lxterminal
    ./ghostty
    ./pulsar
    ./zed
    ./mime.nix
    ./mpv.nix
    ./salert.nix
    ./sshuttle.nix
  ];

  # TODO: doesn't work?
  nixpkgs.config.permittedUnfreePackages = [
    pkgs.discord.name
    pkgs.telegram-desktop.name
    pkgs.spotify.name
  ];

  nixpkgs.config.permittedInsecurePackages = [
    pkgs.pulsar.name
    pkgs.zotero.name
  ];

  # TODO: add remote-exec once packaged
  programs.bash.initExtra = ''
    # remote-exec
    if command -v remote >/dev/null && command -v remote-quick >/dev/null; then
      complete -F _command remote
      complete -F _command remote-quick
    fi
  '';

  home.packages = with pkgs; [
    wl-clipboard-timeout

    audacity

    discord
    element-desktop
    unstable.signal-desktop
    #element-desktop-wayland
    /* fractal */
    /* neochat */
    /* nheko */
    /* fluffychat */

    (pkgs.onlyoffice-desktopeditors or pkgs.unstable.onlyoffice-desktopeditors or pkgs.libreoffice)

    emote
    normcap
    gcolor3
    icon-library

    gitg
    imhex
    xdot

    remote-exec

    (pkgs.zxtune or unstable.zxtune or null)

    vlc

    f3d
    # firefox # we assume the host has this
    zotero
    (pkgs.loupe or pkgs.gnome.eog)
    papers
    evince
    # shotwell # image editor

    gnome-connections
    scrcpy
    #spotify # use flathub version instead
    transgui #transmission-remote-gtk
  ]
  ++ builtins.filter (drv: (builtins.tryEval drv.outPath).success) [
    slack
    telegram-desktop
    teams
    zoom-us
  ];

  # programs.firefox.enable = true; # likely also very invasive, we assume the host has firefox
  home.sessionVariables.MOZ_ENABLE_WAYLAND = "1";
  home.sessionVariables.MOZ_USE_XINPUT2 = "1"; # smooth scrolling

  home.shellAliases.eog = lib.mkIf (pkgs?loupe) "loupe";

  # flatpak
  # TODO: this requires a logout+login to take effect
  home.activation.addFlathubRemote = lib.hm.dag.entryAfter ["writeBoundary"] ''
    if command -v flatpak >/dev/null; then
      $DRY_RUN_CMD flatpak remote-add --if-not-exists --user flathub https://dl.flathub.org/repo/flathub.flatpakrepo
    fi
  '';
  # TODO: automatic flatpak updates

  # TODO: fix collision
  ## Do not keep me from using the app just to force an update
  #xdg.configFile."discord/settings.json".text = builtins.toJSON {
  #  SKIP_HOST_UPDATE = true;
  #};

}
