dotfiles/modules/nixos/services/mastodon/default.nix

215 lines
5.2 KiB
Nix
Raw Normal View History

2024-10-06 15:25:05 -05:00
{
flake,
config,
pkgs,
lib,
...
2025-01-19 00:32:58 -06:00
}:
let
inherit (flake.config.machines.devices)
ceres
2025-01-08 19:06:14 -06:00
;
2025-02-02 21:16:28 -06:00
inherit (flake.config.services.instances) smtp mastodon web;
2024-10-19 18:22:29 -05:00
service = mastodon;
2025-01-19 00:37:20 -06:00
host = "${mastodon.subdomain}.${web.domains.url3}";
2024-10-19 18:22:29 -05:00
localhost = web.localhost.address0;
2025-01-19 00:32:58 -06:00
in
{
2024-10-06 15:25:05 -05:00
# If you need to start fresh for some reason, run these to create the new Admin account:
# sudo -u mastodon mastodon-tootctl accounts create nick --email=nick@localhost --confirmed --role=Owner
# sudo -u mastodon mastodon-tootctl accounts approve nick
# If you fuck up and lose the password, use this:
# sudo mastodon-tootctl accounts modify --reset-password nick
# If you really fuck up and name yourself wrong, use this shit
# sudo mastodon-tootctl accounts modify username --remove-role
2024-11-23 20:53:15 -06:00
# nixpkgs.overlays = [
# (
# final: prev: {
# mastodon = prev.mastodon.overrideAttrs (oldAttrs: {
# postPatch =
# (oldAttrs.postPatch or "")
# + ''
# patch -p1 < ${./chars.patch}
# '';
# });
# }
# )
# ];
2024-10-06 15:25:05 -05:00
services = {
mastodon = {
enable = true;
2024-12-19 23:35:16 -06:00
localDomain = host;
2024-10-06 15:25:05 -05:00
secretKeyBaseFile = "/var/lib/mastodon/secrets/secret-key-base";
streamingProcesses = 7;
trustedProxy = localhost;
automaticMigrations = true;
database = {
createLocally = true;
2024-10-19 18:22:29 -05:00
name = service.name;
2024-10-06 15:25:05 -05:00
host = "/run/postgresql";
2024-10-19 18:22:29 -05:00
user = service.name;
2024-10-06 15:25:05 -05:00
passwordFile = config.sops.secrets.mastodon-database.path;
};
extraConfig = {
SINGLE_USER_MODE = "true";
SMTP_AUTH_METHOD = "plain";
SMTP_DELIVERY_METHOD = "smtp";
SMTP_ENABLE_STARTTLS_AUTO = "true";
SMTP_SSL = "false";
};
mediaAutoRemove = {
enable = true;
olderThanDays = 14;
};
redis = {
createLocally = true;
enableUnixSocket = true;
};
sidekiqThreads = 25;
sidekiqProcesses = {
all = {
2025-01-08 19:06:14 -06:00
jobClasses = [
];
2024-10-06 15:25:05 -05:00
threads = null;
};
default = {
2025-01-08 19:06:14 -06:00
jobClasses = [
"default"
];
2024-10-06 15:25:05 -05:00
threads = 5;
};
ingress = {
2025-01-08 19:06:14 -06:00
jobClasses = [
"ingress"
];
2024-10-06 15:25:05 -05:00
threads = 5;
};
push-pull = {
2025-01-08 19:06:14 -06:00
jobClasses = [
"push"
"pull"
];
2024-10-06 15:25:05 -05:00
threads = 5;
};
mailers = {
2025-01-08 19:06:14 -06:00
jobClasses = [
"mailers"
];
2024-10-06 15:25:05 -05:00
threads = 5;
};
};
smtp = {
authenticate = true;
createLocally = false;
2024-12-13 16:21:25 -06:00
fromAddress = "upRootNutrition <${service.email.address0}>";
2025-02-02 21:16:28 -06:00
host = smtp.hostname;
2024-10-06 15:25:05 -05:00
passwordFile = config.sops.secrets.mastodon-smtp.path;
2025-02-02 21:16:28 -06:00
port = smtp.ports.port0;
2024-10-19 18:22:29 -05:00
user = service.email.address0;
2024-10-06 15:25:05 -05:00
};
};
caddy = {
virtualHosts = {
"${host}" = {
extraConfig = ''
handle_path /system/* {
file_server * {
root /var/lib/mastodon/public-system
}
}
handle /api/v1/streaming/* {
reverse_proxy unix//run/mastodon-streaming/streaming.socket
}
route * {
file_server * {
root ${pkgs.mastodon}/public
pass_thru
}
reverse_proxy * unix//run/mastodon-web/web.socket
}
2024-10-19 18:22:29 -05:00
tls ${service.ssl.cert} ${service.ssl.key}
2024-10-06 15:25:05 -05:00
handle_errors {
root * ${pkgs.mastodon}/public
rewrite 500.html
file_server
}
encode gzip
header /* {
Strict-Transport-Security "max-age=31536000;"
}
header /emoji/* Cache-Control "public, max-age=31536000, immutable"
header /packs/* Cache-Control "public, max-age=31536000, immutable"
header /system/accounts/avatars/* Cache-Control "public, max-age=31536000, immutable"
header /system/media_attachments/files/* Cache-Control "public, max-age=31536000, immutable"
'';
};
};
};
};
2025-01-08 19:11:58 -06:00
systemd.services.caddy.serviceConfig.ReadWriteDirectories = lib.mkForce [
"/var/lib/caddy"
"/run/mastodon-web"
];
2024-10-06 15:25:05 -05:00
2025-01-19 00:32:58 -06:00
sops =
let
sopsPath = secret: {
path = "${service.sops.path0}/${service.name}-${secret}";
owner = service.name;
mode = "600";
};
in
{
secrets = builtins.listToAttrs (
map
(secret: {
name = "${service.name}-${secret}";
value = sopsPath secret;
})
[
"smtp"
"database"
"redis"
]
);
2024-10-06 15:25:05 -05:00
};
2024-10-19 18:22:29 -05:00
fileSystems."/var/lib/${service.name}" = {
device = service.paths.path0;
2024-10-06 15:25:05 -05:00
fsType = "none";
2025-01-08 19:06:14 -06:00
options = [
"bind"
];
2025-01-08 19:11:58 -06:00
depends = [
ceres.storage0.mount
2025-01-08 19:11:58 -06:00
];
2024-10-06 15:25:05 -05:00
};
systemd.tmpfiles.rules = [
2024-10-19 18:22:29 -05:00
"Z ${service.paths.path0} 0755 ${service.name} ${service.name} -"
"Z ${service.sops.path0} 0755 ${service.name} ${service.name} -"
2024-10-06 15:25:05 -05:00
];
2025-01-08 19:06:14 -06:00
users.users.${service.name}.extraGroups = [
"postgres"
];
2024-10-06 15:25:05 -05:00
networking = {
firewall = {
2025-01-08 19:06:14 -06:00
allowedTCPPorts = [
];
2024-10-06 15:25:05 -05:00
};
};
}