blob: 32a0c2a5dbd987b4d41ec31817effd73fc6b3be8 (
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.mautrix-slack;
dataDir = "/var/lib/mautrix-slack";
registrationFile = "${dataDir}/slack-registration.yaml";
settingsFormat = pkgs.formats.json { };
settingsFile = settingsFormat.generate "mautrix-slack-config.json" cfg.settings;
in
{
options = {
services.mautrix-slack = {
enable = mkEnableOption (lib.mdDoc "Mautrix-Slack, a Matrix-Slack hybrid puppeting/relaybot bridge");
package = mkOption {
type = types.package;
default = pkgs.callPackage ./pkgs/mautrix-slack.nix { };
defaultText = "pkgs.mautrix-slack";
example = "pkgs.mautrix-slack.override { … = …; }";
description = lib.mdDoc ''
Package of the application to run, exposed for overriding purposes.
'';
};
settings = mkOption rec {
apply = recursiveUpdate default;
type = settingsFormat.type;
default = {
homeserver = {
software = "standard";
};
appservice = rec {
address = "http://${hostname}:${toString port}";
hostname = "localhost";
port = 29319;
database = {
type = "postgres";
uri = "postgres:///mautrix-slack?host=/run/postgresql&sslmode=disable";
};
id = "slack";
bot = {
username = "slackbot";
};
# backfill = {
# enable = false;
# conversations_count = 200;
# unread_hours_threshold = 720;
# immediate_messages = 10;
# incremental = {
# messages_per_batch = 100;
# post_batch_delay = 20;
# max_messages = {
# channel = -1;
# group_dm = -1;
# dm = -1;
# };
# };
# };
# encryption = {
# allow = false;
# default = false;
# appservice = false;
# require = false;
# allow_key_sharing = false;
# verification_levels = {
# receive = "unverified";
# send = "unverified";
# share = "cross-signed-tofu";
# };
# rotation = {
# enable_custom = false;
# milliseconds = 604800000;
# messages = 100;
# };
# };
# provisioning = {
# prefix = "/_matrix/provision";
# shared_secret = "generate";
# };
};
logging = {
directory = "/var/log/mautrix";
file_name_format = "slack-{{.Date}}-{{.Index}}.log";
file_date_format = "2006-01-02";
file_mode = 384;
timestamp_format = "Jan _2, 2006 15:04:05";
print_level = "debug";
print_json = false;
file_json = false;
};
};
};
environmentFile = mkOption {
type = types.nullOr types.path;
default = null;
description = lib.mdDoc ''
File containing environment variables to be passed to the mautrix-slack service.
Any config variable can be overridden by setting `MAUTRIX_SLACK_SOME_KEY` to override the `some.key` variable.
'';
};
configurePostgresql = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc ''
Enable PostgreSQL and create a user and database for mautrix-slack. The default `settings` reference this database, if you disable this option you must provide a database URL.
'';
};
};
};
config = mkIf cfg.enable {
users.groups.mautrix-slack = { };
users.users.mautrix-slack = {
group = "mautrix-slack";
isSystemUser = true;
};
services.postgresql = mkIf cfg.configurePostgresql {
enable = true;
ensureDatabases = [ "mautrix-slack" ];
ensureUsers = [{
name = "mautrix-slack";
# ensurePermissions = {
# "DATABASE \"mautrix-slack\"" = "ALL PRIVILEGES";
# };
}];
};
systemd.services.mautrix-slack = rec {
wantedBy = [ "multi-user.target" ];
wants = [
"network-online.target"
] ++ optional config.services.matrix-synapse.enable "matrix-synapse.service"
++ optional cfg.configurePostgresql "postgresql.service";
after = wants;
preStart = ''
# generate the appservice's registration file if absent
if [ ! -f '${registrationFile}' ]; then
${cfg.package}/bin/mautrix-slack -g -c ${settingsFile} \
-r ${registrationFile}
fi
'';
serviceConfig = {
Type = "simple";
Restart = "always";
User = "mautrix-slack";
NoNewPrivileges = true;
MemoryDenyWriteExecute = true;
PrivateDevices = true;
PrivateTmp = true;
ProtectHome = true;
ProtectSystem = "strict";
ProtectControlGroups = true;
RestrictSUIDSGID = true;
RestrictRealtime = true;
LockPersonality = true;
ProtectKernelLogs = true;
ProtectKernelTunables = true;
ProtectHostname = true;
ProtectKernelModules = true;
PrivateUsers = true;
ProtectClock = true;
SystemCallArchitectures = "native";
SystemCallErrorNumber = "EPERM";
SystemCallFilter = "@system-service";
StateDirectory = baseNameOf dataDir;
LogsDirectory = "mautrix";
LogsDirectoryMode = "0750";
EnvironmentFile = cfg.environmentFile;
ExecStart = ''
${cfg.package}/bin/mautrix-slack --no-update --config=${settingsFile} --registration=${registrationFile}
'';
};
};
};
}
|