blob: def8dc94f9f83e1e2c18c0bbde7b955df4ceb155 (
plain)
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
153
154
155
156
157
158
159
|
{ name, systemConfig, asConfig, lib, pkgs, ... }:
with lib;
let
inherit (systemConfig.services.matrix-appservices)
homeserverURL
homeserverDomain;
package = asConfig.package;
pname = getName package;
command = "${package}/bin/${package.meta.mainProgram or pname}";
mautrix = {
startupScript = ''
${command} --config=$SETTINGS_FILE
'';
settings = {
homeserver = {
address = homeserverURL;
domain = homeserverDomain;
};
appservice = with asConfig; {
address = "http://${host}:${toString port}";
hostname = host;
inherit port;
state_store_path = "$DIR/mx-state.json";
# mautrix stores the registration tokens in the config file
as_token = "$AS_TOKEN";
hs_token = "$HS_TOKEN";
};
bridge = {
username_template = "${name}_{userid}";
permissions = {
${homeserverDomain} = "user";
};
};
};
};
in
{
other = {
description = ''
No defaults will be set.
'';
};
matrix-appservice = {
startupScript = ''
${command} \
--config=$SETTINGS_FILE \
--port=$(echo ${asConfig.listenAddress} | sed 's/.*://') \
--file=$REGISTRATION_FILE
'';
description = ''
For bridges based on the matrix-appservice-bridge library. The settings for these
bridges are NOT configured automatically, because of the various differences
between them.
'';
};
mx-puppet = {
startupScript = ''
${command} \
--config=$SETTINGS_FILE \
--registration-file=$REGISTRATION_FILE
'';
registrationData =
let
# mx-puppet virtual users are always created based on the package name
botName = removePrefix "mx-puppet-" pname;
in
{
id = "${botName}-puppet";
sender_localpart = "_${botName}puppet_bot";
protocols = [ ];
namespaces = {
rooms = [ ];
users = [
{
regex = "@_${botName}puppet_.*:${homeserverDomain}";
exclusive = true;
}
];
aliases = [
{
regex = "#_${botName}puppet_.*:${homeserverDomain}";
exclusive = true;
}
];
};
};
settings = {
bridge = {
inherit (asConfig) port;
bindAddress = asConfig.host;
domain = homeserverDomain;
homeserverUrl = homeserverURL;
};
database.filename = "$DIR/database.db";
provisioning.whitelist = [ "@.*:${homeserverDomain}" ];
relay.whitelist = [ "@.*:${homeserverDomain}" ];
selfService.whitelist = [ "@.*:${homeserverDomain}" ];
logging = {
lineDateFormat = "";
files = [ ];
};
};
serviceConfig.WorkingDirectory =
"${package}/lib/node_modules/${pname}";
description = ''
For bridges based on the mx-puppet-bridge library. The settings will be
configured to use a sqlite database. Make sure to override database.filename,
if you plan to use another database.
'';
};
mautrix-go = {
inherit (mautrix) startupScript;
settings = recursiveUpdate mautrix.settings {
bridge.username_template = "${name}_{{.}}";
appservice.database = {
type = "sqlite3";
uri = "$DIR/database.db";
};
};
description = ''
The settings are configured to use a sqlite database. The startupScript will
create a new config file on every run to set the tokens, because mautrix
requires them to be in the config file.
'';
};
mautrix-python = {
settings = recursiveUpdate mautrix.settings {
appservice.database = "sqlite:///$DIR/database.db";
};
startupScript = optionalString (package ? alembic)
"${package.alembic}/bin/alembic -x config=$SETTINGS_FILE upgrade head\n"
+ mautrix.startupScript;
description = ''
Same properties as mautrix-go. This will also upgrade the database on every run
'';
};
}
|