1 { config, pkgs, lib, ... }:
6 dataDir = "/var/lib/mx-puppet-discord";
7 registrationFile = "${dataDir}/discord-registration.yaml";
8 cfg = config.services.mx-puppet-discord;
9 settingsFormat = pkgs.formats.json {};
10 settingsFile = settingsFormat.generate "mx-puppet-discord-config.json" cfg.settings;
14 services.mx-puppet-discord = {
15 enable = mkEnableOption (lib.mdDoc ''
16 mx-puppet-discord is a discord puppeting bridge for matrix.
17 It handles bridging private and group DMs, as well as Guilds (servers)
20 settings = mkOption rec {
21 apply = recursiveUpdate default;
22 inherit (settingsFormat) type;
29 provisioning.whitelist = [ ];
30 relay.whitelist = [ ];
32 # variables are preceded by a colon.
35 userOverride = ":displayname";
40 #defaults to sqlite but can be configured to use postgresql with
42 database.filename = "${dataDir}/database.db";
45 lineDateFormat = "MMM-D HH:mm:ss.SSS";
48 example = literalExpression ''
51 bindAddress = "localhost";
52 domain = "example.com";
53 homeserverUrl = "https://example.com";
56 provisioning.whitelist = [ "@admin:example.com" ];
57 relay.whitelist = [ "@.*:example.com" ];
60 description = lib.mdDoc ''
61 {file}`config.yaml` configuration as a Nix attribute set.
62 Configuration options should match those described in
64 sample.config.yaml](https://github.com/matrix-discord/mx-puppet-discord/blob/master/sample.config.yaml).
67 serviceDependencies = mkOption {
68 type = with types; listOf str;
69 default = optional config.services.matrix-synapse.enable "matrix-synapse.service";
70 defaultText = literalExpression ''
71 optional config.services.matrix-synapse.enable "matrix-synapse.service"
73 description = lib.mdDoc ''
74 List of Systemd services to require and wait for when starting the application service.
80 config = mkIf cfg.enable {
81 systemd.services.mx-puppet-discord = {
82 description = "Matrix to Discord puppeting bridge";
84 wantedBy = [ "multi-user.target" ];
85 wants = [ "network-online.target" ] ++ cfg.serviceDependencies;
86 after = [ "network-online.target" ] ++ cfg.serviceDependencies;
89 # generate the appservice's registration file if absent
90 if [ ! -f '${registrationFile}' ]; then
91 ${pkgs.mx-puppet-discord}/bin/mx-puppet-discord -r -c ${settingsFile} \
92 -f ${registrationFile}
100 ProtectSystem = "strict";
102 ProtectKernelTunables = true;
103 ProtectKernelModules = true;
104 ProtectControlGroups = true;
108 WorkingDirectory = pkgs.mx-puppet-discord;
109 StateDirectory = baseNameOf dataDir;
113 ${pkgs.mx-puppet-discord}/bin/mx-puppet-discord \
115 -f ${registrationFile}
121 meta.maintainers = with maintainers; [ govanify ];