1 { config, pkgs, lib, ... }:
3 cfg = config.services.mautrix-facebook;
4 settingsFormat = pkgs.formats.json {};
5 settingsFile = settingsFormat.generate "mautrix-facebook-config.json" cfg.settings;
7 puppetRegex = lib.concatStringsSep
13 cfg.settings.bridge.username_template));
16 services.mautrix-facebook = {
17 enable = lib.mkEnableOption "Mautrix-Facebook, a Matrix-Facebook hybrid puppeting/relaybot bridge";
19 settings = lib.mkOption rec {
20 apply = lib.recursiveUpdate default;
21 type = settingsFormat.type;
24 address = "http://localhost:8008";
25 software = "standard";
30 address = "http://${hostname}:${toString port}";
31 hostname = "localhost";
34 database = "postgresql://";
36 bot_username = "facebookbot";
39 metrics.enabled = false;
40 manhole.enabled = false;
47 verification_levels = {
48 receive = "cross-signed-tofu";
49 send = "cross-signed-tofu";
50 share = "cross-signed-tofu";
53 username_template = "facebook_{userid}";
58 formatters.journal_fmt.format = "%(name)s: %(message)s";
60 class = "systemd.journal.JournalHandler";
61 formatter = "journal_fmt";
62 SYSLOG_IDENTIFIER = "mautrix-facebook";
66 handlers = ["journal"];
70 example = lib.literalExpression ''
73 address = "http://localhost:8008";
74 domain = "mydomain.example";
77 bridge.permissions = {
78 "@admin:mydomain.example" = "admin";
79 "mydomain.example" = "user";
84 {file}`config.yaml` configuration as a Nix attribute set.
85 Configuration options should match those described in
86 [example-config.yaml](https://github.com/mautrix/facebook/blob/master/mautrix_facebook/example-config.yaml).
88 Secret tokens should be specified using {option}`environmentFile`
89 instead of this world-readable attribute set.
93 environmentFile = lib.mkOption {
94 type = lib.types.nullOr lib.types.path;
97 File containing environment variables to be passed to the mautrix-facebook service.
99 Any config variable can be overridden by setting `MAUTRIX_FACEBOOK_SOME_KEY` to override the `some.key` variable.
103 configurePostgresql = lib.mkOption {
104 type = lib.types.bool;
107 Enable PostgreSQL and create a user and database for mautrix-facebook. The default `settings` reference this database, if you disable this option you must provide a database URL.
111 registrationData = lib.mkOption {
112 type = lib.types.attrs;
115 Output data for appservice registration. Simply make any desired changes and serialize to JSON. Note that this data contains secrets so think twice before putting it into the nix store.
117 Currently `as_token` and `hs_token` need to be added as they are not known to this module.
123 config = lib.mkIf cfg.enable {
124 users.groups.mautrix-facebook = {};
126 users.users.mautrix-facebook = {
127 group = "mautrix-facebook";
131 services.postgresql = lib.mkIf cfg.configurePostgresql {
132 ensureDatabases = ["mautrix-facebook"];
134 name = "mautrix-facebook";
135 ensureDBOwnership = true;
139 systemd.services.mautrix-facebook = rec {
140 wantedBy = [ "multi-user.target" ];
142 "network-online.target"
143 ] ++ lib.optional config.services.matrix-synapse.enable config.services.matrix-synapse.serviceUnit
144 ++ lib.optional cfg.configurePostgresql "postgresql.service";
151 User = "mautrix-facebook";
153 ProtectSystem = "strict";
155 ProtectKernelTunables = true;
156 ProtectKernelModules = true;
157 ProtectControlGroups = true;
160 EnvironmentFile = cfg.environmentFile;
163 ${pkgs.mautrix-facebook}/bin/mautrix-facebook --config=${settingsFile}
168 services.mautrix-facebook = {
170 id = cfg.settings.appservice.id;
176 regex = lib.escapeRegex "@${cfg.settings.appservice.bot_username}:${cfg.settings.homeserver.domain}";
180 regex = "@${puppetRegex}:${lib.escapeRegex cfg.settings.homeserver.domain}";
186 url = cfg.settings.appservice.address;
187 sender_localpart = "mautrix-facebook-sender";
189 rate_limited = false;
190 "de.sorunome.msc2409.push_ephemeral" = true;
191 push_ephemeral = true;
196 meta.maintainers = with lib.maintainers; [ kevincox ];