2025-08-23 05:02:47 +03:00
|
|
|
self: { pkgs, config, lib, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
mkOption
|
|
|
|
mkEnableOption
|
2025-08-23 05:34:30 +03:00
|
|
|
mkPackageOption
|
2025-08-23 05:02:47 +03:00
|
|
|
mkIf
|
|
|
|
types
|
|
|
|
;
|
|
|
|
|
|
|
|
cfg = config.services.synapse-revitalization;
|
|
|
|
in {
|
|
|
|
options.services.synapse-revitalization = {
|
|
|
|
enable = mkEnableOption "Enable synapse-revitalization service";
|
|
|
|
adminAuthTokenFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = "File containing admin user's authentication token";
|
|
|
|
};
|
|
|
|
serverKeyFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = "Synapse server signing key file";
|
|
|
|
default = "/var/lib/matrix-synapse/homeserver.signing.key";
|
|
|
|
};
|
|
|
|
serverName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Synapse server's name";
|
|
|
|
default = config.services.matrix-synapse.settings.server_name;
|
|
|
|
};
|
|
|
|
serverFQDN = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Synapse server's fqdn";
|
|
|
|
};
|
2025-08-23 05:34:30 +03:00
|
|
|
package = mkPackageOption pkgs "synapse-revitalization" {};
|
2025-08-23 05:02:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.enable) {
|
2025-08-23 05:34:30 +03:00
|
|
|
nixpkgs.overlays = [ self.overlays.default ];
|
2025-08-23 05:02:47 +03:00
|
|
|
systemd.services."synapse-revitalization" =
|
|
|
|
let pkg = "${pkgs.synapse-revitalization}/bin/synapse-revitalization";
|
|
|
|
script = pkgs.writeShellScript "synapse-revitalization-script" ''
|
|
|
|
journalctl -f -u matrix-synapse -o cat |
|
|
|
|
while read -r line; do
|
|
|
|
echo "$line" | grep "as we're not in the room" && ${pkg} "$line" &
|
|
|
|
echo "$line" | grep "Ignoring PDU for unknown room_id" && ${pkg} "$line" &
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
enable = true;
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
User = "root";
|
|
|
|
Group = "root";
|
|
|
|
ExecStart = script;
|
|
|
|
Restart = "always";
|
|
|
|
};
|
|
|
|
environment = {
|
|
|
|
"SYNAPSE_REVITALIZATION_ADMIN_AUTH_TOKEN_FILE" = cfg.adminAuthTokenFile;
|
|
|
|
"SYNAPSE_REVITALIZATION_SERVER_KEY_FILE" = cfg.serverKeyFile;
|
|
|
|
"SYNAPSE_REVITALIZATION_SERVER_NAME" = cfg.serverName;
|
|
|
|
"SYNAPSE_REVITALIZATION_SERVER_ADDRESS" = cfg.serverFQDN;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|