{ pkgs, ... }@all: with all;
{
  home.packages = with pkgs; [
    # cinny-desktop
    (weechat.override {
      configure = { availablePlugins, ... }: {
        scripts = with pkgs.weechatScripts; [
          weechat-matrix
        ];
      };
    })
  ];
  sops.secrets."weechat/passphrase" = { path = "%r/secrets/weechat/passphrase"; };

  home.file = {
    ".config/weechat/sec.conf".text = ''
      [crypt]
      cipher = aes256
      hash_algo = sha256
      passphrase_command = "cat $XDG_RUNTIME_DIR/secrets/weechat/passphrase"
      salt = on

      [data]
      __passphrase__ = on
      matrix_nx2site_password = "AD1FDBA557C3C2BA41A0BAAD43FBE91E35830A7779A82DE4C3C34204133459512B2008E83A5FDDA9C1209F9DEF833819DF5E9726AEB01162B421864DD3F08F4F9900DADB"
    '';
    ".config/weechat/matrix.conf".text = ''
      [network]
      autoreconnect_delay_growing = 2
      autoreconnect_delay_max = 600
      debug_buffer = off
      debug_category = all
      debug_level = error
      fetch_backlog_on_pgup = on
      lag_min_show = 500
      lag_reconnect = 90
      lazy_load_room_users = off
      max_backlog_sync_events = 10
      max_initial_sync_events = 30
      max_nicklist_users = 5000
      print_unconfirmed_messages = on
      read_markers_conditions = "''${markers_enabled}"
      resending_ignores_devices = on
      typing_notice_conditions = "''${typing_enabled}"

      [look]
      bar_item_typing_notice_prefix = "Typing: "
      busy_sign = "⏳"
      code_block_margin = 2
      code_blocks = on
      disconnect_sign = "❌"
      encrypted_room_sign = "🔐"
      encryption_warning_sign = "⚠️ "
      human_buffer_names = off
      markdown_input = on
      max_typing_notice_item_length = 50
      new_channel_position = none
      pygments_style = "native"
      quote_wrap = 67
      redactions = strikethrough
      server_buffer = merge_with_core

      [color]
      error_message_bg = default
      error_message_fg = darkgray
      nick_prefixes = "admin=lightgreen;mod=lightgreen;power=yellow"
      quote_bg = default
      quote_fg = lightgreen
      unconfirmed_message_bg = default
      unconfirmed_message_fg = darkgray
      untagged_code_bg = default
      untagged_code_fg = blue

      [server]
      nx2site.autoconnect = off
      nx2site.address = "nx2.site"
      nx2site.port = 443
      nx2site.proxy = ""
      nx2site.ssl_verify = on
      nx2site.username = "nx2"
      nx2site.password = "''${sec.data.matrix_nx2site_password}"
      nx2site.device_name = "Weechat@${hyper.host}"
      nx2site.autoreconnect_delay = 10
      nx2site.sso_helper_listening_port = 0
    '';
  };
}
