2019-04-14 13:10:50 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.jellyfin;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.jellyfin = {
|
|
|
|
enable = mkEnableOption "Jellyfin Media Server";
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "jellyfin";
|
|
|
|
description = "User account under which Jellyfin runs.";
|
|
|
|
};
|
|
|
|
|
2020-08-16 17:41:41 +02:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2021-04-24 14:01:47 +02:00
|
|
|
default = pkgs.jellyfin;
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression "pkgs.jellyfin";
|
2020-08-16 17:41:41 +02:00
|
|
|
description = ''
|
|
|
|
Jellyfin package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-04-14 13:10:50 +02:00
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "jellyfin";
|
|
|
|
description = "Group under which jellyfin runs.";
|
|
|
|
};
|
2020-12-29 21:46:54 +01:00
|
|
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Open the default ports in the firewall for the media server. The
|
|
|
|
HTTP/HTTPS ports can be changed in the Web UI, so this option should
|
|
|
|
only be used if they are unchanged.
|
|
|
|
'';
|
|
|
|
};
|
2019-04-14 13:10:50 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.jellyfin = {
|
|
|
|
description = "Jellyfin Media Server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = rec {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
StateDirectory = "jellyfin";
|
|
|
|
CacheDirectory = "jellyfin";
|
2020-08-16 17:41:41 +02:00
|
|
|
ExecStart = "${cfg.package}/bin/jellyfin --datadir '/var/lib/${StateDirectory}' --cachedir '/var/cache/${CacheDirectory}'";
|
2019-04-14 13:10:50 +02:00
|
|
|
Restart = "on-failure";
|
2020-09-17 21:10:44 +02:00
|
|
|
|
|
|
|
# Security options:
|
|
|
|
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
|
|
|
|
AmbientCapabilities = "";
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
|
|
|
|
# ProtectClock= adds DeviceAllow=char-rtc r
|
|
|
|
DeviceAllow = "";
|
|
|
|
|
|
|
|
LockPersonality = true;
|
|
|
|
|
|
|
|
PrivateTmp = true;
|
2022-03-10 21:02:13 +01:00
|
|
|
# Disabled to allow Jellyfin to access hw accel devices endpoints
|
|
|
|
# PrivateDevices = true;
|
2020-09-17 21:10:44 +02:00
|
|
|
PrivateUsers = true;
|
|
|
|
|
2022-03-10 01:19:57 +01:00
|
|
|
# Disabled as it does not allow Jellyfin to interface with CUDA devices
|
|
|
|
# ProtectClock = true;
|
2020-09-17 21:10:44 +02:00
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
|
|
|
|
RemoveIPC = true;
|
|
|
|
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
# AF_NETLINK needed because Jellyfin monitors the network connection
|
2022-03-09 20:44:06 +01:00
|
|
|
RestrictAddressFamilies = [ "AF_NETLINK" "AF_INET" "AF_INET6" "AF_UNIX" ];
|
2020-09-17 21:10:44 +02:00
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallErrorNumber = "EPERM";
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
2021-05-13 14:29:25 +02:00
|
|
|
"~@cpu-emulation" "~@debug" "~@keyring" "~@memlock" "~@obsolete" "~@privileged" "~@setuid"
|
2020-09-17 21:10:44 +02:00
|
|
|
];
|
2019-04-14 13:10:50 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users = mkIf (cfg.user == "jellyfin") {
|
2019-10-12 22:25:28 +02:00
|
|
|
jellyfin = {
|
|
|
|
group = cfg.group;
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
2019-04-14 13:10:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
users.groups = mkIf (cfg.group == "jellyfin") {
|
|
|
|
jellyfin = {};
|
|
|
|
};
|
|
|
|
|
2020-12-29 21:46:54 +01:00
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
# from https://jellyfin.org/docs/general/networking/index.html
|
|
|
|
allowedTCPPorts = [ 8096 8920 ];
|
|
|
|
allowedUDPPorts = [ 1900 7359 ];
|
|
|
|
};
|
|
|
|
|
2019-04-14 13:10:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ minijackson ];
|
|
|
|
}
|