{ config, pkgs, lib, ... }: let cfg = config.services.matrix-synapse; in { config = lib.mkIf cfg.enableUserDirWorker { services.matrix-synapse = { settings = { instance_map = { user_dir = { path = "/run/matrix-synapse/user_dir.sock"; }; }; update_user_directory_from_worker = "user_dir"; }; workers = { user_dir = { worker_app = "synapse.app.generic_worker"; worker_listeners = [ { type = "http"; path = "/run/matrix-synapse/user_dir.sock"; resources = [ { names = [ "replication" ]; compress = false; } ]; } { type = "http"; path = "/run/matrix-synapse/user_dir-client.sock"; resources = [ { names = [ "client" ]; compress = false; } ]; } ]; database = ( import ../db.nix { workerName = "user_dir"; dbGroup = "small"; } ); }; }; }; services.nginx.virtualHosts."${cfg.nginxVirtualHostName}" = { locations."~ ^/_matrix/client/(api/v1|r0|v3|unstable)/user_directory/search$" = { proxyPass = "http://unix:/run/matrix-synapse/user_dir-client.sock"; }; }; }; }