2019-04-14 12:10:50 +01: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 16:41:41 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2021-04-24 13:01:47 +01:00
|
|
|
default = pkgs.jellyfin;
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression "pkgs.jellyfin";
|
2020-08-16 16:41:41 +01:00
|
|
|
description = ''
|
|
|
|
Jellyfin package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-04-14 12:10:50 +01:00
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "jellyfin";
|
|
|
|
description = "Group under which jellyfin runs.";
|
|
|
|
};
|
2020-12-29 20:46:54 +00: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 12:10:50 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.jellyfin = {
|
|
|
|
description = "Jellyfin Media Server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
2022-07-04 13:25:43 +01:00
|
|
|
# This is mostly follows: https://github.com/jellyfin/jellyfin/blob/master/fedora/jellyfin.service
|
2022-06-18 15:59:31 +01:00
|
|
|
# Upstream also disable some hardenings when running in LXC, we do the same with the isContainer option
|
2019-04-14 12:10:50 +01:00
|
|
|
serviceConfig = rec {
|
2022-06-18 15:59:31 +01:00
|
|
|
Type = "simple";
|
2019-04-14 12:10:50 +01:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
StateDirectory = "jellyfin";
|
2022-05-31 16:28:33 +01:00
|
|
|
StateDirectoryMode = "0700";
|
2019-04-14 12:10:50 +01:00
|
|
|
CacheDirectory = "jellyfin";
|
2022-05-31 16:28:33 +01:00
|
|
|
CacheDirectoryMode = "0700";
|
|
|
|
UMask = "0077";
|
2022-06-18 15:59:31 +01:00
|
|
|
WorkingDirectory = "/var/lib/jellyfin";
|
2020-08-16 16:41:41 +01:00
|
|
|
ExecStart = "${cfg.package}/bin/jellyfin --datadir '/var/lib/${StateDirectory}' --cachedir '/var/cache/${CacheDirectory}'";
|
2019-04-14 12:10:50 +01:00
|
|
|
Restart = "on-failure";
|
2022-06-18 15:59:31 +01:00
|
|
|
TimeoutSec = 15;
|
|
|
|
SuccessExitStatus = ["0" "143"];
|
2020-09-17 20:10:44 +01:00
|
|
|
|
|
|
|
# Security options:
|
|
|
|
NoNewPrivileges = true;
|
2022-06-18 15:59:31 +01:00
|
|
|
SystemCallArchitectures = "native";
|
2020-09-17 20:10:44 +01:00
|
|
|
# AF_NETLINK needed because Jellyfin monitors the network connection
|
2022-06-18 15:59:31 +01:00
|
|
|
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK" ];
|
|
|
|
RestrictNamespaces = !config.boot.isContainer;
|
2020-09-17 20:10:44 +01:00
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
2022-06-18 15:59:31 +01:00
|
|
|
ProtectControlGroups = !config.boot.isContainer;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = !config.boot.isContainer;
|
|
|
|
ProtectKernelModules = !config.boot.isContainer;
|
|
|
|
ProtectKernelTunables = !config.boot.isContainer;
|
|
|
|
LockPersonality = true;
|
|
|
|
PrivateTmp = !config.boot.isContainer;
|
|
|
|
# needed for hardware accelaration
|
|
|
|
PrivateDevices = false;
|
|
|
|
PrivateUsers = true;
|
|
|
|
RemoveIPC = true;
|
2020-09-17 20:10:44 +01:00
|
|
|
|
|
|
|
SystemCallFilter = [
|
2022-06-18 15:59:31 +01:00
|
|
|
"~@clock"
|
|
|
|
"~@aio"
|
|
|
|
"~@chown"
|
|
|
|
"~@cpu-emulation"
|
|
|
|
"~@debug"
|
|
|
|
"~@keyring"
|
|
|
|
"~@memlock"
|
|
|
|
"~@module"
|
|
|
|
"~@mount"
|
|
|
|
"~@obsolete"
|
|
|
|
"~@privileged"
|
|
|
|
"~@raw-io"
|
|
|
|
"~@reboot"
|
|
|
|
"~@setuid"
|
|
|
|
"~@swap"
|
2020-09-17 20:10:44 +01:00
|
|
|
];
|
2022-06-18 15:59:31 +01:00
|
|
|
SystemCallErrorNumber = "EPERM";
|
2019-04-14 12:10:50 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users = mkIf (cfg.user == "jellyfin") {
|
2019-10-12 21:25:28 +01:00
|
|
|
jellyfin = {
|
|
|
|
group = cfg.group;
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
2019-04-14 12:10:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
users.groups = mkIf (cfg.group == "jellyfin") {
|
|
|
|
jellyfin = {};
|
|
|
|
};
|
|
|
|
|
2020-12-29 20:46:54 +00:00
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
# from https://jellyfin.org/docs/general/networking/index.html
|
|
|
|
allowedTCPPorts = [ 8096 8920 ];
|
|
|
|
allowedUDPPorts = [ 1900 7359 ];
|
|
|
|
};
|
|
|
|
|
2019-04-14 12:10:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ minijackson ];
|
|
|
|
}
|