From 307171bf1f54caffa77fa212f3119ae1b8b82815 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sat, 19 Sep 2020 06:21:30 -0300 Subject: Initial setup for Telegram in Matrix, but it is still not working --- TODOs.org | 1 + mautrix-whatsapp-config.yaml | 255 +++++++++++++++++++++++++++++++++++ mautrix-whatsapp.yaml | 255 ----------------------------------- nixos-switch.sh | 3 +- secrets/mautrix-telegram-config.yaml | Bin 0 -> 24523 bytes secrets/telegram.org | Bin 0 -> 2410 bytes vps-configuration.nix | 49 +++++-- 7 files changed, 293 insertions(+), 270 deletions(-) create mode 100644 mautrix-whatsapp-config.yaml delete mode 100644 mautrix-whatsapp.yaml create mode 100644 secrets/mautrix-telegram-config.yaml create mode 100644 secrets/telegram.org diff --git a/TODOs.org b/TODOs.org index 2d60619..a0057ce 100644 --- a/TODOs.org +++ b/TODOs.org @@ -49,6 +49,7 @@ resource "vultr_block_storage" "vps_storage" { } #+END_SRC ** TODO Prosody HTTP uploads +** TODO Use nixos-unstable * Tasks - v5 ** TODO Stop doing chmod to share certificates ** TODO Run cgit from nginx instead of using lighttpd diff --git a/mautrix-whatsapp-config.yaml b/mautrix-whatsapp-config.yaml new file mode 100644 index 0000000..ba7ac9a --- /dev/null +++ b/mautrix-whatsapp-config.yaml @@ -0,0 +1,255 @@ +# Homeserver details. +homeserver: + # The address that this appservice can use to connect to the homeserver. + address: https://matrix.euandreh.xyz + # The domain of the homeserver (for MXIDs, etc). + domain: matrix.euandreh.xyz + +# Application service host/registration related details. +# Changing these values requires regeneration of the registration. +appservice: + # The address that the homeserver can use to connect to this appservice. + address: http://localhost:29318 + + # The hostname and port where this appservice should listen. + hostname: 0.0.0.0 + port: 29318 + + # Database config. + database: + # The database type. "sqlite3" and "postgres" are supported. + type: sqlite3 + # The database URI. + # SQLite: File name is enough. https://github.com/mattn/go-sqlite3#connection-string + # Postgres: Connection string. For example, postgres://user:password@host/database?sslmode=disable + uri: mautrix-whatsapp.db + # Maximum number of connections. Mostly relevant for Postgres. + max_open_conns: 20 + max_idle_conns: 2 + + # Settings for provisioning API + provisioning: + # Prefix for the provisioning API paths. + prefix: /_matrix/provision/v1 + # Shared secret for authentication. If set to "disable", the provisioning API will be disabled. + shared_secret: disable + + # The unique ID of this appservice. + id: whatsapp + # Appservice bot details. + bot: + # Username of the appservice bot. + username: whatsappbot + # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty + # to leave display name/avatar as-is. + displayname: WhatsApp bridge bot + avatar: mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr + + # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. + as_token: "This value is generated when generating the registration" + hs_token: "This value is generated when generating the registration" + +metrics: + # Whether or not to enable prometheus metrics + enabled: false + # IP and port where the metrics listener should be. The path is always /metrics + listen: 127.0.0.1:8001 + +whatsapp: + # Device name that's shown in the "WhatsApp Web" section in the mobile app + device_name: Mautrix-WhatsApp bridge + short_name: mx-wa + +# Bridge config +bridge: + # Localpart template of MXIDs for WhatsApp users. + # {{.}} is replaced with the phone number of the WhatsApp user. + username_template: whatsapp_{{.}} + # Displayname template for WhatsApp users. + # {{.Notify}} - nickname set by the WhatsApp user + # {{.Jid}} - phone number (international format) + # The following variables are also available, but will cause problems on multi-user instances: + # {{.Name}} - display name from contact list + # {{.Short}} - short display name from contact list + # To use multiple if's, you need to use: {{else if .Name}}, for example: + # "{{if .Notify}}{{.Notify}}{{else if .Name}}{{.Name}}{{else}}{{.Jid}}{{end}} (WA)" + displayname_template: "{{if .Notify}}{{.Notify}}{{else}}{{.Jid}}{{end}} (WA)" + # Localpart template for per-user room grouping community IDs. + # On startup, the bridge will try to create these communities, add all of the specific user's + # portals to the community, and invite the Matrix user to it. + # (Note that, by default, non-admins might not have your homeserver's permission to create + # communities.) + # {{.Localpart}} is the MXID localpart and {{.Server}} is the MXID server part of the user. + community_template: whatsapp_{{.Localpart}}={{.Server}} + + # WhatsApp connection timeout in seconds. + connection_timeout: 20 + # If WhatsApp doesn't respond within connection_timeout, should the bridge try to fetch the message + # to see if it was actually bridged? Use this if you have problems with sends timing out but actually + # succeeding. + fetch_message_on_timeout: false + # Whether or not the bridge should send a read receipt from the bridge bot when a message has been + # sent to WhatsApp. If fetch_message_on_timeout is enabled, a successful post-timeout fetch will + # trigger a read receipt too. + delivery_receipts: false + # Number of times to regenerate QR code when logging in. + # The regenerated QR code is sent as an edit and essentially multiplies the login timeout (20 seconds) + login_qr_regen_count: 2 + # Maximum number of times to retry connecting on connection error. + max_connection_attempts: 3 + # Number of seconds to wait between connection attempts. + # Negative numbers are exponential backoff: -connection_retry_delay + 1 + 2^attempts + connection_retry_delay: -1 + # Whether or not the bridge should send a notice to the user's management room when it retries connecting. + # If false, it will only report when it stops retrying. + report_connection_retry: true + # Maximum number of seconds to wait for chats to be sent at startup. + # If this is too low and you have lots of chats, it could cause backfilling to fail. + chat_list_wait: 30 + # Maximum number of seconds to wait to sync portals before force unlocking message processing. + # If this is too low and you have lots of chats, it could cause backfilling to fail. + portal_sync_wait: 600 + user_message_buffer: 1024 + portal_message_buffer: 128 + + # Whether or not to send call start/end notices to Matrix. + call_notices: + start: true + end: true + + # Number of chats to sync for new users. + initial_chat_sync_count: 10 + # Number of old messages to fill when creating new portal rooms. + initial_history_fill_count: 20 + # Whether or not notifications should be turned off while filling initial history. + # Only applicable when using double puppeting. + initial_history_disable_notifications: false + # Maximum number of chats to sync when recovering from downtime. + # Set to -1 to sync all new chats during downtime. + recovery_chat_sync_limit: -1 + # Whether or not to sync history when recovering from downtime. + recovery_history_backfill: true + # Maximum number of seconds since last message in chat to skip + # syncing the chat in any case. This setting will take priority + # over both recovery_chat_sync_limit and initial_chat_sync_count. + # Default is 3 days = 259200 seconds + sync_max_chat_age: 259200 + + # Whether or not to sync with custom puppets to receive EDUs that + # are not normally sent to appservices. + sync_with_custom_puppets: true + # Whether or not to update the m.direct account data event when double puppeting is enabled. + # Note that updating the m.direct event is not atomic (except with mautrix-asmux) + # and is therefore prone to race conditions. + sync_direct_chat_list: false + # When double puppeting is enabled, users can use `!wa toggle` to change whether or not + # presence and read receipts are bridged. These settings set the default values. + # Existing users won't be affected when these are changed. + default_bridge_receipts: true + default_bridge_presence: true + # Shared secret for https://github.com/devture/matrix-synapse-shared-secret-auth + # + # If set, custom puppets will be enabled automatically for local users + # instead of users having to find an access token and run `login-matrix` + # manually. + login_shared_secret: null + + # Whether or not to invite own WhatsApp user's Matrix puppet into private + # chat portals when backfilling if needed. + # This always uses the default puppet instead of custom puppets due to + # rate limits and timestamp massaging. + invite_own_puppet_for_backfilling: true + # Whether or not to explicitly set the avatar and room name for private + # chat portal rooms. This can be useful if the previous field works fine, + # but causes room avatar/name bugs. + private_chat_portal_meta: false + # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run. + # This field will automatically be changed back to false after it, + # except if the config file is not writable. + resend_bridge_info: false + + # Whether or not thumbnails from WhatsApp should be sent. + # They're disabled by default due to very low resolution. + whatsapp_thumbnail: false + + # Allow invite permission for user. User can invite any bots to room with whatsapp + # users (private chat and groups) + allow_user_invite: false + + # The prefix for commands. Only required in non-management rooms. + command_prefix: "!wa" + + # End-to-bridge encryption support options. This requires login_shared_secret to be configured + # in order to get a device for the bridge bot. + # + # Additionally, https://github.com/matrix-org/synapse/pull/5758 is required if using a normal + # application service. + encryption: + # Allow encryption, work in group chat rooms with e2ee enabled + allow: false + # Default to encryption, force-enable encryption in all portals the bridge creates + # This will cause the bridge bot to be in private chats for the encryption to work properly. + # It is recommended to also set private_chat_portal_meta to true when using this. + default: false + # Options for automatic key sharing. + key_sharing: + # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. + # You must use a client that supports requesting keys from other users to use this feature. + allow: false + # Require the requesting device to have a valid cross-signing signature? + # This doesn't require that the bridge has verified the device, only that the user has verified it. + # Not yet implemented. + require_cross_signing: false + # Require devices to be verified by the bridge? + # Verification by the bridge is not yet implemented. + require_verification: true + + # Permissions for using the bridge. + # Permitted values: + # relaybot - Talk through the relaybot (if enabled), no access otherwise + # user - Access to use the bridge to chat with a WhatsApp account. + # admin - User level and some additional administration tools + # Permitted keys: + # * - All Matrix users + # domain - All users on that homeserver + # mxid - Specific user + permissions: + "*": relaybot + "@eu:euandreh.xyz": admin + "@eu:matrix.euandreh.xyz": admin + + relaybot: + # Whether or not relaybot support is enabled. + enabled: false + # The management room for the bot. This is where all status notifications are posted and + # in this room, you can use `!wa ` instead of `!wa relaybot `. Omitting + # the command prefix completely like in user management rooms is not possible. + management: !foo:example.com + # List of users to invite to all created rooms that include the relaybot. + invites: [] + # The formats to use when sending messages to WhatsApp via the relaybot. + message_formats: + m.text: "{{ .Sender.Displayname }}: {{ .Message }}" + m.notice: "{{ .Sender.Displayname }}: {{ .Message }}" + m.emote: "* {{ .Sender.Displayname }} {{ .Message }}" + m.file: "{{ .Sender.Displayname }} sent a file" + m.image: "{{ .Sender.Displayname }} sent an image" + m.audio: "{{ .Sender.Displayname }} sent an audio file" + m.video: "{{ .Sender.Displayname }} sent a video" + m.location: "{{ .Sender.Displayname }} sent a location" + +# Logging config. +logging: + # The directory for log files. Will be created if not found. + directory: ./logs + # Available variables: .Date for the file date and .Index for different log files on the same day. + file_name_format: "{{.Date}}-{{.Index}}.log" + # Date format for file names in the Go time format: https://golang.org/pkg/time/#pkg-constants + file_date_format: 2006-01-02 + # Log file permissions. + file_mode: 0600 + # Timestamp format for log entries in the Go time format. + timestamp_format: Jan _2, 2006 15:04:05 + # Minimum severity for log messages. + # Options: debug, info, warn, error, fatal + print_level: debug diff --git a/mautrix-whatsapp.yaml b/mautrix-whatsapp.yaml deleted file mode 100644 index ba7ac9a..0000000 --- a/mautrix-whatsapp.yaml +++ /dev/null @@ -1,255 +0,0 @@ -# Homeserver details. -homeserver: - # The address that this appservice can use to connect to the homeserver. - address: https://matrix.euandreh.xyz - # The domain of the homeserver (for MXIDs, etc). - domain: matrix.euandreh.xyz - -# Application service host/registration related details. -# Changing these values requires regeneration of the registration. -appservice: - # The address that the homeserver can use to connect to this appservice. - address: http://localhost:29318 - - # The hostname and port where this appservice should listen. - hostname: 0.0.0.0 - port: 29318 - - # Database config. - database: - # The database type. "sqlite3" and "postgres" are supported. - type: sqlite3 - # The database URI. - # SQLite: File name is enough. https://github.com/mattn/go-sqlite3#connection-string - # Postgres: Connection string. For example, postgres://user:password@host/database?sslmode=disable - uri: mautrix-whatsapp.db - # Maximum number of connections. Mostly relevant for Postgres. - max_open_conns: 20 - max_idle_conns: 2 - - # Settings for provisioning API - provisioning: - # Prefix for the provisioning API paths. - prefix: /_matrix/provision/v1 - # Shared secret for authentication. If set to "disable", the provisioning API will be disabled. - shared_secret: disable - - # The unique ID of this appservice. - id: whatsapp - # Appservice bot details. - bot: - # Username of the appservice bot. - username: whatsappbot - # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty - # to leave display name/avatar as-is. - displayname: WhatsApp bridge bot - avatar: mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr - - # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. - as_token: "This value is generated when generating the registration" - hs_token: "This value is generated when generating the registration" - -metrics: - # Whether or not to enable prometheus metrics - enabled: false - # IP and port where the metrics listener should be. The path is always /metrics - listen: 127.0.0.1:8001 - -whatsapp: - # Device name that's shown in the "WhatsApp Web" section in the mobile app - device_name: Mautrix-WhatsApp bridge - short_name: mx-wa - -# Bridge config -bridge: - # Localpart template of MXIDs for WhatsApp users. - # {{.}} is replaced with the phone number of the WhatsApp user. - username_template: whatsapp_{{.}} - # Displayname template for WhatsApp users. - # {{.Notify}} - nickname set by the WhatsApp user - # {{.Jid}} - phone number (international format) - # The following variables are also available, but will cause problems on multi-user instances: - # {{.Name}} - display name from contact list - # {{.Short}} - short display name from contact list - # To use multiple if's, you need to use: {{else if .Name}}, for example: - # "{{if .Notify}}{{.Notify}}{{else if .Name}}{{.Name}}{{else}}{{.Jid}}{{end}} (WA)" - displayname_template: "{{if .Notify}}{{.Notify}}{{else}}{{.Jid}}{{end}} (WA)" - # Localpart template for per-user room grouping community IDs. - # On startup, the bridge will try to create these communities, add all of the specific user's - # portals to the community, and invite the Matrix user to it. - # (Note that, by default, non-admins might not have your homeserver's permission to create - # communities.) - # {{.Localpart}} is the MXID localpart and {{.Server}} is the MXID server part of the user. - community_template: whatsapp_{{.Localpart}}={{.Server}} - - # WhatsApp connection timeout in seconds. - connection_timeout: 20 - # If WhatsApp doesn't respond within connection_timeout, should the bridge try to fetch the message - # to see if it was actually bridged? Use this if you have problems with sends timing out but actually - # succeeding. - fetch_message_on_timeout: false - # Whether or not the bridge should send a read receipt from the bridge bot when a message has been - # sent to WhatsApp. If fetch_message_on_timeout is enabled, a successful post-timeout fetch will - # trigger a read receipt too. - delivery_receipts: false - # Number of times to regenerate QR code when logging in. - # The regenerated QR code is sent as an edit and essentially multiplies the login timeout (20 seconds) - login_qr_regen_count: 2 - # Maximum number of times to retry connecting on connection error. - max_connection_attempts: 3 - # Number of seconds to wait between connection attempts. - # Negative numbers are exponential backoff: -connection_retry_delay + 1 + 2^attempts - connection_retry_delay: -1 - # Whether or not the bridge should send a notice to the user's management room when it retries connecting. - # If false, it will only report when it stops retrying. - report_connection_retry: true - # Maximum number of seconds to wait for chats to be sent at startup. - # If this is too low and you have lots of chats, it could cause backfilling to fail. - chat_list_wait: 30 - # Maximum number of seconds to wait to sync portals before force unlocking message processing. - # If this is too low and you have lots of chats, it could cause backfilling to fail. - portal_sync_wait: 600 - user_message_buffer: 1024 - portal_message_buffer: 128 - - # Whether or not to send call start/end notices to Matrix. - call_notices: - start: true - end: true - - # Number of chats to sync for new users. - initial_chat_sync_count: 10 - # Number of old messages to fill when creating new portal rooms. - initial_history_fill_count: 20 - # Whether or not notifications should be turned off while filling initial history. - # Only applicable when using double puppeting. - initial_history_disable_notifications: false - # Maximum number of chats to sync when recovering from downtime. - # Set to -1 to sync all new chats during downtime. - recovery_chat_sync_limit: -1 - # Whether or not to sync history when recovering from downtime. - recovery_history_backfill: true - # Maximum number of seconds since last message in chat to skip - # syncing the chat in any case. This setting will take priority - # over both recovery_chat_sync_limit and initial_chat_sync_count. - # Default is 3 days = 259200 seconds - sync_max_chat_age: 259200 - - # Whether or not to sync with custom puppets to receive EDUs that - # are not normally sent to appservices. - sync_with_custom_puppets: true - # Whether or not to update the m.direct account data event when double puppeting is enabled. - # Note that updating the m.direct event is not atomic (except with mautrix-asmux) - # and is therefore prone to race conditions. - sync_direct_chat_list: false - # When double puppeting is enabled, users can use `!wa toggle` to change whether or not - # presence and read receipts are bridged. These settings set the default values. - # Existing users won't be affected when these are changed. - default_bridge_receipts: true - default_bridge_presence: true - # Shared secret for https://github.com/devture/matrix-synapse-shared-secret-auth - # - # If set, custom puppets will be enabled automatically for local users - # instead of users having to find an access token and run `login-matrix` - # manually. - login_shared_secret: null - - # Whether or not to invite own WhatsApp user's Matrix puppet into private - # chat portals when backfilling if needed. - # This always uses the default puppet instead of custom puppets due to - # rate limits and timestamp massaging. - invite_own_puppet_for_backfilling: true - # Whether or not to explicitly set the avatar and room name for private - # chat portal rooms. This can be useful if the previous field works fine, - # but causes room avatar/name bugs. - private_chat_portal_meta: false - # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run. - # This field will automatically be changed back to false after it, - # except if the config file is not writable. - resend_bridge_info: false - - # Whether or not thumbnails from WhatsApp should be sent. - # They're disabled by default due to very low resolution. - whatsapp_thumbnail: false - - # Allow invite permission for user. User can invite any bots to room with whatsapp - # users (private chat and groups) - allow_user_invite: false - - # The prefix for commands. Only required in non-management rooms. - command_prefix: "!wa" - - # End-to-bridge encryption support options. This requires login_shared_secret to be configured - # in order to get a device for the bridge bot. - # - # Additionally, https://github.com/matrix-org/synapse/pull/5758 is required if using a normal - # application service. - encryption: - # Allow encryption, work in group chat rooms with e2ee enabled - allow: false - # Default to encryption, force-enable encryption in all portals the bridge creates - # This will cause the bridge bot to be in private chats for the encryption to work properly. - # It is recommended to also set private_chat_portal_meta to true when using this. - default: false - # Options for automatic key sharing. - key_sharing: - # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. - # You must use a client that supports requesting keys from other users to use this feature. - allow: false - # Require the requesting device to have a valid cross-signing signature? - # This doesn't require that the bridge has verified the device, only that the user has verified it. - # Not yet implemented. - require_cross_signing: false - # Require devices to be verified by the bridge? - # Verification by the bridge is not yet implemented. - require_verification: true - - # Permissions for using the bridge. - # Permitted values: - # relaybot - Talk through the relaybot (if enabled), no access otherwise - # user - Access to use the bridge to chat with a WhatsApp account. - # admin - User level and some additional administration tools - # Permitted keys: - # * - All Matrix users - # domain - All users on that homeserver - # mxid - Specific user - permissions: - "*": relaybot - "@eu:euandreh.xyz": admin - "@eu:matrix.euandreh.xyz": admin - - relaybot: - # Whether or not relaybot support is enabled. - enabled: false - # The management room for the bot. This is where all status notifications are posted and - # in this room, you can use `!wa ` instead of `!wa relaybot `. Omitting - # the command prefix completely like in user management rooms is not possible. - management: !foo:example.com - # List of users to invite to all created rooms that include the relaybot. - invites: [] - # The formats to use when sending messages to WhatsApp via the relaybot. - message_formats: - m.text: "{{ .Sender.Displayname }}: {{ .Message }}" - m.notice: "{{ .Sender.Displayname }}: {{ .Message }}" - m.emote: "* {{ .Sender.Displayname }} {{ .Message }}" - m.file: "{{ .Sender.Displayname }} sent a file" - m.image: "{{ .Sender.Displayname }} sent an image" - m.audio: "{{ .Sender.Displayname }} sent an audio file" - m.video: "{{ .Sender.Displayname }} sent a video" - m.location: "{{ .Sender.Displayname }} sent a location" - -# Logging config. -logging: - # The directory for log files. Will be created if not found. - directory: ./logs - # Available variables: .Date for the file date and .Index for different log files on the same day. - file_name_format: "{{.Date}}-{{.Index}}.log" - # Date format for file names in the Go time format: https://golang.org/pkg/time/#pkg-constants - file_date_format: 2006-01-02 - # Log file permissions. - file_mode: 0600 - # Timestamp format for log entries in the Go time format. - timestamp_format: Jan _2, 2006 15:04:05 - # Minimum severity for log messages. - # Options: debug, info, warn, error, fatal - print_level: debug diff --git a/nixos-switch.sh b/nixos-switch.sh index b53fbe4..a2d7fd3 100755 --- a/nixos-switch.sh +++ b/nixos-switch.sh @@ -22,7 +22,8 @@ envsubst < envsubst-configuration.nix | ssh "$TLD" 'cat > /etc/nixos/envsubst-co echo "${USER_PASSWORD}" | ssh "$TLD" sudo -S "\ sudo chown nextcloud:users ${SECRETS_ROOT}/nextcloud-admin.txt; \ sudo chown nextcloud:users ${SECRETS_ROOT}/nextcloud-database.txt;" -scp mautrix-whatsapp.yaml "${TLD}:~/config.yaml" +scp mautrix-whatsapp-config.yaml "${TLD}:/data/" +scp secrets/mautrix-telegram-config.yaml "${TLD}:/data/" # Run nixos-rebuild scp vps-configuration.nix "${TLD}:/etc/nixos/configuration.nix" diff --git a/secrets/mautrix-telegram-config.yaml b/secrets/mautrix-telegram-config.yaml new file mode 100644 index 0000000..6f7b106 Binary files /dev/null and b/secrets/mautrix-telegram-config.yaml differ diff --git a/secrets/telegram.org b/secrets/telegram.org new file mode 100644 index 0000000..75514e5 Binary files /dev/null and b/secrets/telegram.org differ diff --git a/vps-configuration.nix b/vps-configuration.nix index 35694da..6c8464f 100644 --- a/vps-configuration.nix +++ b/vps-configuration.nix @@ -37,7 +37,6 @@ let matrixServerJSON = { "m.server" = "${matrixDomain}:443"; }; matrixClientJSON = { "m.homeserver" = { "base_url" = "https://${TLD}"; }; }; matrixPort = 8008; - mautrixWappDir = "/home/${envsubstConfiguration.userName}/mautrix-wapp"; }; staticSiteFromRepo = repoName: pkgs.stdenv.mkDerivation { @@ -67,20 +66,23 @@ let poetry run flask inicializar-banco poetry run waitress-serve --host localhost --port ${config.piresProdPort} --call pires:create_app '').overrideAttrs (baseAttrs: { buildInputs = with pkgs; [ git poetry ]; }); - mautrix-wapp = (pkgs.writeShellScriptBin "run-mautrix-wapp.sh" '' - set -x - DIR=${config.mautrixWappDir} + mautrix-whatsapp = pkgs.writeShellScriptBin "run-mautrix-whatsapp.sh" '' + pushd $HOME + mkdir -p logs + ${pkgsUnstable.mautrix-whatsapp}/bin/mautrix-whatsapp -g -c /data/mautrix-whatsapp-config.yaml -r /data/mautrix-whatsapp-registration.yaml + ${pkgsUnstable.mautrix-whatsapp}/bin/mautrix-whatsapp -c /data/mautrix-whatsapp-config.yaml + ''; + mautrix-telegram = pkgs.writeShellScriptBin "run-mautrix-telegram.sh" '' + DIR=$HOME/mautrix-telegram if [[ ! -d "$DIR" ]]; then - git clone https://github.com/tulir/mautrix-whatsapp.git "$DIR" + ${pkgs.git}/bin/git clone https://github.com/tulir/mautrix-telegram.git "$DIR" fi pushd "$DIR" - git pull - ./build.sh - cp ../config.yaml . - ./mautrix-whatsapp -g - cp registration.yaml /data/ - ./mautrix-whatsapp - '').overrideAttrs (baseAttrs: { buildInputs = with pkgs; [ git olm go ]; }); + ${pkgs.git}/bin/git pull + ${pkgsUnstable.mautrix-telegram}/bin/mautrix-telegram -g -c /data/mautrix-telegram-config.yaml -r /data/mautrix-telegram-registration.yaml + ${pkgs.python3Packages.alembic}/bin/alembic -x config=/data/mautrix-telegram-config.yaml upgrade head + ${pkgsUnstable.mautrix-telegram}/bin/mautrix-telegram -c /data/mautrix-telegram-config.yaml + ''; in { nix = { binaryCaches = [ "https://euandreh.cachix.org" ]; @@ -108,6 +110,8 @@ in { gotop matrix-synapse poetry + pkgsUnstable.mautrix-whatsapp + pkgsUnstable.mautrix-telegram ]; networking.firewall.allowedTCPPorts = [ @@ -397,7 +401,10 @@ in { compress = false; }]; }]; - app_service_config_files = [ "/data/registration.yaml" ]; + app_service_config_files = [ + "/data/mautrix-whatsapp-registration.yaml" + # "/data/mautrix-telegram-registration.yaml" + ]; }; }; @@ -458,7 +465,21 @@ in { # Service serviceConfig = { User = "${envsubstConfiguration.userName}"; - ExecStart = "${mautrix-wapp}/bin/run-mautrix-wapp.sh"; + ExecStart = "${mautrix-whatsapp}/bin/run-mautrix-whatsapp.sh"; + Restart = "always"; + }; + # Install + wantedBy = [ "multi-user.target" ]; + }; + "mautrix-telegram" = { + enable = false; + # Unit + description = "mautrix-telegram systemd service"; + after = [ "network.target" ]; + # Service + serviceConfig = { + User = "${envsubstConfiguration.userName}"; + ExecStart = "${mautrix-telegram}/bin/run-mautrix-telegram.sh"; Restart = "always"; }; # Install -- cgit v1.2.3