2022-04-26 12:14:40 +00:00
|
|
|
{ pkgs, config, lib, ... }:
|
2022-04-25 16:47:49 +00:00
|
|
|
let
|
2022-04-26 08:10:54 +00:00
|
|
|
listenIPs = (import ../../utils/getInternalIP.nix config).listenIPs;
|
|
|
|
listenStatements = lib.concatStringsSep "\n" (builtins.map (ip: "listen ${ip}:443 http3;") listenIPs) + ''
|
|
|
|
add_header Alt-Svc 'h3=":443"';
|
|
|
|
'';
|
2022-04-25 16:47:49 +00:00
|
|
|
sopsConfig = {
|
|
|
|
owner = "mastodon";
|
|
|
|
restartUnits = [
|
|
|
|
"mastodon-streaming.service"
|
|
|
|
"mastodon-web.service"
|
|
|
|
"mastodon-sidekiq.service"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
./elasticsearch.nix
|
2022-04-26 08:42:42 +00:00
|
|
|
../../modules/mastodon.nix
|
2022-04-25 16:47:49 +00:00
|
|
|
];
|
|
|
|
services.mastodon = {
|
|
|
|
enable = true;
|
2022-04-26 08:20:21 +00:00
|
|
|
enableUnixSocket = false;
|
2022-04-25 16:47:49 +00:00
|
|
|
elasticsearch = {
|
|
|
|
host = "127.0.0.1";
|
|
|
|
};
|
|
|
|
localDomain = "chir.rs";
|
|
|
|
extraConfig = {
|
2022-04-26 08:40:11 +00:00
|
|
|
WEB_DOMAIN = "mastodon.chir.rs";
|
2022-04-25 16:47:49 +00:00
|
|
|
REDIS_NAMESPACE = "mastodon";
|
2022-04-25 17:01:55 +00:00
|
|
|
SINGLE_USER_MODE = "true";
|
|
|
|
REDIS_HOST = "127.0.0.1";
|
2022-04-25 18:22:16 +00:00
|
|
|
REDIS_PORT = toString config.services.redis.servers.mastodon.port;
|
2022-04-26 08:40:11 +00:00
|
|
|
S3_ENABLED = "true";
|
|
|
|
S3_BUCKET = "mastodon-chir-rs";
|
|
|
|
S3_REGION = "us-west-000";
|
|
|
|
S3_PROTOCOL = "https";
|
|
|
|
S3_HOSTNAME = "s3.us-west-000.backblazeb2.com";
|
2022-04-26 11:34:53 +00:00
|
|
|
S3_ENDPOINT = "https://s3.us-west-000.backblazeb2.com/";
|
2022-04-26 08:40:11 +00:00
|
|
|
S3_ALIAS_HOST = "mastodon-assets.chir.rs";
|
2022-04-27 08:48:02 +00:00
|
|
|
S3_OPEN_TIMEOUT = "120";
|
|
|
|
S3_READ_TIMEOUT = "120";
|
2022-04-28 07:42:56 +00:00
|
|
|
S3_MULTIPART_THRESHOLD = "5242880";
|
2022-04-25 16:47:49 +00:00
|
|
|
};
|
2022-04-25 17:01:55 +00:00
|
|
|
redis.createLocally = false;
|
2022-04-25 16:51:53 +00:00
|
|
|
otpSecretFile = config.sops.secrets."services/mastodon/otpSecret".path;
|
|
|
|
secretKeyBaseFile = config.sops.secrets."services/mastodon/secretKeyBase".path;
|
2022-04-25 16:47:49 +00:00
|
|
|
smtp = {
|
|
|
|
authenticate = true;
|
|
|
|
createLocally = false;
|
|
|
|
fromAddress = "mastodon@chir.rs";
|
|
|
|
host = "mail.chir.rs";
|
2022-04-25 16:51:53 +00:00
|
|
|
passwordFile = config.sops.secrets."services/mastodon/smtpPassword".path;
|
2022-04-25 16:47:49 +00:00
|
|
|
user = "mastodon@chir.rs";
|
|
|
|
};
|
2022-04-25 16:51:53 +00:00
|
|
|
vapidPrivateKeyFile = config.sops.secrets."services/mastodon/vapid/private".path;
|
|
|
|
vapidPublicKeyFile = config.sops.secrets."services/mastodon/vapid/public".path;
|
2022-04-26 08:40:11 +00:00
|
|
|
s3AccessKeyIdFile = config.sops.secrets."services/mastodon/s3/key_id".path;
|
2022-04-26 08:45:29 +00:00
|
|
|
s3SecretAccessKeyFile = config.sops.secrets."services/mastodon/s3/secret_key".path;
|
2022-04-25 16:47:49 +00:00
|
|
|
};
|
|
|
|
sops.secrets."services/mastodon/otpSecret" = sopsConfig;
|
|
|
|
sops.secrets."services/mastodon/secretKeyBase" = sopsConfig;
|
|
|
|
sops.secrets."services/mastodon/smtpPassword" = sopsConfig;
|
|
|
|
sops.secrets."services/mastodon/vapid/private" = sopsConfig;
|
|
|
|
sops.secrets."services/mastodon/vapid/public" = sopsConfig;
|
2022-04-26 08:40:11 +00:00
|
|
|
sops.secrets."services/mastodon/s3/key_id" = sopsConfig;
|
|
|
|
sops.secrets."services/mastodon/s3/secret_key" = sopsConfig;
|
2022-04-25 16:51:21 +00:00
|
|
|
|
2022-04-26 06:36:17 +00:00
|
|
|
services.nginx.virtualHosts =
|
|
|
|
let mastodon = {
|
2022-04-26 08:10:54 +00:00
|
|
|
listenAddresses = listenIPs;
|
2022-04-26 06:36:17 +00:00
|
|
|
root = "${config.services.mastodon.package}/public/";
|
|
|
|
locations."/system/".alias = "/var/lib/mastodon/public-system/";
|
2022-04-25 16:51:21 +00:00
|
|
|
|
2022-04-26 06:36:17 +00:00
|
|
|
locations."/" = {
|
|
|
|
tryFiles = "$uri @proxy";
|
|
|
|
};
|
|
|
|
locations."@proxy" = {
|
|
|
|
proxyPass = (if config.services.mastodon.enableUnixSocket then "http://unix:/run/mastodon-web/web.socket" else "http://127.0.0.1:${toString(config.services.mastodon.webPort)}");
|
|
|
|
proxyWebsockets = true;
|
2022-04-26 07:47:38 +00:00
|
|
|
extraConfig = ''
|
|
|
|
proxy_set_header X-Forwarded-Proto https;
|
|
|
|
'';
|
2022-04-26 06:36:17 +00:00
|
|
|
};
|
|
|
|
locations."/api/v1/streaming/" = {
|
|
|
|
proxyPass = (if config.services.mastodon.enableUnixSocket then "http://unix:/run/mastodon-streaming/streaming.socket" else "http://127.0.0.1:${toString(config.services.mastodon.streamingPort)}/");
|
|
|
|
proxyWebsockets = true;
|
2022-04-26 07:47:38 +00:00
|
|
|
extraConfig = ''
|
|
|
|
proxy_set_header X-Forwarded-Proto https;
|
|
|
|
'';
|
2022-04-26 06:36:17 +00:00
|
|
|
};
|
2022-04-25 16:51:21 +00:00
|
|
|
};
|
2022-04-26 06:36:17 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
"mastodon.chir.rs" = mastodon // {
|
|
|
|
sslCertificate = "/var/lib/acme/chir.rs/cert.pem";
|
|
|
|
sslCertificateKey = "/var/lib/acme/chir.rs/key.pem";
|
|
|
|
};
|
|
|
|
"mastodon.int.chir.rs" = mastodon // {
|
|
|
|
sslCertificate = "/var/lib/acme/int.chir.rs/cert.pem";
|
|
|
|
sslCertificateKey = "/var/lib/acme/int.chir.rs/key.pem";
|
|
|
|
};
|
2022-04-25 16:51:21 +00:00
|
|
|
};
|
2022-04-25 17:01:55 +00:00
|
|
|
services.redis.servers.mastodon = {
|
|
|
|
enable = true;
|
|
|
|
bind = "127.0.0.1";
|
|
|
|
databases = 1;
|
|
|
|
port = 6379;
|
|
|
|
};
|
2022-04-25 18:09:22 +00:00
|
|
|
users.users.mastodon.home = lib.mkForce (toString config.services.mastodon.package);
|
2022-04-26 12:14:40 +00:00
|
|
|
services.elasticsearch.package = pkgs.elasticsearch7;
|
2022-04-25 16:47:49 +00:00
|
|
|
}
|