{ config, pkgs, ... }:

{
  programs.sway = {
    enable = true;
    # Execute sway with required environment variables for GTK apps.
    wrapperFeatures.gtk = true;
  };

  environment.systemPackages = with pkgs; [
    # CLI tools
    brightnessctl
    wl-clipboard # for wl-copy and wl-paste

    # graphical tools
    imv
    mpv

    # set and forget
    i3status-rust
  ];

  # This generates /etc/xdg/mimeapps.list. The XDG spec and xdg-open don't support wildcards in MIME types.
  # TODO: use an xdg-open alternative that supports wildcards in MIME types and doesn't use mimeapps.list
  xdg.mime.defaultApplications =
    let
      defaultBrowser = "firefox.desktop";
    in
    {
      "text/html" = defaultBrowser;

      "x-scheme-handler/http" = defaultBrowser;
      "x-scheme-handler/https" = defaultBrowser;
      "x-scheme-handler/mailto" = "thunderbird.desktop";
    };

  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
  };
  security.rtkit.enable = true; # recommended for PipeWire

  programs.thunderbird = {
    enable = true;
  };

  programs.firefox = {
    enable = true;

    policies = {
      DontCheckDefaultBrowser = true;
      DisablePocket = true;
      FirefoxHome = {
        SponsoredTopSites = false;
      };

      SearchSuggestEnabled = false;
      # cannot use SearchEngines because it's only available on ESR :(
      # (https://mozilla.github.io/policy-templates/#searchengines-this-policy-is-only-available-on-the-esr)

      ExtensionSettings = {
        "uBlock0@raymondhill.net" = {
          install_url = "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi";
          installation_mode = "force_installed";
        };
      };

      PasswordManagerEnabled = false;
      ExtensionSettings."{446900e4-71c2-419f-a6a7-df9c091e268b}" = {
        install_url = "https://addons.mozilla.org/firefox/downloads/latest/bitwarden-password-manager/latest.xpi";
        installation_mode = "force_installed";
      };
    };
  };
}