about summary refs log tree commit diff
path: root/modules/workstation/weechat/default.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-07-30 12:12:24 +0000
committerAlyssa Ross <hi@alyssa.is>2019-07-30 12:12:24 +0000
commit4784be4b821928e0d2cc12c9381c54078dc346e8 (patch)
treec23a33a4b60275798d20685762081f0b6ce1b540 /modules/workstation/weechat/default.nix
parentf2845fc268ca1d2dc2864a68fb8ce2dcdd516712 (diff)
downloadnixlib-4784be4b821928e0d2cc12c9381c54078dc346e8.tar
nixlib-4784be4b821928e0d2cc12c9381c54078dc346e8.tar.gz
nixlib-4784be4b821928e0d2cc12c9381c54078dc346e8.tar.bz2
nixlib-4784be4b821928e0d2cc12c9381c54078dc346e8.tar.lz
nixlib-4784be4b821928e0d2cc12c9381c54078dc346e8.tar.xz
nixlib-4784be4b821928e0d2cc12c9381c54078dc346e8.tar.zst
nixlib-4784be4b821928e0d2cc12c9381c54078dc346e8.zip
modules/weechat: init
Previously, this lived in a separate Git repo, because WeeChat likes to
rewrite its configuration when it's upgraded. But by using a headless
WeeChat to write our configuration, which shouldn't be automatically
changed between upgrades, we can configure it declaratively through Nix!
Diffstat (limited to 'modules/workstation/weechat/default.nix')
-rw-r--r--modules/workstation/weechat/default.nix114
1 files changed, 104 insertions, 10 deletions
diff --git a/modules/workstation/weechat/default.nix b/modules/workstation/weechat/default.nix
index 08a1edb86e6f..2bc2d07d26af 100644
--- a/modules/workstation/weechat/default.nix
+++ b/modules/workstation/weechat/default.nix
@@ -1,4 +1,97 @@
-{ pkgs, ... }:
+{ pkgs, lib, ... }:
+
+with lib;
+
+let
+  networks = [ "freenode" ];
+
+  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" "slack.api_tokens" ];
+
+  cfgin = {
+    alias.cmd.B = "buffer";
+    irc.look.buffer_switch_autojoin = false;
+    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;
+
+    plugins.var.python.slack.slack_api_token = "\\\${sec.data.slack.api_tokens}";
+    plugins.var.python.slack.auto_open_threads = true;
+    plugins.var.python.slack.background_load_all_history = true;
+    plugins.var.python.slack.short_buffer_names = true;
+    plugins.var.python.slack.show_reaction_nicks = true;
+    plugins.var.python.vimode.no_warn = true;
+
+    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,[vi_buffer]";
+    weechat.bar.status.items = "[otr],[buffer_plugin],buffer_name+(buffer_modes)+{buffer_nicklist_count}+buffer_zoom+buffer_filter,scroll,[lag],[hotlist],completion";
+
+    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 = [ "@edinburgh-staff" "@devp" "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 (d: ''/set sec.data.${d} test'') sec ++ [ "/save" ] ++
+    map (n: "/server add ${n} ${cfgin.irc.server_default.addresses}") networks ++
+    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' ".";
+
+  cfg = pkgs.runCommand "weechat-config" {} (lib.traceVal ''
+    ${pkgs.weechat}/bin/weechat-headless -d $out \
+        ${concatMapStringsSep " " (cmd: "-r ${escapeShellArg cmd}") commands} \
+        -r /save \
+        -r /exit
+  '');
+
+in
 
 {
   environment.extraInit = ''
@@ -6,19 +99,20 @@
   '';
 
   environment.systemPackages = with pkgs; [
-    (weechat.override {
+    (wrapWeechat (weechat-unwrapped.override { pythonPackages = python3Packages; }) {
       configure = { availablePlugins, ... }: {
-        plugins = with availablePlugins; [
-          (python.withPackages (ps: with ps; [ potr websocket_client ]))
-        ];
+        scripts = with weechatScripts;
+          [ colorize_nicks go wee-slack zncplayback ];
       };
     })
   ];
 
-  home.qyliss.dirs."state/weechat".activationScripts.git = ''
-    ${pkgs.git}/bin/git init -q
-    ${pkgs.git}/bin/git remote rm origin 2>/dev/null || true
-    ${pkgs.git}/bin/git remote add origin git@github.com:alyssais/weechat-config
-    chown -R qyliss .git
+  home.qyliss.dirs."state/weechat".activationScripts.config = ''
+    for file in ${cfg}/*.conf
+    do
+        if [ "$file" != ${cfg}/sec.conf ]
+        then ln -sf $file $(basename $file)
+        fi
+    done
   '';
 }