#
# Configuration that sets up our local weechat env.
#
# vim: et:ts=2:sw=2:
#
{
  pkgs,
  lib,
  deprekages,
  ...
}:
let

  #
  # WeeChat.
  #

  # List each of the scripts we want to use.
  scripts = with pkgs.weechatScripts; [
    colorize_nicks
    wee-slack
    weechat-matrix
    weechat-notify-send
  ];

  # Create an easy way to 
  script-initializers-list = map (
    script: "/script load ${script}/share/${lib.lists.head script.scripts}"
  ) scripts;
  script-initializers = builtins.concatStringsSep "\n" script-initializers-list;

  # Create a customized weechat.
  weechat = pkgs.weechat.override {
    configure =
      { availablePlugins, ... }:
      {
        plugins = (builtins.attrValues availablePlugins) ++ [ deprekages.weechat-discord ];

        # Load our plugins on startup, and set up our color theme.
        init = ''
          ${script-initializers}

          /set weechat.bar.status.color_bg 0
          /set weechat.bar.title.color_bg 0
          /set weechat.color.chat_nick_colors 1,2,3,4,5,6
          /set buffers.color.hotlist_message_fg 7
          /set weechat.bar.buffers.position top

          /set buflist.format.buffer ''${format_number}''${cut:20,...,''${format_nick_prefix}''${format_name}}
        '';

      };
  };
in
{

  # Use signald, so we can connect up to signal.
  services.signald = {
    enable = true;
    user = "deprekated";
  };

  # Provide weechat, and related packages.
  environment.systemPackages = with pkgs; [
    signaldctl
    weechat
  ];
}
