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