Skip to content

Commit bf4cb5f

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

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed

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.liberta = {
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: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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+
options = {
41+
scripts = lib.mkOption {
42+
type = lib.types.listOf lib.types.package;
43+
default = [ ];
44+
description = ''
45+
some stuff from pkgs.weechatScripts
46+
'';
47+
};
48+
files = lib.mkOption {
49+
type = lib.types.attrsOf (wlib.types.file config.pkgs);
50+
default = { };
51+
example = lib.literalExpression ''
52+
{
53+
"sec.conf".content = '''
54+
[crypt]
55+
cipher = aes256
56+
hash_algo = sha256
57+
passphrase_command = ""
58+
salt = on
59+
60+
[data]
61+
__passphrase__ = off
62+
foo = "bar"
63+
''';
64+
}
65+
'';
66+
};
67+
extraCommands = lib.mkOption {
68+
type = lib.types.lines;
69+
default = "";
70+
};
71+
settings = lib.mkOption {
72+
type = jsonFormat.type;
73+
default = { };
74+
description = ''
75+
your weechat config in nix-style syntax.
76+
secrets can be defined with \''${my.secret.value}
77+
'';
78+
example = {
79+
irc.server_default.nicks = "rick_\\\${sec.data.foo}";
80+
irc.server_default.msg_part = "ciao kakao";
81+
irc.server_default.msg_quit = "tschö mit \\\${sec.data.foo}";
82+
irc.look.color_nicks_in_nicklist = true;
83+
matrix.server.nibbana = {
84+
address = "nibbana.jp";
85+
};
86+
irc.server.hackint = {
87+
address = "irc.hackint.org/6697";
88+
ssl = true;
89+
autoconnect = true;
90+
autojoin = [ "#krebs" ];
91+
};
92+
weechat.bar.buflist.hidden = true;
93+
irc.server.hackint.command = lib.concatStringsSep "\\;" [
94+
"/msg nickserv IDENTIFY \\\${sec.data.hackint_password}"
95+
"/msg nickserv SET CLOAK ON"
96+
];
97+
filters.playlist_topic = {
98+
buffer = "irc.*.#the_playlist";
99+
tags = [ "irc_topic" ];
100+
regex = "*";
101+
};
102+
relay = {
103+
port.weechat = 9000;
104+
network.password = "hunter2";
105+
};
106+
alias.cmd.mod = "quote omode $channel +o $nick";
107+
secure.test.passphrase_command = "echo lol1234123124";
108+
};
109+
};
110+
};
111+
112+
config =
113+
let
114+
setFile = config.pkgs.writeText "weechat.set" (
115+
lib.optionalString (config.settings != { }) (
116+
lib.concatStringsSep "\n" (
117+
lib.optionals (config.settings.irc or { } != { }) (
118+
lib.mapAttrsToList (
119+
name: server: "/server add ${name} ${weechatLib.toWeechatValue server.addresses}"
120+
) config.settings.irc.server
121+
)
122+
++ lib.optionals (config.settings.matrix or { } != { }) (
123+
lib.mapAttrsToList (
124+
name: server: "/matrix server add ${name} ${server.address}"
125+
) config.settings.matrix.server
126+
)
127+
++ lib.mapAttrsToList weechatLib.setCommand (weechatLib.attrPathsSep "." config.settings)
128+
++ lib.optionals (config.settings.filters or { } != { }) (
129+
lib.mapAttrsToList weechatLib.filterAddreplace config.settings.filters
130+
)
131+
++ lib.singleton config.extraCommands
132+
)
133+
)
134+
);
135+
in
136+
{
137+
flags = {
138+
"--dir" = config.pkgs.linkFarm "weechat-config-dir" (
139+
lib.mapAttrsToList (name: file: {
140+
inherit name;
141+
inherit (file) path;
142+
}) config.files
143+
);
144+
};
145+
package = config.pkgs.weechat.override {
146+
configure = _: {
147+
init = "/exec -oc cat ${setFile}";
148+
scripts = config.scripts;
149+
};
150+
};
151+
};
152+
}
153+
)

0 commit comments

Comments
 (0)