2023-05-27 16:57:28 +01:00
|
|
|
{ lib, ... }:
|
|
|
|
let
|
2023-12-03 15:06:11 +00:00
|
|
|
inherit (lib) mkForce;
|
2023-05-27 16:57:28 +01:00
|
|
|
inherit (lib.my) net;
|
2023-11-02 13:41:50 +00:00
|
|
|
inherit (lib.my.c.colony) domain prefixes;
|
2023-05-27 16:57:28 +01:00
|
|
|
in
|
|
|
|
{
|
2023-11-16 21:42:30 +00:00
|
|
|
nixos.systems.toot = { config, ... }: {
|
2022-11-20 02:43:48 +00:00
|
|
|
system = "x86_64-linux";
|
|
|
|
nixpkgs = "mine";
|
2023-11-16 21:42:30 +00:00
|
|
|
rendered = config.configuration.config.my.asContainer;
|
2022-11-20 02:43:48 +00:00
|
|
|
|
|
|
|
assignments = {
|
|
|
|
internal = {
|
|
|
|
name = "toot-ctr";
|
2023-05-27 16:57:28 +01:00
|
|
|
inherit domain;
|
|
|
|
ipv4.address = net.cidr.host 8 prefixes.ctrs.v4;
|
2022-11-20 02:43:48 +00:00
|
|
|
ipv6 = {
|
|
|
|
iid = "::8";
|
2023-05-27 16:57:28 +01:00
|
|
|
address = net.cidr.host 8 prefixes.ctrs.v6;
|
2022-11-20 02:43:48 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
configuration = { lib, pkgs, config, assignments, allAssignments, ... }:
|
|
|
|
let
|
2023-02-19 17:39:15 +00:00
|
|
|
inherit (lib) mkMerge mkIf genAttrs;
|
|
|
|
inherit (lib.my) networkdAssignment systemdAwaitPostgres;
|
2022-11-20 02:43:48 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
config = mkMerge [
|
|
|
|
{
|
|
|
|
my = {
|
|
|
|
deploy.enable = false;
|
|
|
|
server.enable = true;
|
|
|
|
|
|
|
|
secrets = {
|
|
|
|
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILSslLkDe54AKYzxdtKD70zcU72W0EpYsfbdJ6UFq0QK";
|
|
|
|
files = genAttrs
|
|
|
|
(map (f: "toot/${f}") [
|
|
|
|
"postgres-password.txt"
|
|
|
|
"secret-key.txt"
|
|
|
|
"otp-secret.txt"
|
|
|
|
"vapid-key.txt"
|
|
|
|
"smtp-password.txt"
|
|
|
|
"s3-secret-key.txt"
|
|
|
|
])
|
|
|
|
(_: with config.services.mastodon; {
|
|
|
|
owner = user;
|
|
|
|
inherit group;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
firewall = {
|
|
|
|
tcp.allowed = [
|
|
|
|
19999
|
|
|
|
|
2023-12-03 15:06:11 +00:00
|
|
|
"http"
|
2022-11-20 02:43:48 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd = {
|
|
|
|
network.networks."80-container-host0" = networkdAssignment "host0" assignments.internal;
|
|
|
|
services = {
|
|
|
|
# No option to provide an S3 secret access key file :(
|
|
|
|
mastodon-init-dirs.script = ''
|
|
|
|
echo "AWS_SECRET_ACCESS_KEY=\""$(< ${config.age.secrets."toot/s3-secret-key.txt".path})"\"" >> /var/lib/mastodon/.secrets_env
|
|
|
|
'';
|
2023-02-19 17:39:15 +00:00
|
|
|
mastodon-init-db = systemdAwaitPostgres pkgs.postgresql "colony-psql";
|
2022-11-20 02:43:48 +00:00
|
|
|
|
|
|
|
# Can't use the extraConfig because these services expect a different format for the both family bind address...
|
|
|
|
mastodon-streaming.environment.BIND = "::";
|
|
|
|
mastodon-web.environment.BIND = "[::]";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services = {
|
|
|
|
netdata.enable = true;
|
|
|
|
mastodon = mkMerge [
|
2023-12-03 15:06:11 +00:00
|
|
|
rec {
|
2022-11-20 02:43:48 +00:00
|
|
|
enable = true;
|
2023-12-03 15:06:11 +00:00
|
|
|
localDomain = extraConfig.WEB_DOMAIN; # for nginx config
|
|
|
|
extraConfig = {
|
|
|
|
LOCAL_DOMAIN = "nul.ie";
|
|
|
|
WEB_DOMAIN = "toot.nul.ie";
|
|
|
|
};
|
2022-11-20 02:43:48 +00:00
|
|
|
|
|
|
|
secretKeyBaseFile = config.age.secrets."toot/secret-key.txt".path;
|
|
|
|
otpSecretFile = config.age.secrets."toot/otp-secret.txt".path;
|
|
|
|
vapidPrivateKeyFile = config.age.secrets."toot/vapid-key.txt".path;
|
|
|
|
vapidPublicKeyFile = toString (pkgs.writeText
|
|
|
|
"vapid-pubkey.txt"
|
|
|
|
"BAyRyD2pnLQtMHr3J5AzjNMll_HDC6ra1ilOLAUmKyhkEdbm7_OwKZUgw1UefY4CHEcv4OOX9TnnN2DOYYuPZu8=");
|
|
|
|
|
2023-12-03 15:06:11 +00:00
|
|
|
streamingProcesses = 4;
|
|
|
|
configureNginx = true;
|
2022-11-20 02:43:48 +00:00
|
|
|
|
|
|
|
database = {
|
|
|
|
createLocally = false;
|
|
|
|
host = "colony-psql";
|
|
|
|
user = "mastodon";
|
|
|
|
passwordFile = config.age.secrets."toot/postgres-password.txt".path;
|
|
|
|
name = "mastodon";
|
|
|
|
};
|
|
|
|
|
|
|
|
smtp = {
|
|
|
|
createLocally = false;
|
|
|
|
fromAddress = "Mastodon <toot@nul.ie>";
|
|
|
|
host = "mail.nul.ie";
|
|
|
|
port = 587;
|
|
|
|
authenticate = true;
|
|
|
|
user = "toot@nul.ie";
|
|
|
|
passwordFile = config.age.secrets."toot/smtp-password.txt".path;
|
|
|
|
};
|
|
|
|
extraConfig.SMTP_ENABLE_STARTTLS_AUTO = "true";
|
|
|
|
|
|
|
|
redis.createLocally = true;
|
|
|
|
|
2022-11-20 04:44:22 +00:00
|
|
|
mediaAutoRemove = {
|
|
|
|
enable = true;
|
|
|
|
olderThanDays = 30;
|
|
|
|
};
|
2022-11-20 02:43:48 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
extraConfig = {
|
|
|
|
S3_ENABLED = "true";
|
|
|
|
S3_BUCKET = "mastodon";
|
|
|
|
AWS_ACCESS_KEY_ID = "mastodon";
|
|
|
|
S3_ENDPOINT = "https://s3.nul.ie/";
|
|
|
|
S3_REGION = "eu-central-1";
|
|
|
|
S3_PROTOCOL = "https";
|
|
|
|
S3_HOSTNAME = "mastodon.s3.nul.ie";
|
|
|
|
|
|
|
|
S3_ALIAS_HOST = "mastodon.s3.nul.ie";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2023-12-03 15:06:11 +00:00
|
|
|
|
|
|
|
# Override some stuff since we are proxying upstream
|
|
|
|
nginx = {
|
|
|
|
recommendedProxySettings = mkForce false;
|
|
|
|
virtualHosts."${config.services.mastodon.localDomain}" =
|
|
|
|
let
|
|
|
|
extraConfig = ''
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
forceSSL = false;
|
|
|
|
enableACME = false;
|
|
|
|
locations = {
|
|
|
|
"@proxy" = { inherit extraConfig; };
|
|
|
|
"/api/v1/streaming/" = { inherit extraConfig; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-11-20 02:43:48 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
(mkIf config.my.build.isDevVM {
|
|
|
|
virtualisation = {
|
|
|
|
forwardPorts = with config.services.mastodon; [
|
|
|
|
{ from = "host"; guest.port = webPort; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|