about summary refs log tree commit diff
path: root/modules/workstation/weechat/default.nix
blob: 95ba03c1ecdc2689c6227a5b0096667086036549 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
{ config, pkgs, lib, ... }:

with lib;

let
  scripts = with pkgs.weechatScripts;
    [ colorize_nicks weechat-go weechat-matrix zncplayback ];

  networks = [
    "blitzed" "gnome" "hackint" "indymedia" "ircnet" "libera"
    "oftc" "pissnet" "tilde"
  ];

  matrixServers = { fairydust = "fairydust.space"; };

  toWeeChat = value:
    /**/ if value == true  then "on"
    else if value == false then "off"
    else if isList value   then concatStringsSep "," value
    else toString value;

  sec = [ "znc.username" "znc.password" ];

  ignores = [
    "osmbot-test oftc #osm-gb"
  ];

  cfgin = {
    alias.cmd.B = "buffer";
    alias.cmd.ZNC = "quote znc";
    irc.look.buffer_switch_autojoin = false;
    irc.look.color_nicks_in_nicklist = true;
    irc.look.display_join_message = false;
    irc.look.server_buffer = "independent";
    irc.look.temporary_servers = true;

    irc.server_default = {
      addresses = "znc.qyliss.net/6697";
      autoconnect = true;
      capabilities = [ "account-notify" "away-notify" "cap-notify" "multi-prefix" "server-time" "znc.in/server-time-iso" "znc.in/self-message" "znc.in/playback" ];
      nicks = "qyliss";
      password = "\\\${sec.data.znc.password}";
      ssl = true;
      username = "\\\${sec.data.znc.username}";
    };

    irc.server = genAttrs networks (s:
      { username = "'\\\${sec.data.znc.username}/${s}'"; });
    plugins.var.python.zncplayback.servers = networks;

    logger.color.backlog_end = "*default";
    logger.look.backlog = 200;

    matrix.look.human_buffer_names = true;
    matrix.server = flip mapAttrs matrixServers (name: _: {
      autoconnect = true;
      device_name = "WeeChat (${config.networking.hostName})";
      username = "qyliss";
      password = "\\\${sec.data.fairydust.password}";
    });

    script.look.sort = "p,n";

    weechat.bar.buflist.hidden = true;
    weechat.bar.fset.items = "fset";
    weechat.bar.input.items = "[mode_indicator]+ [input_prompt]+(away),[input_search],[input_paste],input_text";
    weechat.bar.nicklist.size_max = 12;
    weechat.bar.status.color_bg = 53;
    weechat.bar.status.items = "[otr],[buffer_plugin],buffer_name+(buffer_modes)+{buffer_nicklist_count}+buffer_zoom+buffer_filter,[matrix_typing_notice],scroll,[lag],[hotlist],completion";
    weechat.bar.title.color_bg = 53;

    weechat.color.chat_nick_colors = [ "cyan" "magenta" "green" "brown" "lightblue" "lightcyan" "lightmagenta" "lightgreen" "blue" ];
    weechat.color.chat_nick_self = "default";
    weechat.color.status_count_other = "white";
    weechat.color.status_data_other = "white";
    weechat.color.status_nicklist_count = "white";
    weechat.color.status_time = "white";

    weechat.completion.default_template = "%(nicks)|%(irc_channels)|%(emoji)";
    weechat.completion.nick_completer = ":";

    weechat.look.buffer_notify_default = "message";
    weechat.look.highlight = [
      "spectrum" "spectrumos" "pr-tracker" "crosvm"
      "qyliss" "alyssa*" "*dntmissher" "*@alyssa"
    ];
    weechat.look.hotlist_names_count = 10;
    weechat.look.hotlist_names_level = 14;
    weechat.look.mouse = true;
    weechat.look.prefix_align_max = 12;
    weechat.look.save_config_on_exit = false;
    weechat.look.window_title = "WeeChat \\\${info:version}";
  };

  commands =
    map (n: "/server add ${n} ${cfgin.irc.server_default.addresses}") networks ++
    [ "/matrix server delete matrix_org" ] ++
    mapAttrsToList (n: d: "/matrix server add ${n} ${d}") matrixServers ++
    map (i: "/ignore add ${i}") ignores ++
    mapAttrsToList (name: value: "/set ${name} ${toWeeChat value}")
                   (flattenAttrs cfgin);

  flattenAttrs' = sep: attrs:
    listToAttrs (concatLists (flip mapAttrsToList attrs (k: v:
      if isAttrs v then mapAttrsToList (k': nameValuePair "${k}${sep}${k'}") (flattenAttrs' sep v)
                 else [ (nameValuePair k v) ])));

  flattenAttrs = flattenAttrs' ".";

  # If we were to pass --run-command ourselves, it would get forwarded
  # to WeeChat before the /script loads, so scripts wouldn't be
  # available and we wouldn't be able to do stuff like set up Matrix.
  cfg = pkgs.runCommand "weechat-config" {} ''
    LC_ALL=C.UTF-8 ${pkgs.weechat.override {
      configure = { ... }: {
        inherit scripts;
        init = concatStringsSep ";" (commands ++ [ "/save" "/exit" ]);
      };
    }}/bin/weechat-headless -d $out
  '';

  weechatHome = "${config.users.users.qyliss.home}/state/weechat";

in

{
  environment.extraInit = ''
    export WEECHAT_HOME="$HOME/state/weechat"
  '';

  environment.systemPackages = with pkgs; [
    (weechat.override {
      configure = { ...}: {
        inherit scripts;
      };
    })

    weechatScripts.weechat-matrix # for helper scripts
  ];

  systemd.tmpfiles.packages = [ (pkgs.runCommand "weechat-tmpfiles" {} ''
    conf=$out/lib/tmpfiles.d/weechat.conf
    mkdir -p $(dirname $conf)
    echo "d ${weechatHome} 0700 qyliss qyliss" > $conf
    for file in ${cfg}/*.conf
    do
        if [ "$file" != ${cfg}/sec.conf ]
        then echo "L+ ${weechatHome}/$(basename "$file") - - - - $file" >> $conf
        fi
    done
  '') ];
}