nixpkgs/nixos/modules/services/misc/jellyfin.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

165 lines
5.4 KiB
Nix
Raw Normal View History

2019-04-14 11:10:50 +00:00
{ config, pkgs, lib, ... }:
let
2023-12-28 00:32:05 +00:00
inherit (lib) mkIf getExe maintainers mkEnableOption mkOption mkPackageOption;
inherit (lib.types) str path bool;
2019-04-14 11:10:50 +00:00
cfg = config.services.jellyfin;
in
{
options = {
services.jellyfin = {
2023-12-28 00:32:05 +00:00
enable = mkEnableOption "Jellyfin Media Server";
package = mkPackageOption pkgs "jellyfin" { };
2019-04-14 11:10:50 +00:00
user = mkOption {
2023-12-28 00:32:05 +00:00
type = str;
2019-04-14 11:10:50 +00:00
default = "jellyfin";
2023-12-28 00:32:05 +00:00
description = "User account under which Jellyfin runs.";
2019-04-14 11:10:50 +00:00
};
group = mkOption {
2023-12-28 00:32:05 +00:00
type = str;
2019-04-14 11:10:50 +00:00
default = "jellyfin";
2023-12-28 00:32:05 +00:00
description = "Group under which jellyfin runs.";
};
dataDir = mkOption {
type = path;
default = "/var/lib/jellyfin";
description = ''
Base data directory,
passed with `--datadir` see [#data-directory](https://jellyfin.org/docs/general/administration/configuration/#data-directory)
'';
};
configDir = mkOption {
type = path;
default = "${cfg.dataDir}/config";
defaultText = "\${cfg.dataDir}/config";
description = ''
Directory containing the server configuration files,
passed with `--configdir` see [configuration-directory](https://jellyfin.org/docs/general/administration/configuration/#configuration-directory)
'';
};
cacheDir = mkOption {
type = path;
default = "/var/cache/jellyfin";
description = ''
Directory containing the jellyfin server cache,
passed with `--cachedir` see [#cache-directory](https://jellyfin.org/docs/general/administration/configuration/#cache-directory)
'';
};
logDir = mkOption {
type = path;
default = "${cfg.dataDir}/log";
defaultText = "\${cfg.dataDir}/log";
description = ''
Directory where the Jellyfin logs will be stored,
passed with `--logdir` see [#log-directory](https://jellyfin.org/docs/general/administration/configuration/#log-directory)
'';
2019-04-14 11:10:50 +00:00
};
2020-12-29 20:46:54 +00:00
openFirewall = mkOption {
2023-12-28 00:32:05 +00:00
type = bool;
2020-12-29 20:46:54 +00:00
default = false;
2023-12-28 00:32:05 +00:00
description = ''
2020-12-29 20:46:54 +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
2023-12-28 00:32:05 +00:00
only be used if they are unchanged, see [Port Bindings](https://jellyfin.org/docs/general/networking/#port-bindings).
2020-12-29 20:46:54 +00:00
'';
};
2019-04-14 11:10:50 +00:00
};
};
config = mkIf cfg.enable {
2023-12-28 00:32:05 +00:00
systemd = {
tmpfiles.settings.jellyfinDirs = {
"${cfg.dataDir}"."d" = {
mode = "700";
inherit (cfg) user group;
};
"${cfg.configDir}"."d" = {
mode = "700";
inherit (cfg) user group;
};
"${cfg.logDir}"."d" = {
mode = "700";
inherit (cfg) user group;
};
"${cfg.cacheDir}"."d" = {
mode = "700";
inherit (cfg) user group;
};
};
services.jellyfin = {
description = "Jellyfin Media Server";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
# 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
serviceConfig = {
Type = "simple";
User = cfg.user;
Group = cfg.group;
UMask = "0077";
WorkingDirectory = cfg.dataDir;
ExecStart = "${getExe cfg.package} --datadir '${cfg.dataDir}' --configdir '${cfg.configDir}' --cachedir '${cfg.cacheDir}' --logdir '${cfg.logDir}'";
Restart = "on-failure";
TimeoutSec = 15;
SuccessExitStatus = ["0" "143"];
# Security options:
NoNewPrivileges = true;
SystemCallArchitectures = "native";
# AF_NETLINK needed because Jellyfin monitors the network connection
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK" ];
RestrictNamespaces = !config.boot.isContainer;
RestrictRealtime = true;
RestrictSUIDSGID = true;
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 acceleration
PrivateDevices = false;
PrivateUsers = true;
RemoveIPC = true;
SystemCallFilter = [
"~@clock" "~@aio" "~@chown" "~@cpu-emulation" "~@debug" "~@keyring" "~@memlock" "~@module" "~@mount" "~@obsolete" "~@privileged" "~@raw-io" "~@reboot" "~@setuid" "~@swap"
];
SystemCallErrorNumber = "EPERM";
};
2019-04-14 11:10:50 +00:00
};
};
users.users = mkIf (cfg.user == "jellyfin") {
2019-10-12 20:25:28 +00:00
jellyfin = {
2023-12-28 00:32:05 +00:00
inherit (cfg) group;
2019-10-12 20:25:28 +00:00
isSystemUser = true;
};
2019-04-14 11:10:50 +00: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 11:10:50 +00:00
};
2024-06-15 02:21:38 +00:00
meta.maintainers = with maintainers; [ minijackson fsnkty ];
2019-04-14 11:10:50 +00:00
}