1# Mjolnir (Matrix Moderation Tool) {#module-services-mjolnir} 2 3This chapter will show you how to set up your own, self-hosted 4[Mjolnir](https://github.com/matrix-org/mjolnir) instance. 5 6As an all-in-one moderation tool, it can protect your server from 7malicious invites, spam messages, and whatever else you don't want. 8In addition to server-level protection, Mjolnir is great for communities 9wanting to protect their rooms without having to use their personal 10accounts for moderation. 11 12The bot by default includes support for bans, redactions, anti-spam, 13server ACLs, room directory changes, room alias transfers, account 14deactivation, room shutdown, and more. 15 16See the [README](https://github.com/matrix-org/mjolnir#readme) 17page and the [Moderator's guide](https://github.com/matrix-org/mjolnir/blob/main/docs/moderators.md) 18for additional instructions on how to setup and use Mjolnir. 19 20For [additional settings](#opt-services.mjolnir.settings) 21see [the default configuration](https://github.com/matrix-org/mjolnir/blob/main/config/default.yaml). 22 23## Mjolnir Setup {#module-services-mjolnir-setup} 24 25First create a new Room which will be used as a management room for Mjolnir. In 26this room, Mjolnir will log possible errors and debugging information. You'll 27need to set this Room-ID in [services.mjolnir.managementRoom](#opt-services.mjolnir.managementRoom). 28 29Next, create a new user for Mjolnir on your homeserver, if not present already. 30 31The Mjolnir Matrix user expects to be free of any rate limiting. 32See [Synapse #6286](https://github.com/matrix-org/synapse/issues/6286) 33for an example on how to achieve this. 34 35If you want Mjolnir to be able to deactivate users, move room aliases, shutdown rooms, etc. 36you'll need to make the Mjolnir user a Matrix server admin. 37 38Now invite the Mjolnir user to the management room. 39 40It is recommended to use [Pantalaimon](https://github.com/matrix-org/pantalaimon), 41so your management room can be encrypted. This also applies if you are looking to moderate an encrypted room. 42 43To enable the Pantalaimon E2E Proxy for mjolnir, enable 44[services.mjolnir.pantalaimon](#opt-services.mjolnir.pantalaimon.enable). This will 45autoconfigure a new Pantalaimon instance, which will connect to the homeserver 46set in [services.mjolnir.homeserverUrl](#opt-services.mjolnir.homeserverUrl) and Mjolnir itself 47will be configured to connect to the new Pantalaimon instance. 48 49```nix 50{ 51 services.mjolnir = { 52 enable = true; 53 homeserverUrl = "https://matrix.domain.tld"; 54 pantalaimon = { 55 enable = true; 56 username = "mjolnir"; 57 passwordFile = "/run/secrets/mjolnir-password"; 58 }; 59 protectedRooms = [ "https://matrix.to/#/!xxx:domain.tld" ]; 60 managementRoom = "!yyy:domain.tld"; 61 }; 62} 63``` 64 65### Element Matrix Services (EMS) {#module-services-mjolnir-setup-ems} 66 67If you are using a managed ["Element Matrix Services (EMS)"](https://ems.element.io/) 68server, you will need to consent to the terms and conditions. Upon startup, an error 69log entry with a URL to the consent page will be generated. 70 71## Synapse Antispam Module {#module-services-mjolnir-matrix-synapse-antispam} 72 73A Synapse module is also available to apply the same rulesets the bot 74uses across an entire homeserver. 75 76To use the Antispam Module, add `matrix-synapse-plugins.matrix-synapse-mjolnir-antispam` 77to the Synapse plugin list and enable the `mjolnir.Module` module. 78 79```nix 80{ 81 services.matrix-synapse = { 82 plugins = with pkgs; [ matrix-synapse-plugins.matrix-synapse-mjolnir-antispam ]; 83 extraConfig = '' 84 modules: 85 - module: mjolnir.Module 86 config: 87 # Prevent servers/users in the ban lists from inviting users on this 88 # server to rooms. Default true. 89 block_invites: true 90 # Flag messages sent by servers/users in the ban lists as spam. Currently 91 # this means that spammy messages will appear as empty to users. Default 92 # false. 93 block_messages: false 94 # Remove users from the user directory search by filtering matrix IDs and 95 # display names by the entries in the user ban list. Default false. 96 block_usernames: false 97 # The room IDs of the ban lists to honour. Unlike other parts of Mjolnir, 98 # this list cannot be room aliases or permalinks. This server is expected 99 # to already be joined to the room - Mjolnir will not automatically join 100 # these rooms. 101 ban_lists: 102 - "!roomid:example.org" 103 ''; 104 }; 105} 106```