mastodon-container/mastodon-container.nix

145 lines
4.1 KiB
Nix
Raw Normal View History

2023-07-25 18:37:43 -07:00
{ config, lib, pkgs, ... }@toplevel:
with lib;
2024-01-17 12:57:19 -08:00
let cfg = config.services.mastodonContainer;
2023-07-25 18:37:43 -07:00
in {
2024-01-17 13:13:47 -08:00
options.services.mastodonContainer = with types; {
2024-01-17 12:57:19 -08:00
enable = mkEnableOption "Enable Mastodon running in an Arion container.";
2023-07-26 16:30:53 -07:00
2024-01-17 12:57:19 -08:00
domain = mkOption {
2023-07-26 16:30:53 -07:00
type = str;
2024-01-17 12:57:19 -08:00
description = "Domain name of this Mastodon instance.";
2023-07-26 16:30:53 -07:00
};
2024-01-17 12:57:19 -08:00
hostname = mkOption {
2023-07-25 18:37:43 -07:00
type = str;
2024-01-17 12:57:19 -08:00
description = "Hostname of the Mastodon server.";
default = toplevel.config.services.mastodonContainer.domain;
2023-07-25 18:37:43 -07:00
};
state-directory = mkOption {
type = str;
description = "Port at which to store server data.";
};
2023-07-26 09:25:12 -07:00
port = mkOption {
type = port;
description = "Port at which to serve Mastodon web requests.";
2024-01-17 13:08:19 -08:00
default = 55001;
2023-07-25 18:37:43 -07:00
};
2024-01-17 12:57:19 -08:00
environment-files = mkOption {
type = listOf str;
description =
"List of files with env variables to set for the Mastodon job.";
default = [ ];
2023-09-03 10:51:31 -07:00
};
2024-01-17 14:25:57 -08:00
streaming-processes = mkOption {
type = int;
description =
"Number of processes to use for Mastodon streaming. Recommended is (#cores - 1).";
default = 4;
};
2023-07-26 16:30:53 -07:00
smtp = {
2024-01-17 12:57:19 -08:00
host = mkOption {
2023-07-26 16:30:53 -07:00
type = str;
description = "Outgoing SMTP server.";
};
port = mkOption {
type = port;
description = "Outgoing SMTP server port.";
default = 25;
};
2024-01-17 12:57:19 -08:00
user = mkOption {
type = str;
description = "User as which to authenticate to the SMTP server.";
2024-01-17 13:08:19 -08:00
default = "mastodon";
2023-07-25 18:37:43 -07:00
};
2024-01-17 12:57:19 -08:00
password-file = mkOption {
2024-01-17 13:08:19 -08:00
type = nullOr str;
2024-01-17 12:57:19 -08:00
description = "Path to file containing SMTP password";
2023-07-26 16:30:53 -07:00
};
2024-01-17 12:57:19 -08:00
from-address = mkOption {
type = str;
description = "Address from which to send outgoing mail.";
default =
"${toplevel.config.services.mastodonContainer.smtp.user}@${toplevel.config.services.mastodonContainer.domain}";
2023-09-06 11:12:10 -07:00
};
};
2024-01-17 12:57:19 -08:00
};
2023-07-25 18:51:57 -07:00
2024-01-17 12:57:19 -08:00
config = mkIf cfg.enable {
2023-07-25 18:37:43 -07:00
virtualisation.arion.projects.mastodon.settings = let
image = { pkgs, ... }: {
project.name = "mastodon";
services = {
2024-01-17 12:57:19 -08:00
mastodon = { pkgs, ... }: {
service = {
restart = "always";
volumes = [
"postgres-data:/var/lib/postgres/data"
"redis-data:/var/lib/redis"
"mastodon-data:/var/lib/mastodon"
];
};
2024-01-17 14:12:39 -08:00
nixos = {
useSystemd = true;
configuration = {
boot.tmp.useTmpfs = true;
system.nssModules = mkForce [ ];
services = {
nscd.enable = false;
postgresql.enable = true;
mastodon = {
enable = true;
webPort = cfg.port;
localDomain = cfg.domain;
extraEnvFiles = cfg.environment-files;
smtp = {
inherit (cfg.smtp) host port user;
fromAddress = cfg.smtp.from-address;
authenticate = !isNull cfg.smtp.password-file;
passwordFile = cfg.smtp.password-file;
};
redis.createLocally = true;
database.createLocally = true;
configureNginx = true;
automaticMigrations = true;
2024-01-17 14:25:57 -08:00
streamingProcesses = cfg.streaming-processes;
2024-01-17 12:57:19 -08:00
};
nginx = {
virtualHosts."${cfg.hostname}" = {
forceSSL = false;
enableACME = false;
};
};
2024-01-17 12:57:19 -08:00
};
};
};
2023-07-25 18:37:43 -07:00
};
};
};
in { imports = [ image ]; };
2024-01-17 12:57:19 -08:00
services.nginx = {
enable = true;
recommendedProxySettings = true;
virtualHosts."${cfg.hostname}" = {
enableACME = true;
forceSSL = true;
2024-01-17 12:57:19 -08:00
locations."/" = {
2024-01-17 13:18:32 -08:00
proxyPass = "http://localhost:${toString cfg.port}";
2024-01-17 12:57:19 -08:00
proxyWebsockets = true;
};
};
};
2023-07-25 18:37:43 -07:00
};
}