System/machines/matrix/configuration.nix

209 lines
6.3 KiB
Nix
Raw Normal View History

2022-09-26 23:31:01 -04:00
{ config, lib, pkgs, inputs, ... }:
{
# Sops setup for this machine
sops.secrets = {
"borg-ssh-key" = {
sopsFile = ../../secrets/matrix/borg.yaml;
format = "yaml";
};
"borg-password" = {
sopsFile = ../../secrets/matrix/borg.yaml;
format = "yaml";
};
"matrix-secrets.yaml" = {
owner = "matrix-synapse";
format = "binary";
sopsFile = ../../secrets/matrix/recaptcha;
};
};
# Setup system configuration
nathan = {
services = {
nginx = {
enable = true;
acme = true;
};
matrix = {
2023-06-09 23:02:21 -04:00
enable = false;
2022-09-26 23:31:01 -04:00
baseDomain = "community.rs";
enableRegistration = true;
};
borg = {
enable = true;
extraExcludes = [
"*/.cache"
"*/.tmp"
"/var/lib/redis"
"/var/lib/docker"
"/var/log"
"/var/minecraft"
"/var/sharedstore"
];
passwordFile = config.sops.secrets."borg-password".path;
sshKey = config.sops.secrets."borg-ssh-key".path;
};
2023-06-01 09:24:42 -04:00
# postgresql.backup = true;
# Disabled for now due to lack of space :(, waiting for pendulum to get fixed so I can migrate over to it
postgresql.backup = false;
2022-09-26 23:31:01 -04:00
};
config = {
setupGrub = false;
nix = {
autoUpdate = true;
autoGC = true;
};
harden = false;
virtualization = { docker = true; };
2022-09-26 23:31:01 -04:00
};
};
# Configure bootloader
boot.loader.grub.enable = true;
boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only
boot.loader.grub.forceInstall = true;
boot.loader.timeout = 10;
boot.loader.grub.extraConfig = ''
serial --speed=19200 --unit=0 --word=8 --parity=no --stop=1;
terminal_input serial;
terminal_output serial
'';
boot.kernelParams = [ "console=ttyS0" ];
2022-09-26 23:31:01 -04:00
# Configure networking
networking = {
domain = "community.rs";
useDHCP = false;
interfaces.enp0s5.useDHCP = true;
nameservers = [ "1.1.1.1" ];
# Open ports in firewall
firewall = { };
};
2023-05-28 20:22:18 -04:00
# Set postgresql version
2023-06-01 09:24:42 -04:00
# services.postgresql.package = pkgs.postgresql_15;
2023-05-28 20:22:18 -04:00
2022-09-26 23:31:01 -04:00
# Setup home manager
home-manager.users.nathan = import ./home.nix;
# Create www-html group
users.groups.www-html.gid = 6848;
# Add shaurya
users.users.shaurya = {
isNormalUser = true;
home = "/home/shaurya";
description = "Shaurya";
extraGroups = [ "www-html" ];
openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDA8BwFgWGrX5is2rQV+T0dy4MUWhfpE5EzYxjgLuH1V shauryashubham1234567890@gmail.com"
];
shell = pkgs.nushell;
};
# Add www-html for my self
users.users.nathan = { extraGroups = [ "www-html" ]; };
2022-09-26 23:31:01 -04:00
# Configure matrix registration
2022-09-27 00:55:48 -04:00
services.matrix-synapse = {
settings = {
enable_registration_captcha = true;
allow_guest_access = false;
allow_public_rooms_over_federation = true;
experimental_features = { spaces_enabled = true; };
auto_join_rooms =
[ "#space:community.rs" "#rules:community.rs" "#info:community.rs" ];
turn_uris = [
2023-06-04 12:31:53 -04:00
# "turn:turn.community.rs:3478?transport=udp"
# "turn:turn.community.rs:3478?transport=tcp"
];
2023-06-04 12:31:53 -04:00
# turn_user_lifetime = "1h";
2022-09-27 00:55:48 -04:00
};
2022-09-26 23:31:01 -04:00
extraConfigFiles = [ config.sops.secrets."matrix-secrets.yaml".path ];
};
2023-03-03 19:52:10 -05:00
# Install our utilties
environment.systemPackages = with pkgs; [ matrix-synapse-tools.synadm ];
2022-09-27 00:55:48 -04:00
# Setup a task to cleanup the database
systemd.services.synapse-db-cleanup = {
serviceConfig = {
Type = "oneshot";
User = "postgres";
Group = "postgres";
};
path = with pkgs; [ matrix-synapse-tools.rust-synapse-compress-state ];
script = ''
2022-09-27 01:32:20 -04:00
synapse_auto_compressor -p "user=matrix-synapse password=synapse dbname=synapse host=localhost" -c 500 -n 100
2022-09-27 00:55:48 -04:00
'';
2022-09-26 23:40:13 -04:00
};
2022-09-27 01:32:20 -04:00
systemd.timers.synapse-db-cleanup = {
wantedBy = [ "timers.target" ];
partOf = [ "synapse-db-cleanup.service" ];
timerConfig = {
# Weekly on sunday mornings
OnCalendar = "Sun, 5:00";
Unit = "synapse-db-cleanup.service";
};
};
2022-09-26 23:40:13 -04:00
2022-09-26 23:31:01 -04:00
# Configure the vhost for the domain
services.nginx.virtualHosts = let
fqdn = let
join = hostName: domain:
hostName + lib.optionalString (domain != null) ".${domain}";
in join config.networking.hostName config.networking.domain;
in {
"${config.networking.domain}" = {
enableACME = true;
forceSSL = true;
2022-09-26 23:31:01 -04:00
locations."= /.well-known/matrix/server".extraConfig = let
# use 443 instead of the default 8448 port to unite
# the client-server and server-server port for simplicity
server = { "m.server" = "${fqdn}:443"; };
in ''
add_header Content-Type application/json;
return 200 '${builtins.toJSON server}';
'';
locations."= /.well-known/matrix/client".extraConfig = let
client = {
"m.homeserver" = { "base_url" = "https://${fqdn}"; };
"m.identity_server" = { "base_url" = "https://vector.im"; };
};
# ACAO required to allow element-web on any URL to request this json file
in ''
add_header Content-Type application/json;
add_header Access-Control-Allow-Origin *;
return 200 '${builtins.toJSON client}';
'';
locations."/".extraConfig = ''
rewrite ^(.*)$ http://www.community.rs$1 redirect;
'';
};
# Main domain
"www.community.rs" = {
enableACME = true;
forceSSL = true;
locations."= /.well-known/matrix/server".extraConfig = let
# use 443 instead of the default 8448 port to unite
# the client-server and server-server port for simplicity
server = { "m.server" = "${fqdn}:443"; };
in ''
add_header Content-Type application/json;
return 200 '${builtins.toJSON server}';
'';
locations."= /.well-known/matrix/client".extraConfig = let
client = {
"m.homeserver" = { "base_url" = "https://${fqdn}"; };
"m.identity_server" = { "base_url" = "https://vector.im"; };
};
# ACAO required to allow element-web on any URL to request this json file
in ''
add_header Content-Type application/json;
add_header Access-Control-Allow-Origin *;
return 200 '${builtins.toJSON client}';
'';
root = "/var/www";
2022-09-26 23:31:01 -04:00
};
};
2022-09-26 23:31:01 -04:00
}