dotfiles/nixos/modules/services/peertube.nix

132 lines
3.1 KiB
Nix
Raw Normal View History

2024-10-06 15:25:05 -05:00
{
flake,
config,
pkgs,
...
}: let
2024-10-19 18:22:29 -05:00
inherit (flake.config.system.device) server;
inherit (flake.config.service.instance) caddy peertube web;
service = peertube;
localhost = web.localhost.address0;
host = "${service.subdomain}.${web.domains.url1}";
2024-10-06 15:25:05 -05:00
in {
services = {
peertube = {
configureNginx = false;
enable = true;
enableWebHttps = true;
2024-10-19 18:22:29 -05:00
group = service.name;
2024-10-06 15:25:05 -05:00
listenWeb = caddy.ports.port1;
2024-10-19 18:22:29 -05:00
listenHttp = service.ports.port0;
2024-10-06 15:25:05 -05:00
localDomain = host;
2024-10-19 18:22:29 -05:00
serviceEnvironmentFile = config.sops.secrets."${service.name}-root".path;
user = service.name;
2024-10-06 15:25:05 -05:00
plugins = {
enable = true;
plugins = with pkgs; [
peertube-plugin-livechat
peertube-plugin-matomo
peertube-plugin-transcoding-custom-quality
peertube-theme-dark
];
};
secrets = {
2024-10-19 18:22:29 -05:00
secretsFile = config.sops.secrets."${service.name}-secret".path;
2024-10-06 15:25:05 -05:00
};
settings = {
instance = {
name = "The Nutrivore";
};
log = {
level = "debug";
};
smtp = {
transport = "smtp";
disable_starttls = false;
2024-10-19 18:22:29 -05:00
from_address = service.email.address0;
2024-10-06 15:25:05 -05:00
hostname = "smtp.protonmail.ch";
port = 587;
2024-10-19 18:22:29 -05:00
username = service.email.address0;
2024-10-06 15:25:05 -05:00
tls = false;
};
};
database = {
createLocally = true;
2024-10-19 18:22:29 -05:00
passwordFile = config.sops.secrets."${service.name}-database".path;
2024-10-06 15:25:05 -05:00
};
redis = {
enableUnixSocket = true;
createLocally = true;
2024-10-19 18:22:29 -05:00
passwordFile = config.sops.secrets."${service.name}-redis".path;
2024-10-06 15:25:05 -05:00
};
smtp = {
createLocally = true;
2024-10-19 18:22:29 -05:00
passwordFile = config.sops.secrets."${service.name}-smtp".path;
2024-10-06 15:25:05 -05:00
};
};
caddy = {
virtualHosts = {
${host} = {
extraConfig = ''
2024-10-19 18:22:29 -05:00
reverse_proxy ${localhost}:${toString service.ports.port0}
2024-10-06 15:25:05 -05:00
2024-10-19 18:22:29 -05:00
tls ${service.ssl.cert} ${service.ssl.key}
2024-10-06 15:25:05 -05:00
'';
};
};
};
};
sops = let
sopsPath = secret: {
2024-10-19 18:22:29 -05:00
path = "${service.sops.path0}/${service.name}-${secret}-pass";
owner = service.name;
2024-10-06 15:25:05 -05:00
mode = "600";
};
in {
secrets = builtins.listToAttrs (
map
(secret: {
2024-10-19 18:22:29 -05:00
name = "${service.name}-${secret}";
2024-10-06 15:25:05 -05:00
value = sopsPath secret;
})
2024-11-04 02:09:15 -06:00
[
"smtp"
"database"
"redis"
"root"
"secret"
]
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";
options = ["bind"];
depends = [server.storage0.mount];
};
systemd.tmpfiles.rules = [
2024-10-19 18:22:29 -05:00
"Z ${service.paths.path0} 755 ${service.name} ${service.name} -"
"Z ${service.sops.path0} 755 ${service.name} ${service.name} -"
2024-10-06 15:25:05 -05:00
];
2024-10-19 18:22:29 -05:00
users.users.${service.name}.extraGroups = ["nginx" "caddy"];
2024-10-06 15:25:05 -05:00
networking = {
firewall = {
allowedTCPPorts = [
2024-10-19 18:22:29 -05:00
service.ports.port0
service.ports.port1
service.ports.port2
service.ports.port3
service.ports.port4
2024-10-06 15:25:05 -05:00
];
};
};
}