1import ../../make-test-python.nix ({pkgs, ...}:
2let
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
5 mkdir -p $out
6 cp key.pem cert.pem $out
7 '';
8
9 hosts = ''
10 192.168.2.101 mastodon.local
11 '';
12
13in
14{
15 name = "mastodon-standard";
16 meta.maintainers = with pkgs.lib.maintainers; [ erictapen izorkin turion ];
17
18 nodes = {
19 server = { pkgs, ... }: {
20
21 virtualisation.memorySize = 2048;
22
23 networking = {
24 interfaces.eth1 = {
25 ipv4.addresses = [
26 { address = "192.168.2.101"; prefixLength = 24; }
27 ];
28 };
29 extraHosts = hosts;
30 firewall.allowedTCPPorts = [ 80 443 ];
31 };
32
33 security = {
34 pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
35 };
36
37 services.redis.servers.mastodon = {
38 enable = true;
39 bind = "127.0.0.1";
40 port = 31637;
41 };
42
43 # TODO remove once https://github.com/NixOS/nixpkgs/pull/266270 is resolved.
44 services.postgresql.package = pkgs.postgresql_14;
45
46 services.mastodon = {
47 enable = true;
48 configureNginx = true;
49 localDomain = "mastodon.local";
50 enableUnixSocket = false;
51 streamingProcesses = 2;
52 smtp = {
53 createLocally = false;
54 fromAddress = "mastodon@mastodon.local";
55 };
56 extraConfig = {
57 EMAIL_DOMAIN_ALLOWLIST = "example.com";
58 };
59 };
60
61 services.nginx = {
62 virtualHosts."mastodon.local" = {
63 enableACME = pkgs.lib.mkForce false;
64 sslCertificate = "${cert pkgs}/cert.pem";
65 sslCertificateKey = "${cert pkgs}/key.pem";
66 };
67 };
68 };
69
70 client = { pkgs, ... }: {
71 environment.systemPackages = [ pkgs.jq ];
72 networking = {
73 interfaces.eth1 = {
74 ipv4.addresses = [
75 { address = "192.168.2.102"; prefixLength = 24; }
76 ];
77 };
78 extraHosts = hosts;
79 };
80
81 security = {
82 pki.certificateFiles = [ "${cert pkgs}/cert.pem" ];
83 };
84 };
85 };
86
87 testScript = import ./script.nix {
88 inherit pkgs;
89 extraInit = ''
90 server.wait_for_unit("nginx.service")
91 server.wait_for_open_port(443)
92 server.wait_for_unit("postgresql.service")
93 server.wait_for_open_port(5432)
94 '';
95 };
96})