1
0
Fork 0
dotfiles/system/nixos/mastodon.nix

127 lines
3 KiB
Nix
Raw Normal View History

2022-11-29 14:51:54 +00:00
{ config, secret, ... }:
2022-11-29 14:17:23 +00:00
2022-11-29 14:51:54 +00:00
let
web-domain = "mastodon.kempkens.io";
2022-11-29 15:51:16 +00:00
2022-11-29 15:52:49 +00:00
nginx-extra-proxy-settings = ''
proxy_set_header Host $host;
2022-11-29 16:45:06 +00:00
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
2022-11-29 15:52:49 +00:00
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
2022-12-20 16:47:13 +00:00
proxy_force_ranges on;
2022-11-29 15:52:49 +00:00
'';
2022-11-29 14:51:54 +00:00
in
2022-11-29 14:17:23 +00:00
{
services.mastodon = {
enable = true;
configureNginx = false;
localDomain = "kempkens.io";
streamingPort = 55000;
webPort = 55001;
sidekiqPort = 55002;
enableUnixSocket = true;
sidekiqThreads = 12;
2022-11-29 14:17:23 +00:00
2022-11-29 14:54:13 +00:00
trustedProxy = "127.0.0.1";
2022-11-29 14:17:23 +00:00
2023-02-05 19:32:19 +00:00
vapidPublicKeyFile = config.age.secrets.mastodon-vapid-public-key.path;
secretKeyBaseFile = config.age.secrets.mastodon-secret-key-base.path;
otpSecretFile = config.age.secrets.mastodon-otp-secret.path;
vapidPrivateKeyFile = config.age.secrets.mastodon-vapid-private-key.path;
2022-11-29 14:17:23 +00:00
database = {
createLocally = false;
host = "10.99.99.3";
port = 5432;
name = "mastodon";
inherit (secret.mastodon.database) user;
2023-02-05 19:32:19 +00:00
passwordFile = config.age.secrets.mastodon-database-password.path;
2022-11-29 14:17:23 +00:00
};
redis = {
createLocally = false;
host = "10.99.99.3";
port = 6379;
};
2022-12-23 16:08:24 +00:00
elasticsearch = {
host = "10.99.99.3";
port = 9200;
};
2022-11-29 14:17:23 +00:00
smtp = {
createLocally = false;
authenticate = true;
host = "smtp.mailgun.org";
2022-11-29 16:03:25 +00:00
port = 587;
2022-11-29 14:17:23 +00:00
fromAddress = "mastodon@mg.kempkens.io";
inherit (secret.mastodon.smtp) user;
2023-02-05 19:32:19 +00:00
passwordFile = config.age.secrets.mastodon-smtp-password.path;
2022-11-29 14:17:23 +00:00
};
automaticMigrations = true;
mediaAutoRemove = {
enable = true;
startAt = "daily";
2022-12-01 21:48:43 +00:00
olderThanDays = 14;
2022-11-29 14:17:23 +00:00
};
extraConfig = {
2022-11-29 14:51:54 +00:00
WEB_DOMAIN = web-domain;
};
extraEnvFiles = [ config.age.secrets.mastodon-extra-config.path ];
2022-11-29 14:51:54 +00:00
};
services.nginx = {
enable = true;
2023-02-20 19:24:34 +00:00
recommendedOptimisation = true;
recommendedGzipSettings = true;
recommendedBrotliSettings = true;
2022-11-29 14:51:54 +00:00
virtualHosts."${web-domain}" = {
2022-12-26 17:08:25 +00:00
listen = [
{
addr = "127.0.0.1";
port = 80;
}
];
2022-11-29 14:51:54 +00:00
root = "${config.services.mastodon.package}/public/";
forceSSL = false;
enableACME = false;
2022-12-27 21:46:05 +00:00
locations."/system/" = {
2022-12-27 21:57:05 +00:00
extraConfig = ''
rewrite ^/system/?(.*)$ https://mastodon-cdn.kempkens.io/$1 permanent;
'';
2022-12-27 21:46:05 +00:00
};
2022-11-29 14:51:54 +00:00
locations."/" = {
tryFiles = "$uri @proxy";
};
locations."@proxy" = {
proxyPass = "http://unix:/run/mastodon-web/web.socket";
2022-11-29 14:51:54 +00:00
proxyWebsockets = true;
2022-11-29 15:51:16 +00:00
extraConfig = nginx-extra-proxy-settings;
2022-11-29 14:51:54 +00:00
};
locations."/api/v1/streaming/" = {
proxyPass = "http://unix:/run/mastodon-streaming/streaming.socket";
2022-11-29 14:51:54 +00:00
proxyWebsockets = true;
2022-11-29 15:51:16 +00:00
extraConfig = nginx-extra-proxy-settings;
2022-11-29 14:51:54 +00:00
};
2022-11-29 14:17:23 +00:00
};
};
2022-11-29 23:16:26 +00:00
users.groups.mastodon.members = [ config.services.nginx.user ];
2022-11-29 14:17:23 +00:00
}