2025-02-14 18:44:35 +01:00
|
|
|
{ config, lib, ... }:
|
|
|
|
|
2025-02-14 19:46:12 +01:00
|
|
|
let
|
2025-02-15 11:19:10 +01:00
|
|
|
inherit (lib) mkIf mkMerge readFile;
|
2025-02-14 19:46:12 +01:00
|
|
|
|
|
|
|
in
|
2025-02-14 18:44:35 +01:00
|
|
|
{
|
|
|
|
imports = [ ./options.nix ];
|
|
|
|
|
2025-02-15 11:19:10 +01:00
|
|
|
config = mkMerge [
|
|
|
|
(mkIf
|
|
|
|
(
|
|
|
|
config.fediversity.garage.enable
|
|
|
|
&& config.fediversity.peertube.s3AccessKeyFile != null
|
|
|
|
&& config.fediversity.peertube.s3SecretKeyFile != null
|
|
|
|
)
|
|
|
|
{
|
|
|
|
fediversity.garage = {
|
|
|
|
ensureBuckets = {
|
2025-02-14 18:44:35 +01:00
|
|
|
peertube-videos = {
|
2025-02-15 11:19:10 +01:00
|
|
|
website = true;
|
|
|
|
# TODO: these are too broad, after getting everything works narrow it down to the domain we actually want
|
|
|
|
corsRules = {
|
|
|
|
enable = true;
|
|
|
|
allowedHeaders = [ "*" ];
|
|
|
|
allowedMethods = [ "GET" ];
|
|
|
|
allowedOrigins = [ "*" ];
|
|
|
|
};
|
2025-02-14 18:44:35 +01:00
|
|
|
};
|
2025-02-15 11:19:10 +01:00
|
|
|
# TODO: these are too broad, after getting everything works narrow it down to the domain we actually want
|
2025-02-14 18:44:35 +01:00
|
|
|
peertube-playlists = {
|
2025-02-15 11:19:10 +01:00
|
|
|
website = true;
|
|
|
|
corsRules = {
|
|
|
|
enable = true;
|
|
|
|
allowedHeaders = [ "*" ];
|
|
|
|
allowedMethods = [ "GET" ];
|
|
|
|
allowedOrigins = [ "*" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
ensureKeys = {
|
|
|
|
peertube = {
|
|
|
|
inherit (config.fediversity.peertube) s3AccessKeyFile s3SecretKeyFile;
|
|
|
|
ensureAccess = {
|
|
|
|
peertube-videos = {
|
|
|
|
read = true;
|
|
|
|
write = true;
|
|
|
|
owner = true;
|
|
|
|
};
|
|
|
|
peertube-playlists = {
|
|
|
|
read = true;
|
|
|
|
write = true;
|
|
|
|
owner = true;
|
|
|
|
};
|
|
|
|
};
|
2025-02-14 18:44:35 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2025-02-15 11:19:10 +01:00
|
|
|
}
|
|
|
|
)
|
2025-02-14 18:44:35 +01:00
|
|
|
|
2025-02-15 11:19:10 +01:00
|
|
|
(mkIf config.fediversity.peertube.enable {
|
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
80
|
|
|
|
443
|
2025-02-14 18:44:35 +01:00
|
|
|
|
2025-02-15 11:19:10 +01:00
|
|
|
## For Live streaming and Live streaming when RTMPS is enabled.
|
|
|
|
1935
|
|
|
|
1936
|
|
|
|
];
|
2025-02-14 18:44:35 +01:00
|
|
|
|
2025-02-15 11:19:10 +01:00
|
|
|
services.peertube = {
|
|
|
|
enable = true;
|
|
|
|
localDomain = config.fediversity.peertube.domain;
|
2025-02-14 18:44:35 +01:00
|
|
|
|
2025-02-15 11:19:10 +01:00
|
|
|
# TODO: in most of nixpkgs, these are true by default. upstream that unless there's a good reason not to.
|
|
|
|
redis.createLocally = true;
|
|
|
|
database.createLocally = true;
|
2025-02-14 18:44:35 +01:00
|
|
|
|
2025-02-15 11:19:10 +01:00
|
|
|
secrets.secretsFile = config.fediversity.peertube.secretsFile;
|
2025-02-14 18:44:35 +01:00
|
|
|
|
2025-02-15 11:19:10 +01:00
|
|
|
settings = {
|
|
|
|
object_storage = {
|
|
|
|
enabled = true;
|
|
|
|
endpoint = config.fediversity.garage.api.url;
|
|
|
|
region = "garage";
|
|
|
|
upload_acl.public = null; # Garage does not support ACL
|
|
|
|
upload_acl.private = null; # Garage does not support ACL
|
|
|
|
|
|
|
|
# not supported by garage
|
|
|
|
# SEE: https://garagehq.deuxfleurs.fr/documentation/connect/apps/#peertube
|
|
|
|
proxy.proxyify_private_files = false;
|
|
|
|
|
|
|
|
web_videos = rec {
|
|
|
|
bucket_name = "peertube-videos";
|
|
|
|
prefix = "";
|
|
|
|
base_url = config.fediversity.garage.web.urlForBucket bucket_name;
|
|
|
|
};
|
|
|
|
videos = rec {
|
|
|
|
bucket_name = "peertube-videos";
|
|
|
|
prefix = "";
|
|
|
|
base_url = config.fediversity.garage.web.urlForBucket bucket_name;
|
|
|
|
};
|
|
|
|
streaming_playlists = rec {
|
|
|
|
bucket_name = "peertube-playlists";
|
|
|
|
prefix = "";
|
|
|
|
base_url = config.fediversity.garage.web.urlForBucket bucket_name;
|
|
|
|
};
|
2025-02-14 18:44:35 +01:00
|
|
|
};
|
|
|
|
};
|
2025-02-15 11:19:10 +01:00
|
|
|
serviceEnvironmentFile = "/etc/peertube-env";
|
2025-02-14 18:44:35 +01:00
|
|
|
};
|
2025-02-14 19:46:12 +01:00
|
|
|
|
2025-02-15 11:19:10 +01:00
|
|
|
## FIXME: secrets management; we should have a service that writes the
|
|
|
|
## `.env` files based on all the secrets that we need to put there.
|
|
|
|
environment.etc.peertube-env.text = ''
|
|
|
|
AWS_ACCESS_KEY_ID=${readFile config.fediversity.peertube.s3AccessKeyFile}
|
|
|
|
AWS_SECRET_ACCESS_KEY=${readFile config.fediversity.peertube.s3SecretKeyFile}
|
|
|
|
'';
|
2025-02-14 18:44:35 +01:00
|
|
|
|
2025-02-15 11:19:10 +01:00
|
|
|
## Proxying through Nginx
|
2025-02-14 18:44:35 +01:00
|
|
|
|
2025-02-15 11:19:10 +01:00
|
|
|
services.peertube = {
|
|
|
|
configureNginx = true;
|
|
|
|
listenWeb = 443;
|
|
|
|
enableWebHttps = true;
|
|
|
|
};
|
|
|
|
services.nginx.virtualHosts.${config.services.peertube.localDomain} = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
2025-02-14 18:44:35 +01:00
|
|
|
}
|