2021-12-19 01:06:50 +00:00
|
|
|
|
{ lib, pkgs, config, options, ... }:
|
2021-10-28 06:52:43 +00:00
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
cfg = config.services.peertube;
|
2021-12-19 01:06:50 +00:00
|
|
|
|
opt = options.services.peertube;
|
2021-10-28 06:52:43 +00:00
|
|
|
|
|
|
|
|
|
settingsFormat = pkgs.formats.json {};
|
|
|
|
|
configFile = settingsFormat.generate "production.json" cfg.settings;
|
|
|
|
|
|
|
|
|
|
env = {
|
|
|
|
|
NODE_CONFIG_DIR = "/var/lib/peertube/config";
|
|
|
|
|
NODE_ENV = "production";
|
|
|
|
|
NODE_EXTRA_CA_CERTS = "/etc/ssl/certs/ca-certificates.crt";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
NPM_CONFIG_CACHE = "/var/cache/peertube/.npm";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
NPM_CONFIG_PREFIX = cfg.package;
|
|
|
|
|
HOME = cfg.package;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemCallsList = [ "@cpu-emulation" "@debug" "@keyring" "@ipc" "@memlock" "@mount" "@obsolete" "@privileged" "@setuid" ];
|
|
|
|
|
|
|
|
|
|
cfgService = {
|
|
|
|
|
# Proc filesystem
|
|
|
|
|
ProcSubset = "pid";
|
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
|
# Access write directories
|
|
|
|
|
UMask = "0027";
|
|
|
|
|
# Capabilities
|
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
|
# Security
|
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
|
# Sandboxing
|
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
|
ProtectHome = true;
|
|
|
|
|
PrivateTmp = true;
|
|
|
|
|
PrivateDevices = true;
|
|
|
|
|
PrivateUsers = true;
|
|
|
|
|
ProtectClock = true;
|
|
|
|
|
ProtectHostname = true;
|
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
|
LockPersonality = true;
|
|
|
|
|
RestrictRealtime = true;
|
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
|
RemoveIPC = true;
|
|
|
|
|
PrivateMounts = true;
|
|
|
|
|
# System Call Filtering
|
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
envFile = pkgs.writeText "peertube.env" (lib.concatMapStrings (s: s + "\n") (
|
|
|
|
|
(lib.concatLists (lib.mapAttrsToList (name: value:
|
|
|
|
|
if value != null then [
|
|
|
|
|
"${name}=\"${toString value}\""
|
|
|
|
|
] else []
|
|
|
|
|
) env))));
|
|
|
|
|
|
|
|
|
|
peertubeEnv = pkgs.writeShellScriptBin "peertube-env" ''
|
|
|
|
|
set -a
|
|
|
|
|
source "${envFile}"
|
|
|
|
|
eval -- "\$@"
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
peertubeCli = pkgs.writeShellScriptBin "peertube" ''
|
|
|
|
|
node ~/dist/server/tools/peertube.js $@
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
options.services.peertube = {
|
|
|
|
|
enable = lib.mkEnableOption "Enable Peertube’s service";
|
|
|
|
|
|
|
|
|
|
user = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "peertube";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "User account under which Peertube runs.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
group = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "peertube";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Group under which Peertube runs.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
localDomain = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
example = "peertube.example.com";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "The domain serving your PeerTube instance.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
listenHttp = lib.mkOption {
|
|
|
|
|
type = lib.types.int;
|
|
|
|
|
default = 9000;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "listen port for HTTP server.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
listenWeb = lib.mkOption {
|
|
|
|
|
type = lib.types.int;
|
|
|
|
|
default = 9000;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "listen port for WEB server.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enableWebHttps = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Enable or disable HTTPS protocol.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dataDirs = lib.mkOption {
|
|
|
|
|
type = lib.types.listOf lib.types.path;
|
|
|
|
|
default = [ ];
|
|
|
|
|
example = [ "/opt/peertube/storage" "/var/cache/peertube" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Allow access to custom data locations.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
serviceEnvironmentFile = lib.mkOption {
|
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
|
|
|
|
default = null;
|
|
|
|
|
example = "/run/keys/peertube/password-init-root";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2021-10-28 06:52:43 +00:00
|
|
|
|
Set environment variables for the service. Mainly useful for setting the initial root password.
|
|
|
|
|
For example write to file:
|
|
|
|
|
PT_INITIAL_ROOT_PASSWORD=changeme
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
settings = lib.mkOption {
|
|
|
|
|
type = settingsFormat.type;
|
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
|
{
|
|
|
|
|
listen = {
|
|
|
|
|
hostname = "0.0.0.0";
|
|
|
|
|
};
|
|
|
|
|
log = {
|
|
|
|
|
level = "debug";
|
|
|
|
|
};
|
|
|
|
|
storage = {
|
|
|
|
|
tmp = "/opt/data/peertube/storage/tmp/";
|
|
|
|
|
logs = "/opt/data/peertube/storage/logs/";
|
|
|
|
|
cache = "/opt/data/peertube/storage/cache/";
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Configuration for peertube.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
database = {
|
|
|
|
|
createLocally = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Configure local PostgreSQL database server for PeerTube.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
host = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = if cfg.database.createLocally then "/run/postgresql" else null;
|
2021-12-19 01:06:50 +00:00
|
|
|
|
defaultText = lib.literalExpression ''
|
|
|
|
|
if config.${opt.database.createLocally}
|
|
|
|
|
then "/run/postgresql"
|
|
|
|
|
else null
|
|
|
|
|
'';
|
2021-10-28 06:52:43 +00:00
|
|
|
|
example = "192.168.15.47";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Database host address or unix socket.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
port = lib.mkOption {
|
|
|
|
|
type = lib.types.int;
|
|
|
|
|
default = 5432;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Database host port.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
name = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "peertube";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Database name.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
user = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "peertube";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Database user.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
passwordFile = lib.mkOption {
|
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
|
|
|
|
default = null;
|
|
|
|
|
example = "/run/keys/peertube/password-posgressql-db";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Password for PostgreSQL database.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
redis = {
|
|
|
|
|
createLocally = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Configure local Redis server for PeerTube.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
host = lib.mkOption {
|
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
|
default = if cfg.redis.createLocally && !cfg.redis.enableUnixSocket then "127.0.0.1" else null;
|
2021-12-19 01:06:50 +00:00
|
|
|
|
defaultText = lib.literalExpression ''
|
|
|
|
|
if config.${opt.redis.createLocally} && !config.${opt.redis.enableUnixSocket}
|
|
|
|
|
then "127.0.0.1"
|
|
|
|
|
else null
|
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Redis host.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
port = lib.mkOption {
|
|
|
|
|
type = lib.types.nullOr lib.types.port;
|
2022-06-16 17:23:12 +00:00
|
|
|
|
default = if cfg.redis.createLocally && cfg.redis.enableUnixSocket then null else 31638;
|
2021-12-19 01:06:50 +00:00
|
|
|
|
defaultText = lib.literalExpression ''
|
|
|
|
|
if config.${opt.redis.createLocally} && config.${opt.redis.enableUnixSocket}
|
|
|
|
|
then null
|
|
|
|
|
else 6379
|
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Redis port.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
passwordFile = lib.mkOption {
|
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
|
|
|
|
default = null;
|
|
|
|
|
example = "/run/keys/peertube/password-redis-db";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Password for redis database.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enableUnixSocket = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = cfg.redis.createLocally;
|
2021-12-19 01:06:50 +00:00
|
|
|
|
defaultText = lib.literalExpression "config.${opt.redis.createLocally}";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Use Unix socket.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
smtp = {
|
|
|
|
|
createLocally = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Configure local Postfix SMTP server for PeerTube.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
passwordFile = lib.mkOption {
|
|
|
|
|
type = lib.types.nullOr lib.types.path;
|
|
|
|
|
default = null;
|
|
|
|
|
example = "/run/keys/peertube/password-smtp";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Password for smtp server.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
package = lib.mkOption {
|
|
|
|
|
type = lib.types.package;
|
|
|
|
|
default = pkgs.peertube;
|
2021-12-06 16:07:01 +00:00
|
|
|
|
defaultText = lib.literalExpression "pkgs.peertube";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Peertube package to use.";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
|
assertions = [
|
|
|
|
|
{ assertion = cfg.serviceEnvironmentFile == null || !lib.hasPrefix builtins.storeDir cfg.serviceEnvironmentFile;
|
|
|
|
|
message = ''
|
|
|
|
|
<option>services.peertube.serviceEnvironmentFile</option> points to
|
|
|
|
|
a file in the Nix store. You should use a quoted absolute path to
|
|
|
|
|
prevent this.
|
|
|
|
|
'';
|
|
|
|
|
}
|
|
|
|
|
{ assertion = !(cfg.redis.enableUnixSocket && (cfg.redis.host != null || cfg.redis.port != null));
|
|
|
|
|
message = ''
|
|
|
|
|
<option>services.peertube.redis.createLocally</option> and redis network connection (<option>services.peertube.redis.host</option> or <option>services.peertube.redis.port</option>) enabled. Disable either of them.
|
|
|
|
|
'';
|
|
|
|
|
}
|
|
|
|
|
{ assertion = cfg.redis.enableUnixSocket || (cfg.redis.host != null && cfg.redis.port != null);
|
|
|
|
|
message = ''
|
|
|
|
|
<option>services.peertube.redis.host</option> and <option>services.peertube.redis.port</option> needs to be set if <option>services.peertube.redis.enableUnixSocket</option> is not enabled.
|
|
|
|
|
'';
|
|
|
|
|
}
|
|
|
|
|
{ assertion = cfg.redis.passwordFile == null || !lib.hasPrefix builtins.storeDir cfg.redis.passwordFile;
|
|
|
|
|
message = ''
|
|
|
|
|
<option>services.peertube.redis.passwordFile</option> points to
|
|
|
|
|
a file in the Nix store. You should use a quoted absolute path to
|
|
|
|
|
prevent this.
|
|
|
|
|
'';
|
|
|
|
|
}
|
|
|
|
|
{ assertion = cfg.database.passwordFile == null || !lib.hasPrefix builtins.storeDir cfg.database.passwordFile;
|
|
|
|
|
message = ''
|
|
|
|
|
<option>services.peertube.database.passwordFile</option> points to
|
|
|
|
|
a file in the Nix store. You should use a quoted absolute path to
|
|
|
|
|
prevent this.
|
|
|
|
|
'';
|
|
|
|
|
}
|
|
|
|
|
{ assertion = cfg.smtp.passwordFile == null || !lib.hasPrefix builtins.storeDir cfg.smtp.passwordFile;
|
|
|
|
|
message = ''
|
|
|
|
|
<option>services.peertube.smtp.passwordFile</option> points to
|
|
|
|
|
a file in the Nix store. You should use a quoted absolute path to
|
|
|
|
|
prevent this.
|
|
|
|
|
'';
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
services.peertube.settings = lib.mkMerge [
|
|
|
|
|
{
|
|
|
|
|
listen = {
|
|
|
|
|
port = cfg.listenHttp;
|
|
|
|
|
};
|
|
|
|
|
webserver = {
|
|
|
|
|
https = (if cfg.enableWebHttps then true else false);
|
|
|
|
|
hostname = "${cfg.localDomain}";
|
|
|
|
|
port = cfg.listenWeb;
|
|
|
|
|
};
|
|
|
|
|
database = {
|
|
|
|
|
hostname = "${cfg.database.host}";
|
|
|
|
|
port = cfg.database.port;
|
|
|
|
|
name = "${cfg.database.name}";
|
|
|
|
|
username = "${cfg.database.user}";
|
|
|
|
|
};
|
|
|
|
|
redis = {
|
|
|
|
|
hostname = "${toString cfg.redis.host}";
|
|
|
|
|
port = (if cfg.redis.port == null then "" else cfg.redis.port);
|
|
|
|
|
};
|
|
|
|
|
storage = {
|
|
|
|
|
tmp = lib.mkDefault "/var/lib/peertube/storage/tmp/";
|
2022-03-05 16:20:37 +00:00
|
|
|
|
bin = lib.mkDefault "/var/lib/peertube/storage/bin/";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
avatars = lib.mkDefault "/var/lib/peertube/storage/avatars/";
|
|
|
|
|
videos = lib.mkDefault "/var/lib/peertube/storage/videos/";
|
|
|
|
|
streaming_playlists = lib.mkDefault "/var/lib/peertube/storage/streaming-playlists/";
|
|
|
|
|
redundancy = lib.mkDefault "/var/lib/peertube/storage/redundancy/";
|
|
|
|
|
logs = lib.mkDefault "/var/lib/peertube/storage/logs/";
|
|
|
|
|
previews = lib.mkDefault "/var/lib/peertube/storage/previews/";
|
|
|
|
|
thumbnails = lib.mkDefault "/var/lib/peertube/storage/thumbnails/";
|
|
|
|
|
torrents = lib.mkDefault "/var/lib/peertube/storage/torrents/";
|
|
|
|
|
captions = lib.mkDefault "/var/lib/peertube/storage/captions/";
|
|
|
|
|
cache = lib.mkDefault "/var/lib/peertube/storage/cache/";
|
|
|
|
|
plugins = lib.mkDefault "/var/lib/peertube/storage/plugins/";
|
|
|
|
|
client_overrides = lib.mkDefault "/var/lib/peertube/storage/client-overrides/";
|
|
|
|
|
};
|
2022-03-05 16:20:37 +00:00
|
|
|
|
import = {
|
|
|
|
|
videos = {
|
|
|
|
|
http = {
|
|
|
|
|
youtube_dl_release = {
|
|
|
|
|
python_path = "${pkgs.python3}/bin/python";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
2021-10-28 06:52:43 +00:00
|
|
|
|
}
|
2022-06-16 17:23:12 +00:00
|
|
|
|
(lib.mkIf cfg.redis.enableUnixSocket { redis = { socket = "/run/redis-peertube/redis.sock"; }; })
|
2021-10-28 06:52:43 +00:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
|
"d '/var/lib/peertube/config' 0700 ${cfg.user} ${cfg.group} - -"
|
|
|
|
|
"z '/var/lib/peertube/config' 0700 ${cfg.user} ${cfg.group} - -"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
systemd.services.peertube-init-db = lib.mkIf cfg.database.createLocally {
|
|
|
|
|
description = "Initialization database for PeerTube daemon";
|
|
|
|
|
after = [ "network.target" "postgresql.service" ];
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
|
|
script = let
|
|
|
|
|
psqlSetupCommands = pkgs.writeText "peertube-init.sql" ''
|
|
|
|
|
SELECT 'CREATE USER "${cfg.database.user}"' WHERE NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${cfg.database.user}')\gexec
|
|
|
|
|
SELECT 'CREATE DATABASE "${cfg.database.name}" OWNER "${cfg.database.user}" TEMPLATE template0 ENCODING UTF8' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '${cfg.database.name}')\gexec
|
|
|
|
|
\c '${cfg.database.name}'
|
|
|
|
|
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
|
|
|
|
CREATE EXTENSION IF NOT EXISTS unaccent;
|
|
|
|
|
'';
|
|
|
|
|
in "${config.services.postgresql.package}/bin/psql -f ${psqlSetupCommands}";
|
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "oneshot";
|
|
|
|
|
WorkingDirectory = cfg.package;
|
|
|
|
|
# User and group
|
|
|
|
|
User = "postgres";
|
|
|
|
|
Group = "postgres";
|
|
|
|
|
# Sandboxing
|
|
|
|
|
RestrictAddressFamilies = [ "AF_UNIX" ];
|
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
|
# System Call Filtering
|
|
|
|
|
SystemCallFilter = "~" + lib.concatStringsSep " " (systemCallsList ++ [ "@resources" ]);
|
|
|
|
|
} // cfgService;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.services.peertube = {
|
|
|
|
|
description = "PeerTube daemon";
|
|
|
|
|
after = [ "network.target" ]
|
|
|
|
|
++ lib.optionals cfg.redis.createLocally [ "redis.service" ]
|
|
|
|
|
++ lib.optionals cfg.database.createLocally [ "postgresql.service" "peertube-init-db.service" ];
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
|
|
environment = env;
|
|
|
|
|
|
2022-03-05 16:20:37 +00:00
|
|
|
|
path = with pkgs; [ bashInteractive ffmpeg nodejs-16_x openssl yarn python3 ];
|
2021-10-28 06:52:43 +00:00
|
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
umask 077
|
|
|
|
|
cat > /var/lib/peertube/config/local.yaml <<EOF
|
|
|
|
|
${lib.optionalString ((!cfg.database.createLocally) && (cfg.database.passwordFile != null)) ''
|
|
|
|
|
database:
|
|
|
|
|
password: '$(cat ${cfg.database.passwordFile})'
|
|
|
|
|
''}
|
|
|
|
|
${lib.optionalString (cfg.redis.passwordFile != null) ''
|
|
|
|
|
redis:
|
|
|
|
|
auth: '$(cat ${cfg.redis.passwordFile})'
|
|
|
|
|
''}
|
|
|
|
|
${lib.optionalString (cfg.smtp.passwordFile != null) ''
|
|
|
|
|
smtp:
|
|
|
|
|
password: '$(cat ${cfg.smtp.passwordFile})'
|
|
|
|
|
''}
|
|
|
|
|
EOF
|
|
|
|
|
ln -sf ${cfg.package}/config/default.yaml /var/lib/peertube/config/default.yaml
|
|
|
|
|
ln -sf ${configFile} /var/lib/peertube/config/production.json
|
|
|
|
|
npm start
|
|
|
|
|
'';
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "simple";
|
|
|
|
|
Restart = "always";
|
|
|
|
|
RestartSec = 20;
|
|
|
|
|
TimeoutSec = 60;
|
|
|
|
|
WorkingDirectory = cfg.package;
|
|
|
|
|
# User and group
|
|
|
|
|
User = cfg.user;
|
|
|
|
|
Group = cfg.group;
|
|
|
|
|
# State directory and mode
|
|
|
|
|
StateDirectory = "peertube";
|
|
|
|
|
StateDirectoryMode = "0750";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
# Cache directory and mode
|
|
|
|
|
CacheDirectory = "peertube";
|
|
|
|
|
CacheDirectoryMode = "0750";
|
2021-10-28 06:52:43 +00:00
|
|
|
|
# Access write directories
|
|
|
|
|
ReadWritePaths = cfg.dataDirs;
|
|
|
|
|
# Environment
|
|
|
|
|
EnvironmentFile = cfg.serviceEnvironmentFile;
|
|
|
|
|
# Sandboxing
|
|
|
|
|
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK" ];
|
|
|
|
|
MemoryDenyWriteExecute = false;
|
|
|
|
|
# System Call Filtering
|
|
|
|
|
SystemCallFilter = [ ("~" + lib.concatStringsSep " " systemCallsList) "pipe" "pipe2" ];
|
|
|
|
|
} // cfgService;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.postgresql = lib.mkIf cfg.database.createLocally {
|
|
|
|
|
enable = true;
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
|
services.redis.servers.peertube = lib.mkMerge [
|
2021-10-28 06:52:43 +00:00
|
|
|
|
(lib.mkIf cfg.redis.createLocally {
|
|
|
|
|
enable = true;
|
|
|
|
|
})
|
2022-06-16 17:23:12 +00:00
|
|
|
|
(lib.mkIf (cfg.redis.createLocally && !cfg.redis.enableUnixSocket) {
|
|
|
|
|
bind = "127.0.0.1";
|
|
|
|
|
port = cfg.redis.port;
|
|
|
|
|
})
|
2021-10-28 06:52:43 +00:00
|
|
|
|
(lib.mkIf (cfg.redis.createLocally && cfg.redis.enableUnixSocket) {
|
2022-06-16 17:23:12 +00:00
|
|
|
|
unixSocket = "/run/redis-peertube/redis.sock";
|
|
|
|
|
unixSocketPerm = 660;
|
2021-10-28 06:52:43 +00:00
|
|
|
|
})
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
services.postfix = lib.mkIf cfg.smtp.createLocally {
|
|
|
|
|
enable = true;
|
|
|
|
|
hostname = lib.mkDefault "${cfg.localDomain}";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
users.users = lib.mkMerge [
|
|
|
|
|
(lib.mkIf (cfg.user == "peertube") {
|
|
|
|
|
peertube = {
|
|
|
|
|
isSystemUser = true;
|
|
|
|
|
group = cfg.group;
|
|
|
|
|
home = cfg.package;
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
(lib.attrsets.setAttrByPath [ cfg.user "packages" ] [ cfg.package peertubeEnv peertubeCli pkgs.ffmpeg pkgs.nodejs-16_x pkgs.yarn ])
|
2022-06-16 17:23:12 +00:00
|
|
|
|
(lib.mkIf cfg.redis.enableUnixSocket {${config.services.peertube.user}.extraGroups = [ "redis-peertube" ];})
|
2021-10-28 06:52:43 +00:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
users.groups = lib.optionalAttrs (cfg.group == "peertube") {
|
|
|
|
|
peertube = { };
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|