1 import ../../make-test-python.nix ({pkgs, ...}:
3 cert = pkgs: pkgs.runCommand "selfSignedCerts" { buildInputs = [ pkgs.openssl ]; } ''
4 openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes -subj '/CN=mastodon.local' -days 36500
6 cp key.pem cert.pem $out
10 192.168.2.103 mastodon.local
13 postgresqlPassword = "thisisnotasecret";
14 redisPassword = "thisisnotasecrettoo";
18 name = "mastodon-remote-postgresql";
19 meta.maintainers = with pkgs.lib.maintainers; [ erictapen izorkin ];
22 databases = { config, ... }: {
25 "redis/password-redis-db".text = redisPassword;
31 { address = "192.168.2.102"; prefixLength = 24; }
35 firewall.allowedTCPPorts = [
36 config.services.redis.servers.mastodon.port
37 config.services.postgresql.settings.port
41 services.redis.servers.mastodon = {
45 requirePassFile = "/etc/redis/password-redis-db";
48 services.postgresql = {
52 hostnossl mastodon mastodon 192.168.2.201/32 md5
54 ensureDatabases = [ "mastodon" ];
58 ensureDBOwnership = true;
61 initialScript = pkgs.writeText "postgresql_init.sql" ''
62 CREATE ROLE mastodon LOGIN PASSWORD '${postgresqlPassword}';
67 nginx = { nodes, ... }: {
71 { address = "192.168.2.103"; prefixLength = 24; }
75 firewall.allowedTCPPorts = [ 80 443 ];
79 pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
84 recommendedProxySettings = true;
85 virtualHosts."mastodon.local" = {
88 enableACME = pkgs.lib.mkForce false;
89 sslCertificate = "${cert pkgs}/cert.pem";
90 sslCertificateKey = "${cert pkgs}/key.pem";
92 tryFiles = "$uri @proxy";
94 locations."@proxy" = {
95 proxyPass = "http://192.168.2.201:${toString nodes.server.services.mastodon.webPort}";
96 proxyWebsockets = true;
102 server = { config, pkgs, ... }: {
103 virtualisation.memorySize = 2048;
107 "mastodon/password-redis-db".text = redisPassword;
108 "mastodon/password-posgressql-db".text = postgresqlPassword;
115 { address = "192.168.2.201"; prefixLength = 24; }
119 firewall.allowedTCPPorts = [
120 config.services.mastodon.webPort
121 config.services.mastodon.sidekiqPort
125 services.mastodon = {
127 configureNginx = false;
128 localDomain = "mastodon.local";
129 enableUnixSocket = false;
130 streamingProcesses = 2;
132 createLocally = false;
133 host = "192.168.2.102";
135 passwordFile = "/etc/mastodon/password-redis-db";
138 createLocally = false;
139 host = "192.168.2.102";
143 passwordFile = "/etc/mastodon/password-posgressql-db";
146 createLocally = false;
147 fromAddress = "mastodon@mastodon.local";
151 EMAIL_DOMAIN_ALLOWLIST = "example.com";
152 RAILS_SERVE_STATIC_FILES = "true";
153 TRUSTED_PROXY_IP = "192.168.2.103";
158 client = { pkgs, ... }: {
159 environment.systemPackages = [ pkgs.jq ];
163 { address = "192.168.2.202"; prefixLength = 24; }
170 pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
175 testScript = import ./script.nix {
178 nginx.wait_for_unit("nginx.service")
179 nginx.wait_for_open_port(443)
180 databases.wait_for_unit("redis-mastodon.service")
181 databases.wait_for_unit("postgresql.service")
182 databases.wait_for_open_port(31637)
183 databases.wait_for_open_port(5432)