{ 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 '') ]; }