DBFGLS5HV5W6BDTZYDWPHNWR4FA5JRC2VGJ2Q5DDRNBING44QYJAC DDCJ7QUNYCSS5BZBYAR5R633WI6I2DD6J3IGKXLEBYO6LWKXBNRAC YUCXZTMNS5QA3ZCVE3XENBZFDDZUV6Y24LVG57WKUDAZ47ACABVAC O5SNUGP5YLA6TCHW4VS66GKHBK7UZMCU4LVIAAZEDD2YDV6UAUTQC HWCVAVGHMRTGNMV7WXWM6XB6KMMZQCMZQXWHQV4MPKXZOCAOGXKAC UZUCVVZYTCBURTGFJZUQJPQCNKB43PP6LVT7ACTSMSB442GRVNYQC 4HN5LZRSOAODRIM57WBB35C66VO7BR4PGFINLUMTGNHULEK43CEQC RTBMBSBABSGTRICJ4AWBKWO3JJHBRKV6FGOMYPDD7X6SS6X35ZIQC V2RX2Y7VB7Y3BHX3ALK4GTCMFJATMLCKIAT4U3XCYZZZIUBIIZ5QC CTCIAQGFIKAIP7JGXIBYWNGE7A5QMF6U662OV3KZOT4HKIWOSTZQC UBB7TTAXVPQQCOVHACKWXSPV2NPARSHREYJB6J3RSEDZZIXPFGOAC LYPQCAOCFLN7SEEDGL736NUVJKB34SY5QBKGVMB2OAZHZJ5RDTFQC ATF3K2KSKMI6STPROVW54ZGLYM6S3XPB45AKAZODDKIXFR4HWYFAC fqdn = "matrix.${domain}";port = 8008;in{imports = [(self + /modules/nginx.nix)]++ (lib.collectNix ./. |> lib.remove ./default.nix);
fqdn = "matrix.${domain}";port = 8008;in{services.restic.backups.matrix = mkResticBackup "matrix" {paths = [ "/var/lib/matrix-synapse" ];timerConfig = {OnCalendar = "hourly";Persistent = true;};};
age.secrets.matrixSigningKey = {rekeyFile = self + /secrets/plum-matrix-signing-key.age;owner = "matrix-synapse";group = "matrix-synapse";};
systemd.services.matrix-synapse.serviceConfig = {# sandboxingPrivateTmp = true;ProtectSystem = "strict";ProtectHome = true;
age.secrets.matrixRegistrationSecret = {rekeyFile = self + /secrets/plum-matrix-registration-secret.age;owner = "matrix-synapse";group = "matrix-synapse";};
# fs restrictionsReadWritePaths = [ "/var/lib/matrix-synapse" ];
systemd.services.matrix-backup = {description = "Backup Matrix data and database";after = [ "matrix-synapse.service" ];script = ''mkdir -p /var/backup/matrixcp -r /var/lib/matrix-synapse /var/backup/matrix/$(date +%Y%m%d_%H%M%S)
# network restrictionsRestrictAddressFamilies = ["AF_INET""AF_INET6""AF_UNIX"];
systemd.services.matrix-synapse.serviceConfig = {# sandboxingPrivateTmp = true;ProtectSystem = "strict";ProtectHome = true;
listeners = [{inherit port;bind_addresses = [ "::1" ];type = "http";tls = false;x_forwarded = true; # behind reverse proxyresources = [{names = ["client""federation""media"];compress = false;}];}];
listeners = [{inherit port;bind_addresses = [ "::1" ];type = "http";tls = false;x_forwarded = true; # behind reverse proxyresources = [{names = ["client""federation""media"];compress = false;}
redis.enabled = true;max_upload_size = "512M";media_store_path = "/var/lib/matrix-synapse/media_store";url_preview_enabled = true;dynamic_thumbnails = true;signing_key_path = config.age.secrets.matrixSigningKey.path;registration_shared_secret = config.age.secrets.matrixRegistrationSecret.path;trusted_key_servers = [ ];extras = ["url-preview""user-search"
database.name = "sqlite3";database.args.database = "/var/lib/matrix-synapse/homeserver.db";
services.nginx.virtualHosts.${fqdn} = merge config.services.nginx.sslTemplate {extraConfig = ''${config.services.nginx.goatCounterTemplate}'';locations."/_matrix".proxyPass = "http://[::1]:${toString port}";locations."/_synapse/client".proxyPass = "http://[::1]:${toString port}";locations."/_synapse/admin".proxyPass = "http://[::1]:${toString port}";};
log_config = "/var/lib/matrix-synapse/log.yaml";log.root.level = "WARNING";
services.nginx.virtualHosts.${domain} = merge config.services.nginx.sslTemplate {locations."/.well-known/matrix/client".extraConfig = ''return 200 '{"m.homeserver": {"base_url": "https://${fqdn}"}}';'';
allow_public_rooms_without_auth = true;allow_public_rooms_over_federation = true;
cinnyBase ={pkgs,lib,config,...}:letinherit (lib.strings) toJSON;inherit (lib.lists) singleton;inherit (config.networking) domain hostName;inherit (config.myLib) merge;fqdn = "chat.${domain}";root = pkgs.cinny;cinnyConfig = {allowCustomHomeservers = false;homeserverList = [ domain ];defaultHomeserver = 0;
max_upload_size = "512M";
rooms = [ ];};};in{assertions = singleton {assertion = config.services.matrix-synapse.enable;message = "The Cinny module should be used on the host running Matrix, but you're trying to enable it on '${hostName}'.";};
signing_key_path = config.age.secrets.matrixSigningKey.path;registration_shared_secret = config.age.secrets.matrixRegistrationSecret.path;
locations."/".extraConfig = # nginx''proxy_hide_header Content-Security-Policy;add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval' ${domain} *.${domain}; object-src 'self' ${domain} *.${domain}; img-src 'self' data: https: blob:; base-uri 'self'; frame-ancestors 'self';" always;add_header X-Frame-Options DENY always;add_header X-Content-Type-Options nosniff always;add_header X-XSS-Protection "1; mode=block" always;add_header Permissions-Policy "camera=(), geolocation=(), payment=(), usb=()" always;add_header Referrer-Policy no-referrer always;'';
services.nginx.virtualHosts.${fqdn} = lib.merge config.services.nginx.sslTemplate {extraConfig = ''${config.services.nginx.goatCounterTemplate}'';locations."/_matrix".proxyPass = "http://[::1]:${toString port}";locations."/_synapse/client".proxyPass = "http://[::1]:${toString port}";locations."/_synapse/admin".proxyPass = "http://[::1]:${toString port}";};
rewrite ^/public/(.*)$ /public/$1 break;rewrite ^/assets/(.*)$ /assets/$1 break;
services.nginx.virtualHosts.${domain} = lib.merge config.services.nginx.sslTemplate {locations."/.well-known/matrix/client".extraConfig = ''return 200 '{"m.homeserver": {"base_url": "https://${fqdn}"}}';'';
rewrite ^(.+)$ /index.html break;'';};
locations."/.well-known/matrix/server".extraConfig = ''return 200 '{"m.server": "${fqdn}:443"}';'';};
};in{flake.modules.nixos.matrix = matrixBase;flake.modules.nixos.cinny = cinnyBase;
inherit (config.networking) domain;inherit (lib) merge;inherit (lib.strings) toJSON;fqdn = "chat.${domain}";root = pkgs.cinny;cinnyConfig = {allowCustomHomeservers = false;hashRouter = {basename = "/";};featuredCommunities = {openAsDefault = false;servers = [domain"matrix.org"];spaces = [ ];rooms = [ ];};};imports = [ (self + /modules/nginx.nix) ];services.nginx.virtualHosts.${fqdn} = merge config.services.nginx.sslTemplate {inherit root;locations."= /config.json".extraConfig = /* nginx */ ''default_type application/json;return 200 '${toJSON cinnyConfig}';'';locations."/".extraConfig = /* nginx */ ''proxy_hide_header Content-Security-Policy;add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval' ${domain} *.${domain}; object-src 'self' ${domain} *.${domain}; img-src 'self' data: https: blob:; base-uri 'self'; frame-ancestors 'self';" always;add_header X-Frame-Options DENY always;add_header X-Content-Type-Options nosniff always;add_header X-XSS-Protection "1; mode=block" always;add_header Permissions-Policy "camera=(), geolocation=(), payment=(), usb=()" always;add_header Referrer-Policy no-referrer always;'';extraConfig = /* nginx */ ''rewrite ^/config.json$ /config.json break;rewrite ^/manifest.json$ /manifest.json break;rewrite ^/sw.js$ /sw.js break;rewrite ^/pdf.worker.min.js$ /pdf.worker.min.js break;rewrite ^/public/(.*)$ /public/$1 break;rewrite ^/assets/(.*)$ /assets/$1 break;rewrite ^(.+)$ /index.html break;'';};}in{enabled = false;homeserverList = [ domain ];defaultHomeserver = 0;{self,config,lib,pkgs,...}:let