Skip to content

Commit 214a367

Browse files
committed
modules/weechat: init
1 parent c33eda4 commit 214a367

2 files changed

Lines changed: 192 additions & 0 deletions

File tree

modules/weechat/check.nix

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
pkgs,
3+
self,
4+
}:
5+
6+
let
7+
lib = pkgs.lib;
8+
weechatWrapped = self.wrapperModules.weechat.apply {
9+
scripts = [
10+
pkgs.weechatScripts.weechat-autosort
11+
pkgs.weechatScripts.colorize_nicks
12+
];
13+
settings = {
14+
weechat = {
15+
look.mouse = true;
16+
color.chat_nick_colors = lib.lists.subtractLists (lib.range 52 69 ++ lib.range 231 248) (
17+
lib.range 31 254
18+
);
19+
};
20+
irc.look.color_nicks_in_nicklist = true;
21+
irc.server.libera = {
22+
autoconnect = true;
23+
addresses = "irc.libera.chat/6697";
24+
tls = true;
25+
autojoin = [ "#vim" ];
26+
};
27+
};
28+
extraCommands = ''
29+
/save
30+
/connect -all
31+
'';
32+
inherit pkgs;
33+
};
34+
in
35+
pkgs.runCommand "weechat-test" { } ''
36+
${weechatWrapped.wrapper}/bin/weechat --version > $out
37+
''

modules/weechat/module.nix

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{ wlib, lib, ... }:
2+
wlib.wrapModule (
3+
{ config, wlib, ... }:
4+
let
5+
jsonFormat = config.pkgs.formats.json { };
6+
weechatLib = rec {
7+
attrPaths =
8+
let
9+
recurse =
10+
path: value:
11+
if builtins.isAttrs value then
12+
lib.mapAttrsToList (name: recurse (path ++ [ name ])) value
13+
else
14+
[ (lib.nameValuePair path value) ];
15+
in
16+
attrs: lib.flatten (recurse [ ] attrs);
17+
18+
attrPathsSep =
19+
sep: attrs:
20+
lib.listToAttrs (map (x: x // { name = lib.concatStringsSep sep x.name; }) (attrPaths attrs));
21+
22+
toWeechatValue =
23+
x:
24+
{
25+
bool = builtins.toJSON x;
26+
string = x;
27+
list = lib.concatMapStringsSep "," toWeechatValue x;
28+
int = toString x;
29+
}
30+
.${builtins.typeOf x};
31+
32+
setCommand = name: value: "/set ${name} \"${toWeechatValue value}\"";
33+
34+
filterAddreplace =
35+
name: filter:
36+
"/filter addreplace ${name} ${filter.buffer} ${toWeechatValue filter.tags} ${filter.regex}";
37+
};
38+
in
39+
{
40+
meta.maintainers = [ lib.maintainers.kmein ];
41+
42+
options = {
43+
scripts = lib.mkOption {
44+
type = lib.types.listOf lib.types.package;
45+
default = [ ];
46+
description = ''
47+
List of WeeChat script packages to load. Scripts can be found in pkgs.weechatScripts.
48+
'';
49+
};
50+
files = lib.mkOption {
51+
type = lib.types.attrsOf (wlib.types.file config.pkgs);
52+
default = { };
53+
example = lib.literalExpression ''
54+
{
55+
"sec.conf".content = '''
56+
[crypt]
57+
cipher = aes256
58+
hash_algo = sha256
59+
passphrase_command = ""
60+
salt = on
61+
62+
[data]
63+
__passphrase__ = off
64+
foo = "bar"
65+
''';
66+
}
67+
'';
68+
};
69+
extraCommands = lib.mkOption {
70+
type = lib.types.lines;
71+
default = "";
72+
};
73+
settings = lib.mkOption {
74+
type = jsonFormat.type;
75+
default = { };
76+
description = ''
77+
Your WeeChat configuration in Nix-style syntax.
78+
Secrets can be defined with \''${my.secret.value}
79+
'';
80+
example = {
81+
irc.server_default.nicks = "rick_\\\${sec.data.foo}";
82+
irc.server_default.msg_part = "ciao kakao";
83+
irc.server_default.msg_quit = "tschö mit \\\${sec.data.foo}";
84+
irc.look.color_nicks_in_nicklist = true;
85+
matrix.server.nibbana = {
86+
addresses = "nibbana.jp";
87+
};
88+
irc.server.hackint = {
89+
addresses = "irc.hackint.org/6697";
90+
ssl = true;
91+
autoconnect = true;
92+
autojoin = [ "#krebs" ];
93+
};
94+
weechat.bar.buflist.hidden = true;
95+
irc.server.hackint.command = lib.concatStringsSep "\\;" [
96+
"/msg nickserv IDENTIFY \\\${sec.data.hackint_password}"
97+
"/msg nickserv SET CLOAK ON"
98+
];
99+
filters.playlist_topic = {
100+
buffer = "irc.*.#the_playlist";
101+
tags = [ "irc_topic" ];
102+
regex = "*";
103+
};
104+
relay = {
105+
port.weechat = 9000;
106+
network.password = "hunter2";
107+
};
108+
alias.cmd.mod = "quote omode $channel +o $nick";
109+
secure.test.passphrase_command = "echo lol1234123124";
110+
};
111+
};
112+
};
113+
114+
config =
115+
let
116+
setFile = config.pkgs.writeText "weechat.set" (
117+
lib.optionalString (config.settings != { }) (
118+
lib.concatStringsSep "\n" (
119+
lib.optionals (config.settings.irc or { } != { }) (
120+
lib.mapAttrsToList (
121+
name: server: "/server add ${name} ${weechatLib.toWeechatValue server.addresses}"
122+
) config.settings.irc.server
123+
)
124+
++ lib.optionals (config.settings.matrix or { } != { }) (
125+
lib.mapAttrsToList (
126+
name: server: "/matrix server add ${name} ${server.address}"
127+
) config.settings.matrix.server
128+
)
129+
++ lib.mapAttrsToList weechatLib.setCommand (weechatLib.attrPathsSep "." config.settings)
130+
++ lib.optionals (config.settings.filters or { } != { }) (
131+
lib.mapAttrsToList weechatLib.filterAddreplace config.settings.filters
132+
)
133+
++ lib.singleton config.extraCommands
134+
)
135+
)
136+
);
137+
in
138+
{
139+
flags = {
140+
"--dir" = config.pkgs.linkFarm "weechat-config-dir" (
141+
lib.mapAttrsToList (name: file: {
142+
inherit name;
143+
inherit (file) path;
144+
}) config.files
145+
);
146+
};
147+
package = config.pkgs.weechat.override {
148+
configure = _: {
149+
init = "/exec -oc cat ${setFile}";
150+
scripts = config.scripts;
151+
};
152+
};
153+
};
154+
}
155+
)

0 commit comments

Comments
 (0)