nix-home/modules/cloud/conduit/default.nix

76 lines
1.8 KiB
Nix
Raw Normal View History

2022-06-10 20:50:07 +00:00
{ pkgs, config, lib, ... }:
let
cfg = config.cloud.conduit;
in
with lib;
{
2023-03-31 14:48:33 +00:00
imports = [ ./heisenbridge.nix ];
2022-06-10 20:50:07 +00:00
options.cloud.conduit = {
enable = mkEnableOption "Enable the conduit server";
2022-07-05 16:51:33 +00:00
package = mkOption {
type = types.package;
default = pkgs.matrix-conduit;
};
2022-06-10 20:50:07 +00:00
host = mkOption {
type = types.str;
default = "m.nkagami.me";
};
port = mkOption {
type = types.int;
default = 6167;
};
allow_registration = mkOption {
type = types.bool;
default = false;
};
2022-06-10 21:37:19 +00:00
well-known_port = mkOption {
type = types.int;
default = 6166;
};
2022-06-10 20:50:07 +00:00
};
config.services.matrix-conduit = mkIf cfg.enable {
2022-07-05 16:51:33 +00:00
inherit (cfg) package;
2022-06-10 20:50:07 +00:00
enable = true;
settings.global = {
inherit (cfg) port allow_registration;
server_name = cfg.host;
database_backend = "rocksdb";
};
};
2022-06-10 21:37:19 +00:00
# Serving .well-known files
2022-06-11 16:06:20 +00:00
# This is a single .well-known/matrix/server file that points to the server,
# which is NOT on port 8448 since Cloudflare doesn't allow us to route HTTPS
# through that port.
2022-06-10 21:37:19 +00:00
config.services.nginx = mkIf cfg.enable {
enable = true;
virtualHosts.conduit-well-kwown = {
listen = [{ addr = "127.0.0.1"; port = cfg.well-known_port; }];
2022-06-11 16:06:20 +00:00
# Check https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/docs/configuring-well-known.md
# for the file structure.
2022-06-10 21:37:19 +00:00
root = pkgs.writeTextDir ".well-known/matrix/server" ''
{
"m.server": "${cfg.host}:443"
}
'';
};
};
config.cloud.traefik.hosts = mkIf cfg.enable {
conduit = { inherit (cfg) port host; };
conduit-well-kwown = {
port = cfg.well-known_port;
filter = "Host(`${cfg.host}`) && PathPrefix(`/.well-known`)";
};
2022-06-10 20:50:07 +00:00
};
}