2022-03-18 15:39:32 +01:00
|
|
|
import ../make-test-python.nix ({pkgs, ...}:
|
|
|
|
let
|
2022-11-25 12:03:43 +01:00
|
|
|
cert = pkgs: pkgs.runCommand "selfSignedCerts" { buildInputs = [ pkgs.openssl ]; } ''
|
|
|
|
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes -subj '/CN=mastodon.local' -days 36500
|
2022-03-18 15:39:32 +01:00
|
|
|
mkdir -p $out
|
2022-11-25 12:03:43 +01:00
|
|
|
cp key.pem cert.pem $out
|
2022-03-18 15:39:32 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
hosts = ''
|
2022-11-25 12:48:48 +01:00
|
|
|
192.168.2.101 mastodon.local
|
2022-03-18 15:39:32 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "mastodon";
|
2022-11-17 19:29:36 +01:00
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ erictapen izorkin turion ];
|
2022-03-18 15:39:32 +01:00
|
|
|
|
|
|
|
nodes = {
|
|
|
|
server = { pkgs, ... }: {
|
2022-11-06 19:53:30 +01:00
|
|
|
|
|
|
|
virtualisation.memorySize = 2048;
|
|
|
|
|
2022-03-18 15:39:32 +01:00
|
|
|
networking = {
|
|
|
|
interfaces.eth1 = {
|
|
|
|
ipv4.addresses = [
|
2022-11-25 12:48:48 +01:00
|
|
|
{ address = "192.168.2.101"; prefixLength = 24; }
|
2022-03-18 15:39:32 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
extraHosts = hosts;
|
|
|
|
firewall.allowedTCPPorts = [ 80 443 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
security = {
|
2022-11-25 12:03:43 +01:00
|
|
|
pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
|
2022-03-18 15:39:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
services.redis.servers.mastodon = {
|
|
|
|
enable = true;
|
|
|
|
bind = "127.0.0.1";
|
|
|
|
port = 31637;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.mastodon = {
|
|
|
|
enable = true;
|
|
|
|
configureNginx = true;
|
|
|
|
localDomain = "mastodon.local";
|
|
|
|
enableUnixSocket = false;
|
|
|
|
smtp = {
|
|
|
|
createLocally = false;
|
|
|
|
fromAddress = "mastodon@mastodon.local";
|
|
|
|
};
|
|
|
|
extraConfig = {
|
|
|
|
EMAIL_DOMAIN_ALLOWLIST = "example.com";
|
|
|
|
};
|
|
|
|
};
|
2022-11-25 12:03:43 +01:00
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
virtualHosts."mastodon.local" = {
|
|
|
|
enableACME = pkgs.lib.mkForce false;
|
|
|
|
sslCertificate = "${cert pkgs}/cert.pem";
|
|
|
|
sslCertificateKey = "${cert pkgs}/key.pem";
|
|
|
|
};
|
|
|
|
};
|
2022-03-18 15:39:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
client = { pkgs, ... }: {
|
|
|
|
environment.systemPackages = [ pkgs.jq ];
|
|
|
|
networking = {
|
|
|
|
interfaces.eth1 = {
|
|
|
|
ipv4.addresses = [
|
2022-11-25 12:48:48 +01:00
|
|
|
{ address = "192.168.2.102"; prefixLength = 24; }
|
2022-03-18 15:39:32 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
extraHosts = hosts;
|
|
|
|
};
|
|
|
|
|
|
|
|
security = {
|
2022-11-25 12:03:43 +01:00
|
|
|
pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
|
2022-03-18 15:39:32 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
start_all()
|
|
|
|
|
|
|
|
server.wait_for_unit("nginx.service")
|
|
|
|
server.wait_for_unit("redis-mastodon.service")
|
|
|
|
server.wait_for_unit("postgresql.service")
|
|
|
|
server.wait_for_unit("mastodon-sidekiq.service")
|
|
|
|
server.wait_for_unit("mastodon-streaming.service")
|
|
|
|
server.wait_for_unit("mastodon-web.service")
|
|
|
|
server.wait_for_open_port(55000)
|
|
|
|
server.wait_for_open_port(55001)
|
|
|
|
|
2022-11-25 12:48:48 +01:00
|
|
|
# Check that mastodon-media-auto-remove is scheduled
|
|
|
|
server.succeed("systemctl status mastodon-media-auto-remove.timer")
|
|
|
|
|
2022-03-18 15:39:32 +01:00
|
|
|
# Check Mastodon version from remote client
|
|
|
|
client.succeed("curl --fail https://mastodon.local/api/v1/instance | jq -r '.version' | grep '${pkgs.mastodon.version}'")
|
|
|
|
|
2022-11-25 12:48:48 +01:00
|
|
|
# Check access from remote client
|
|
|
|
client.succeed("curl --fail https://mastodon.local/about | grep 'Mastodon hosted on mastodon.local'")
|
|
|
|
client.succeed("curl --fail $(curl https://mastodon.local/api/v1/instance 2> /dev/null | jq -r .thumbnail) --output /dev/null")
|
|
|
|
|
|
|
|
# Simple check tootctl commands
|
2022-03-18 15:39:32 +01:00
|
|
|
# Check Mastodon version
|
2022-12-01 00:13:57 +01:00
|
|
|
server.succeed("mastodon-tootctl version | grep '${pkgs.mastodon.version}'")
|
2022-03-18 15:39:32 +01:00
|
|
|
|
|
|
|
# Manage accounts
|
2022-12-01 00:13:57 +01:00
|
|
|
server.succeed("mastodon-tootctl email_domain_blocks add example.com")
|
|
|
|
server.succeed("mastodon-tootctl email_domain_blocks list | grep example.com")
|
|
|
|
server.fail("mastodon-tootctl email_domain_blocks list | grep mastodon.local")
|
|
|
|
server.fail("mastodon-tootctl accounts create alice --email=alice@example.com")
|
|
|
|
server.succeed("mastodon-tootctl email_domain_blocks remove example.com")
|
|
|
|
server.succeed("mastodon-tootctl accounts create bob --email=bob@example.com")
|
|
|
|
server.succeed("mastodon-tootctl accounts approve bob")
|
|
|
|
server.succeed("mastodon-tootctl accounts delete bob")
|
2022-03-18 15:39:32 +01:00
|
|
|
|
|
|
|
# Manage IP access
|
2022-12-01 00:13:57 +01:00
|
|
|
server.succeed("mastodon-tootctl ip_blocks add 192.168.0.0/16 --severity=no_access")
|
|
|
|
server.succeed("mastodon-tootctl ip_blocks export | grep 192.168.0.0/16")
|
|
|
|
server.fail("mastodon-tootctl ip_blocks export | grep 172.16.0.0/16")
|
2022-03-18 15:39:32 +01:00
|
|
|
client.fail("curl --fail https://mastodon.local/about")
|
2022-12-01 00:13:57 +01:00
|
|
|
server.succeed("mastodon-tootctl ip_blocks remove 192.168.0.0/16")
|
2022-03-18 15:39:32 +01:00
|
|
|
client.succeed("curl --fail https://mastodon.local/about")
|
|
|
|
|
|
|
|
server.shutdown()
|
|
|
|
client.shutdown()
|
|
|
|
'';
|
|
|
|
})
|