···
+
{ config, pkgs, lib, ... }:
+
cfg = config.services.mautrix-facebook;
+
settingsFormat = pkgs.formats.json {};
+
settingsFile = settingsFormat.generate "mautrix-facebook-config.json" cfg.settings;
+
puppetRegex = concatStringsSep
+
cfg.settings.bridge.username_template));
+
services.mautrix-facebook = {
+
enable = mkEnableOption "Mautrix-Facebook, a Matrix-Facebook hybrid puppeting/relaybot bridge";
+
settings = mkOption rec {
+
apply = recursiveUpdate default;
+
type = settingsFormat.type;
+
address = "http://localhost:8008";
+
address = "http://${hostname}:${toString port}";
+
hostname = "localhost";
+
database = "postgresql://";
+
bot_username = "facebookbot";
+
metrics.enabled = false;
+
manhole.enabled = false;
+
username_template = "facebook_{userid}";
+
formatters.journal_fmt.format = "%(name)s: %(message)s";
+
class = "systemd.journal.JournalHandler";
+
formatter = "journal_fmt";
+
SYSLOG_IDENTIFIER = "mautrix-facebook";
+
handlers = ["journal"];
+
example = literalExpression ''
+
address = "http://localhost:8008";
+
domain = "mydomain.example";
+
"@admin:mydomain.example" = "admin";
+
"mydomain.example" = "user";
+
<filename>config.yaml</filename> configuration as a Nix attribute set.
+
Configuration options should match those described in
+
<link xlink:href="https://github.com/mautrix/facebook/blob/master/mautrix_facebook/example-config.yaml">
+
example-config.yaml</link>.
+
Secret tokens should be specified using <option>environmentFile</option>
+
instead of this world-readable attribute set.
+
environmentFile = mkOption {
+
type = types.nullOr types.path;
+
File containing environment variables to be passed to the mautrix-telegram service.
+
Any config variable can be overridden by setting <literal>MAUTRIX_FACEBOOK_SOME_KEY</literal> to override the <literal>some.key</literal> variable.
+
configurePostgresql = mkOption {
+
Enable PostgreSQL and create a user and database for mautrix-facebook. The default <literal>settings</literal> reference this database, if you disable this option you must provide a database URL.
+
registrationData = mkOption {
+
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.
+
Currently <literal>as_token</literal> and <literal>hs_token</literal> need to be added as they are not known to this module.
+
config = mkIf cfg.enable {
+
users.users.mautrix-facebook = {
+
group = "mautrix-facebook";
+
services.postgresql = mkIf cfg.configurePostgresql {
+
ensureDatabases = ["mautrix-facebook"];
+
name = "mautrix-facebook";
+
"DATABASE \"mautrix-facebook\"" = "ALL PRIVILEGES";
+
systemd.services.mautrix-facebook = rec {
+
wantedBy = [ "multi-user.target" ];
+
"network-online.target"
+
] ++ optional config.services.matrix-synapse.enable "matrix-synapse.service"
+
++ optional cfg.configurePostgresql "postgresql.service";
+
User = "mautrix-facebook";
+
ProtectSystem = "strict";
+
ProtectKernelTunables = true;
+
ProtectKernelModules = true;
+
ProtectControlGroups = true;
+
EnvironmentFile = cfg.environmentFile;
+
${pkgs.mautrix-facebook}/bin/mautrix-facebook --config=${settingsFile}
+
services.mautrix-facebook = {
+
id = "mautrix-facebook";
+
regex = escapeRegex "@${cfg.settings.appservice.bot_username}:${cfg.settings.homeserver.domain}";
+
regex = "@${puppetRegex}:${escapeRegex cfg.settings.homeserver.domain}";
+
url = cfg.settings.appservice.address;
+
sender_localpart = "mautrix-facebook-sender";
+
"de.sorunome.msc2409.push_ephemeral" = true;
+
meta.maintainers = with maintainers; [ kevincox ];