2023-02-17 20:39:15 +00:00
|
|
|
{ config, pkgs, inputs, lib, ... }:
|
|
|
|
let
|
2023-07-07 07:00:12 +01:00
|
|
|
newestPackages = inputs.nixpkgs-master.legacyPackages.${pkgs.system};
|
|
|
|
package = newestPackages.mastodon;
|
2022-11-26 11:10:35 +00:00
|
|
|
domain = "peninsula.industries";
|
|
|
|
streamingPort = 55000;
|
|
|
|
webPort = 55001;
|
2023-05-08 12:03:29 +01:00
|
|
|
postgresPort = 5432;
|
2022-11-26 11:10:35 +00:00
|
|
|
path = "/var/lib/mastodon/";
|
2022-12-03 22:16:39 +00:00
|
|
|
mailgunSmtpSecretName = "mastodon-mailgun-smtp-password";
|
2022-11-26 11:10:35 +00:00
|
|
|
mailgunSmtpPasswordPath = "/run/secrets/${mailgunSmtpSecretName}";
|
|
|
|
mastodonDbSecretName = "mastodon-db";
|
|
|
|
mastodonDbSecretPath = "/run/secrets/${mastodonDbSecretName}";
|
|
|
|
uid = 2049;
|
|
|
|
gid = 3049;
|
|
|
|
systemUserName = "mastodon";
|
|
|
|
systemGroupName = "mastodon";
|
2022-11-26 21:13:04 +00:00
|
|
|
users = {
|
|
|
|
users."${systemUserName}" = {
|
2022-12-02 13:41:20 +00:00
|
|
|
inherit uid;
|
2022-11-26 21:13:04 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
isNormalUser = false;
|
|
|
|
group = systemGroupName;
|
|
|
|
};
|
|
|
|
groups."${systemGroupName}" = {
|
2022-12-02 13:41:20 +00:00
|
|
|
inherit gid;
|
2023-02-17 20:39:15 +00:00
|
|
|
members = [ "${systemUserName}" "nginx" ];
|
2022-11-26 21:13:04 +00:00
|
|
|
};
|
|
|
|
};
|
2022-11-26 21:54:48 +00:00
|
|
|
secretSettings = {
|
|
|
|
owner = systemUserName;
|
|
|
|
group = systemGroupName;
|
|
|
|
};
|
|
|
|
publicPath = "${path}/public-system/";
|
2022-11-26 11:10:35 +00:00
|
|
|
in {
|
2023-02-17 20:39:15 +00:00
|
|
|
imports = [ ../nginx.nix ];
|
2023-07-06 22:41:43 +01:00
|
|
|
system.stateVersion = "23.05";
|
2022-11-26 11:10:35 +00:00
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
virtualHosts = {
|
|
|
|
"${domain}" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
2022-11-26 21:13:04 +00:00
|
|
|
root = "${package}/public/";
|
2022-11-26 11:10:35 +00:00
|
|
|
|
2023-02-17 20:39:15 +00:00
|
|
|
locations."/" = { tryFiles = "$uri @proxy"; };
|
2022-11-26 21:54:48 +00:00
|
|
|
locations."/system/".alias = "${publicPath}";
|
2022-11-26 11:10:35 +00:00
|
|
|
|
|
|
|
locations."@proxy" = {
|
2022-11-26 21:13:04 +00:00
|
|
|
proxyPass = "http://127.0.0.1:" + toString webPort;
|
2022-11-26 11:10:35 +00:00
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
locations."/api/v1/streaming/" = {
|
2022-11-26 21:13:04 +00:00
|
|
|
proxyPass = "http://127.0.0.1:" + toString streamingPort;
|
2022-11-26 11:10:35 +00:00
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-02-17 20:39:15 +00:00
|
|
|
sops.secrets."${mailgunSmtpSecretName}" = {
|
|
|
|
sopsFile = ./mailgun.sops.yaml;
|
|
|
|
path = mailgunSmtpPasswordPath;
|
|
|
|
} // secretSettings;
|
|
|
|
sops.secrets."${mastodonDbSecretName}" = {
|
|
|
|
sopsFile = ./mastodon-db.sops.yaml;
|
|
|
|
path = mastodonDbSecretPath;
|
|
|
|
} // secretSettings;
|
2022-11-26 21:13:04 +00:00
|
|
|
|
|
|
|
inherit users;
|
|
|
|
|
2022-11-26 21:54:48 +00:00
|
|
|
systemd.services.mastodon-make-path = {
|
|
|
|
script = ''
|
|
|
|
mkdir -p ${path}
|
|
|
|
chown -R ${systemUserName}:${systemGroupName} ${path}
|
|
|
|
mkdir -p ${publicPath}
|
|
|
|
chmod -R o-rwx ${publicPath}
|
|
|
|
chmod -R g-rwx ${publicPath}
|
|
|
|
chmod -R g+X ${publicPath}
|
|
|
|
chmod -R g+r ${publicPath}
|
2022-11-26 23:09:01 +00:00
|
|
|
chmod -R u+rwX ${publicPath}
|
2022-11-26 21:54:48 +00:00
|
|
|
'';
|
2023-02-26 12:05:55 +00:00
|
|
|
serviceConfig = { Type = "oneshot"; };
|
2023-02-17 20:39:15 +00:00
|
|
|
before = [ "container@mastodon.service" ];
|
2022-11-26 21:54:48 +00:00
|
|
|
};
|
|
|
|
|
2022-11-26 11:10:35 +00:00
|
|
|
containers.mastodon = {
|
|
|
|
autoStart = true;
|
|
|
|
forwardPorts = [
|
|
|
|
{
|
|
|
|
containerPort = streamingPort;
|
|
|
|
hostPort = streamingPort;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
containerPort = webPort;
|
|
|
|
hostPort = webPort;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
bindMounts = {
|
|
|
|
"${path}" = {
|
|
|
|
hostPath = "${path}";
|
|
|
|
isReadOnly = false;
|
|
|
|
};
|
|
|
|
"${mailgunSmtpPasswordPath}" = {
|
|
|
|
hostPath = "${mailgunSmtpPasswordPath}";
|
|
|
|
isReadOnly = true;
|
|
|
|
};
|
|
|
|
"${mastodonDbSecretPath}" = {
|
|
|
|
hostPath = "${mastodonDbSecretPath}";
|
|
|
|
isReadOnly = true;
|
|
|
|
};
|
|
|
|
};
|
2023-02-17 20:39:15 +00:00
|
|
|
config = { config, pkgs, lib, ... }: {
|
2023-07-06 22:41:43 +01:00
|
|
|
system.stateVersion = "23.05";
|
2022-11-26 11:10:35 +00:00
|
|
|
services.postgresql.port = postgresPort;
|
2023-02-17 20:39:15 +00:00
|
|
|
users = users // {
|
|
|
|
mutableUsers = false;
|
|
|
|
allowNoPasswordLogin = true;
|
|
|
|
};
|
2023-05-08 12:03:29 +01:00
|
|
|
systemd.services.mastodon-media-auto-remove = {
|
|
|
|
description = "Mastodon media auto remove";
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
EnvironmentFile = "/var/lib/mastodon/.secrets_env";
|
|
|
|
};
|
|
|
|
script = ''
|
|
|
|
/run/current-system/sw/bin/mastodon-tootctl media remove --days=8 --prune-profiles --include-follows -c1
|
|
|
|
/run/current-system/sw/bin/mastodon-tootctl media remove --days=8 --remove-headers --include-follows -c1
|
|
|
|
/run/current-system/sw/bin/mastodon-tootctl preview_cards remove --days=8
|
|
|
|
'';
|
|
|
|
startAt = "daily";
|
|
|
|
};
|
2022-11-26 11:10:35 +00:00
|
|
|
services.mastodon = {
|
|
|
|
enable = true;
|
2022-11-26 21:13:04 +00:00
|
|
|
inherit package;
|
2022-11-26 11:10:35 +00:00
|
|
|
localDomain = "${domain}";
|
|
|
|
user = systemUserName;
|
|
|
|
group = systemGroupName;
|
2023-05-08 12:03:29 +01:00
|
|
|
mediaAutoRemove.enable = false;
|
2022-11-26 11:10:35 +00:00
|
|
|
smtp = {
|
|
|
|
host = "smtp.eu.mailgun.org";
|
|
|
|
port = 465;
|
|
|
|
authenticate = true;
|
|
|
|
user = "postmaster@${domain}";
|
|
|
|
fromAddress = "Peninsula Industries Mastodon <mastodon@${domain}>";
|
|
|
|
createLocally = false;
|
|
|
|
passwordFile = "${mailgunSmtpPasswordPath}";
|
|
|
|
};
|
2023-05-08 12:03:29 +01:00
|
|
|
sidekiqThreads = 8;
|
2022-11-26 11:10:35 +00:00
|
|
|
extraConfig = {
|
|
|
|
SMTP_TLS = "true";
|
|
|
|
SMTP_ENABLE_STARTTLS_AUTO = "true";
|
2022-11-26 13:26:12 +00:00
|
|
|
SINGLE_USER_MODE = "true";
|
2022-11-26 21:13:04 +00:00
|
|
|
RAILS_SERVE_STATIC_FILES = "true";
|
2023-07-16 20:18:38 +01:00
|
|
|
AUTHORIZED_FETCH = "true";
|
|
|
|
DISALLOW_UNAUTHENTICATED_API_ACCESS = "true";
|
2022-11-26 11:10:35 +00:00
|
|
|
};
|
|
|
|
inherit streamingPort;
|
|
|
|
inherit webPort;
|
|
|
|
configureNginx = false;
|
|
|
|
enableUnixSocket = false;
|
|
|
|
database = {
|
|
|
|
port = postgresPort;
|
|
|
|
passwordFile = mastodonDbSecretPath;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|