2023-05-27 16:57:28 +01:00
|
|
|
{ lib, ... }:
|
|
|
|
let
|
|
|
|
inherit (lib.my) net;
|
2023-11-16 13:28:32 +00:00
|
|
|
inherit (lib.my.c) pubDomain;
|
2023-11-02 13:41:50 +00:00
|
|
|
inherit (lib.my.c.colony) domain prefixes;
|
2023-05-27 16:57:28 +01:00
|
|
|
in
|
|
|
|
{
|
2023-11-16 21:42:30 +00:00
|
|
|
nixos.systems.chatterbox = { config, ... }: {
|
2022-06-10 22:14:42 +01:00
|
|
|
system = "x86_64-linux";
|
|
|
|
nixpkgs = "mine";
|
2023-11-16 21:42:30 +00:00
|
|
|
rendered = config.configuration.config.my.asContainer;
|
2022-06-10 22:14:42 +01:00
|
|
|
|
|
|
|
assignments = {
|
|
|
|
internal = {
|
|
|
|
name = "chatterbox-ctr";
|
2023-05-27 16:57:28 +01:00
|
|
|
inherit domain;
|
|
|
|
ipv4.address = net.cidr.host 5 prefixes.ctrs.v4;
|
2022-06-10 22:14:42 +01:00
|
|
|
ipv6 = {
|
|
|
|
iid = "::5";
|
2023-05-27 16:57:28 +01:00
|
|
|
address = net.cidr.host 5 prefixes.ctrs.v6;
|
2022-06-10 22:14:42 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-06-10 23:25:55 +01:00
|
|
|
configuration = { lib, pkgs, config, assignments, allAssignments, ... }:
|
2022-06-10 22:14:42 +01:00
|
|
|
let
|
2024-06-10 13:27:02 +01:00
|
|
|
inherit (lib) genAttrs mkMerge mkIf mkForce;
|
2022-06-10 22:14:42 +01:00
|
|
|
inherit (lib.my) networkdAssignment;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
config = mkMerge [
|
|
|
|
{
|
|
|
|
my = {
|
|
|
|
deploy.enable = false;
|
|
|
|
server.enable = true;
|
|
|
|
|
|
|
|
secrets = {
|
2022-07-01 01:38:20 +01:00
|
|
|
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGGx50oGzm5TsaB5R6f/daFPc5QNkmM15uc9/kiBxKaY";
|
2022-07-10 18:16:35 +01:00
|
|
|
files = {
|
|
|
|
"chatterbox/synapse.yaml" = {
|
|
|
|
owner = "matrix-synapse";
|
|
|
|
group = "matrix-synapse";
|
|
|
|
};
|
|
|
|
"chatterbox/nul.ie.signing.key" = {
|
|
|
|
owner = "matrix-synapse";
|
|
|
|
group = "matrix-synapse";
|
|
|
|
};
|
2024-06-08 22:16:02 +01:00
|
|
|
"chatterbox/doublepuppet.yaml" = {
|
|
|
|
owner = "matrix-synapse";
|
|
|
|
group = "matrix-synapse";
|
|
|
|
};
|
|
|
|
|
|
|
|
"chatterbox/mautrix-whatsapp.env" = {
|
2024-06-09 01:46:00 +01:00
|
|
|
owner = "mautrix-whatsapp";
|
|
|
|
group = "mautrix-whatsapp";
|
2024-06-08 22:16:02 +01:00
|
|
|
};
|
2024-06-08 23:08:27 +01:00
|
|
|
"chatterbox/mautrix-messenger.env" = {
|
2024-06-09 01:46:00 +01:00
|
|
|
owner = "mautrix-meta-messenger";
|
|
|
|
group = "mautrix-meta";
|
|
|
|
};
|
|
|
|
"chatterbox/mautrix-instagram.env" = {
|
|
|
|
owner = "mautrix-meta-instagram";
|
|
|
|
group = "mautrix-meta";
|
2024-06-08 23:08:27 +01:00
|
|
|
};
|
2022-06-10 23:25:55 +01:00
|
|
|
};
|
2022-06-10 22:14:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
firewall = {
|
2023-11-07 19:20:27 +00:00
|
|
|
tcp.allowed = [ 19999 8008 8009 ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users = with lib.my.c.ids; {
|
|
|
|
users = {
|
2024-06-08 22:16:02 +01:00
|
|
|
matrix-synapse.extraGroups = [
|
|
|
|
"mautrix-whatsapp"
|
|
|
|
];
|
2022-06-10 22:14:42 +01:00
|
|
|
};
|
2024-11-25 22:13:54 +00:00
|
|
|
groups = { };
|
2022-06-10 22:14:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd = {
|
|
|
|
network.networks."80-container-host0" = networkdAssignment "host0" assignments.internal;
|
2024-11-25 22:13:54 +00:00
|
|
|
services = { } // (genAttrs [ "mautrix-whatsapp" "mautrix-meta-messenger" "mautrix-meta-instagram" ] (_: {
|
2024-06-10 13:27:02 +01:00
|
|
|
# ffmpeg needed to convert GIFs to video
|
|
|
|
path = with pkgs; [ ffmpeg ];
|
|
|
|
}));
|
2022-06-10 22:14:42 +01:00
|
|
|
};
|
|
|
|
|
2024-11-25 22:13:54 +00:00
|
|
|
# TODO/FIXME: https://github.com/NixOS/nixpkgs/issues/336052
|
|
|
|
nixpkgs.config.permittedInsecurePackages = [ "olm-3.2.16" ];
|
|
|
|
|
2022-06-10 22:14:42 +01:00
|
|
|
services = {
|
2022-06-13 01:12:01 +01:00
|
|
|
netdata.enable = true;
|
2022-06-10 23:25:55 +01:00
|
|
|
matrix-synapse = {
|
|
|
|
enable = true;
|
|
|
|
withJemalloc = true;
|
2023-08-27 18:59:07 +01:00
|
|
|
extras = [
|
|
|
|
"oidc"
|
|
|
|
];
|
2022-06-10 22:14:42 +01:00
|
|
|
|
2022-07-10 18:16:35 +01:00
|
|
|
extraConfigFiles = [ config.age.secrets."chatterbox/synapse.yaml".path ];
|
2022-06-10 23:25:55 +01:00
|
|
|
settings = {
|
|
|
|
server_name = "nul.ie";
|
|
|
|
public_baseurl = "https://matrix.nul.ie";
|
2023-11-16 13:28:32 +00:00
|
|
|
web_client_location = "https://element.${pubDomain}";
|
2022-06-10 23:25:55 +01:00
|
|
|
admin_contact = "dev@nul.ie";
|
|
|
|
prescence.enabled = true;
|
|
|
|
|
|
|
|
listeners = [
|
|
|
|
{
|
2022-06-11 01:20:32 +01:00
|
|
|
# Covers both IPv4 and IPv6
|
|
|
|
bind_addresses = [ "::" ];
|
2022-06-10 23:25:55 +01:00
|
|
|
port = 8008;
|
|
|
|
type = "http";
|
|
|
|
tls = false;
|
|
|
|
x_forwarded = true;
|
|
|
|
resources = [
|
|
|
|
{
|
|
|
|
compress = false;
|
|
|
|
names = [ "client" "federation" ];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
bind_addresses = [ "127.0.0.1" "::1" ];
|
2022-06-11 01:20:32 +01:00
|
|
|
port = 9000;
|
2022-06-10 23:25:55 +01:00
|
|
|
type = "manhole";
|
|
|
|
|
|
|
|
# The NixOS module has defaults for these that we need to override since they don't make sense here
|
|
|
|
tls = false;
|
|
|
|
resources = [];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
# Even public options must be in the secret file because options are only merged at the top level.
|
|
|
|
# Let's just override the defaults in the base config to keep Nix happy
|
|
|
|
database = {
|
|
|
|
name = "sqlite3";
|
|
|
|
args.database = "/dev/null";
|
|
|
|
};
|
|
|
|
|
|
|
|
#media_store_path = "/var/lib/synapse-media";
|
|
|
|
max_upload_size = "1024M";
|
|
|
|
dynamic_thumbnails = true;
|
|
|
|
url_preview_enabled = true;
|
|
|
|
url_preview_ip_range_blacklist = [
|
|
|
|
"127.0.0.0/8"
|
|
|
|
"10.0.0.0/8"
|
|
|
|
"172.16.0.0/12"
|
|
|
|
"192.168.0.0/16"
|
|
|
|
"100.64.0.0/10"
|
|
|
|
"192.0.0.0/24"
|
|
|
|
"169.254.0.0/16"
|
|
|
|
"192.88.99.0/24"
|
|
|
|
"198.18.0.0/15"
|
|
|
|
"192.0.2.0/24"
|
|
|
|
"198.51.100.0/24"
|
|
|
|
"203.0.113.0/24"
|
|
|
|
"224.0.0.0/4"
|
2022-07-10 18:16:35 +01:00
|
|
|
|
2022-06-10 23:25:55 +01:00
|
|
|
"::1/128"
|
|
|
|
"fe80::/10"
|
|
|
|
"fc00::/7"
|
|
|
|
"2001:db8::/32"
|
|
|
|
"ff00::/8"
|
|
|
|
"fec0::/10"
|
2023-11-02 13:41:50 +00:00
|
|
|
] ++ (with lib.my.c.colony.prefixes; [ all.v4 all.v6 ]);
|
2022-06-10 23:25:55 +01:00
|
|
|
url_preview_ip_range_whitelist =
|
|
|
|
with allAssignments.middleman.internal;
|
|
|
|
[ ipv4.address ipv6.address ];
|
|
|
|
|
|
|
|
enable_registration = false;
|
|
|
|
allow_guest_access = false;
|
2022-07-10 18:16:35 +01:00
|
|
|
|
|
|
|
signing_key_path = config.age.secrets."chatterbox/nul.ie.signing.key".path;
|
2022-07-22 00:45:25 +01:00
|
|
|
|
|
|
|
app_service_config_files = [
|
|
|
|
"/var/lib/heisenbridge/registration.yml"
|
2024-06-08 22:16:02 +01:00
|
|
|
config.age.secrets."chatterbox/doublepuppet.yaml".path
|
2022-07-22 00:45:25 +01:00
|
|
|
];
|
|
|
|
};
|
2023-11-07 19:20:27 +00:00
|
|
|
|
2024-03-18 20:23:52 +00:00
|
|
|
};
|
2022-07-22 00:45:25 +01:00
|
|
|
|
|
|
|
heisenbridge = {
|
|
|
|
enable = true;
|
|
|
|
homeserver = "http://localhost:8008";
|
|
|
|
owner = "@dev:nul.ie";
|
|
|
|
namespaces = {
|
|
|
|
users = [
|
|
|
|
{
|
|
|
|
exclusive = true;
|
|
|
|
regex = "@irc_.*";
|
|
|
|
}
|
|
|
|
];
|
2022-06-10 23:25:55 +01:00
|
|
|
};
|
|
|
|
};
|
2024-06-08 22:16:02 +01:00
|
|
|
|
|
|
|
mautrix-whatsapp = {
|
|
|
|
enable = true;
|
|
|
|
environmentFile = config.age.secrets."chatterbox/mautrix-whatsapp.env".path;
|
|
|
|
settings = {
|
|
|
|
homeserver = {
|
|
|
|
address = "http://localhost:8008";
|
|
|
|
domain = "nul.ie";
|
|
|
|
};
|
|
|
|
appservice = {
|
|
|
|
database = {
|
|
|
|
type = "postgres";
|
|
|
|
uri = "$MAU_WAPP_PSQL_URI";
|
|
|
|
};
|
|
|
|
id = "whatsapp2";
|
|
|
|
bot = {
|
|
|
|
username = "whatsapp2";
|
|
|
|
displayname = "WhatsApp Bridge Bot";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
bridge = {
|
|
|
|
username_template = "wapp2_{{.}}";
|
|
|
|
displayname_template = "{{or .BusinessName .PushName .JID}} (WA)";
|
|
|
|
personal_filtering_spaces = true;
|
|
|
|
delivery_receipts = true;
|
|
|
|
allow_user_invite = true;
|
|
|
|
url_previews = true;
|
|
|
|
command_prefix = "!wa";
|
|
|
|
login_shared_secret_map."nul.ie" = "$MAU_WAPP_DOUBLE_PUPPET_TOKEN";
|
|
|
|
encryption = {
|
|
|
|
allow = true;
|
|
|
|
default = true;
|
|
|
|
require = true;
|
|
|
|
};
|
|
|
|
permissions = {
|
|
|
|
"@dev:nul.ie" = "admin";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-06-08 23:08:27 +01:00
|
|
|
|
|
|
|
mautrix-meta.instances = {
|
|
|
|
messenger = {
|
|
|
|
enable = true;
|
|
|
|
registerToSynapse = true;
|
|
|
|
dataDir = "mautrix-messenger";
|
|
|
|
environmentFile = config.age.secrets."chatterbox/mautrix-messenger.env".path;
|
|
|
|
settings = {
|
|
|
|
homeserver = {
|
|
|
|
address = "http://localhost:8008";
|
|
|
|
domain = "nul.ie";
|
|
|
|
};
|
|
|
|
appservice = {
|
|
|
|
database = {
|
|
|
|
type = "postgres";
|
|
|
|
uri = "$MAU_FBM_PSQL_URI";
|
|
|
|
};
|
|
|
|
id = "fbm2";
|
|
|
|
bot = {
|
|
|
|
username = "messenger2";
|
|
|
|
displayname = "Messenger Bridge Bot";
|
|
|
|
avatar = "mxc://maunium.net/ygtkteZsXnGJLJHRchUwYWak";
|
|
|
|
};
|
|
|
|
};
|
2024-11-25 22:13:54 +00:00
|
|
|
network = {
|
|
|
|
mode = "messenger";
|
|
|
|
displayname_template = ''{{or .DisplayName .Username "Unknown user"}} (FBM)'';
|
|
|
|
};
|
2024-06-08 23:08:27 +01:00
|
|
|
bridge = {
|
|
|
|
username_template = "fbm2_{{.}}";
|
|
|
|
personal_filtering_spaces = true;
|
|
|
|
delivery_receipts = true;
|
|
|
|
management_room_text.welcome = "Hello, I'm a Messenger bridge bot.";
|
|
|
|
command_prefix = "!fbm";
|
|
|
|
login_shared_secret_map."nul.ie" = "$MAU_FBM_DOUBLE_PUPPET_TOKEN";
|
2024-06-09 01:46:00 +01:00
|
|
|
backfill = {
|
|
|
|
history_fetch_pages = 5;
|
|
|
|
};
|
|
|
|
encryption = {
|
|
|
|
allow = true;
|
|
|
|
default = true;
|
|
|
|
require = true;
|
|
|
|
};
|
|
|
|
permissions = {
|
|
|
|
"@dev:nul.ie" = "admin";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
instagram = {
|
|
|
|
enable = true;
|
|
|
|
registerToSynapse = true;
|
|
|
|
dataDir = "mautrix-instagram";
|
|
|
|
environmentFile = config.age.secrets."chatterbox/mautrix-instagram.env".path;
|
|
|
|
settings = {
|
|
|
|
homeserver = {
|
|
|
|
address = "http://localhost:8008";
|
|
|
|
domain = "nul.ie";
|
|
|
|
};
|
|
|
|
appservice = {
|
|
|
|
database = {
|
|
|
|
type = "postgres";
|
|
|
|
uri = "$MAU_IG_PSQL_URI";
|
|
|
|
};
|
|
|
|
id = "instagram";
|
|
|
|
bot = {
|
|
|
|
username = "instagram";
|
|
|
|
displayname = "Instagram Bridge Bot";
|
|
|
|
avatar = "mxc://maunium.net/JxjlbZUlCPULEeHZSwleUXQv";
|
|
|
|
};
|
|
|
|
};
|
2024-11-25 22:13:54 +00:00
|
|
|
network = {
|
|
|
|
mode = "instagram";
|
|
|
|
displayname_template = ''{{or .DisplayName .Username "Unknown user"}} (IG)'';
|
|
|
|
};
|
2024-06-09 01:46:00 +01:00
|
|
|
bridge = {
|
|
|
|
username_template = "ig_{{.}}";
|
|
|
|
personal_filtering_spaces = true;
|
|
|
|
delivery_receipts = true;
|
|
|
|
management_room_text.welcome = "Hello, I'm an Instagram bridge bot.";
|
|
|
|
command_prefix = "!ig";
|
|
|
|
login_shared_secret_map."nul.ie" = "$MAU_IG_DOUBLE_PUPPET_TOKEN";
|
|
|
|
backfill = {
|
|
|
|
history_fetch_pages = 5;
|
|
|
|
};
|
2024-06-08 23:08:27 +01:00
|
|
|
encryption = {
|
|
|
|
allow = true;
|
|
|
|
default = true;
|
|
|
|
require = true;
|
|
|
|
};
|
|
|
|
permissions = {
|
|
|
|
"@dev:nul.ie" = "admin";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-06-10 22:14:42 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
(mkIf config.my.build.isDevVM {
|
|
|
|
virtualisation = {
|
|
|
|
forwardPorts = [
|
|
|
|
{ from = "host"; host.port = 8080; guest.port = 80; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|