1 { config, pkgs, lib, ... }:
4 inherit (lib) mkIf getExe maintainers mkEnableOption mkOption mkPackageOption;
5 inherit (lib.types) str path bool;
6 cfg = config.services.jellyfin;
11 enable = mkEnableOption "Jellyfin Media Server";
13 package = mkPackageOption pkgs "jellyfin" { };
18 description = "User account under which Jellyfin runs.";
24 description = "Group under which jellyfin runs.";
29 default = "/var/lib/jellyfin";
32 passed with `--datadir` see [#data-directory](https://jellyfin.org/docs/general/administration/configuration/#data-directory)
36 configDir = mkOption {
38 default = "${cfg.dataDir}/config";
39 defaultText = "\${cfg.dataDir}/config";
41 Directory containing the server configuration files,
42 passed with `--configdir` see [configuration-directory](https://jellyfin.org/docs/general/administration/configuration/#configuration-directory)
48 default = "/var/cache/jellyfin";
50 Directory containing the jellyfin server cache,
51 passed with `--cachedir` see [#cache-directory](https://jellyfin.org/docs/general/administration/configuration/#cache-directory)
57 default = "${cfg.dataDir}/log";
58 defaultText = "\${cfg.dataDir}/log";
60 Directory where the Jellyfin logs will be stored,
61 passed with `--logdir` see [#log-directory](https://jellyfin.org/docs/general/administration/configuration/#log-directory)
65 openFirewall = mkOption {
69 Open the default ports in the firewall for the media server. The
70 HTTP/HTTPS ports can be changed in the Web UI, so this option should
71 only be used if they are unchanged, see [Port Bindings](https://jellyfin.org/docs/general/networking/#port-bindings).
77 config = mkIf cfg.enable {
79 tmpfiles.settings.jellyfinDirs = {
80 "${cfg.dataDir}"."d" = {
82 inherit (cfg) user group;
84 "${cfg.configDir}"."d" = {
86 inherit (cfg) user group;
88 "${cfg.logDir}"."d" = {
90 inherit (cfg) user group;
92 "${cfg.cacheDir}"."d" = {
94 inherit (cfg) user group;
98 description = "Jellyfin Media Server";
99 after = [ "network-online.target" ];
100 wants = [ "network-online.target" ];
101 wantedBy = [ "multi-user.target" ];
103 # This is mostly follows: https://github.com/jellyfin/jellyfin/blob/master/fedora/jellyfin.service
104 # Upstream also disable some hardenings when running in LXC, we do the same with the isContainer option
110 WorkingDirectory = cfg.dataDir;
111 ExecStart = "${getExe cfg.package} --datadir '${cfg.dataDir}' --configdir '${cfg.configDir}' --cachedir '${cfg.cacheDir}' --logdir '${cfg.logDir}'";
112 Restart = "on-failure";
114 SuccessExitStatus = ["0" "143"];
117 NoNewPrivileges = true;
118 SystemCallArchitectures = "native";
119 # AF_NETLINK needed because Jellyfin monitors the network connection
120 RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK" ];
121 RestrictNamespaces = !config.boot.isContainer;
122 RestrictRealtime = true;
123 RestrictSUIDSGID = true;
124 ProtectControlGroups = !config.boot.isContainer;
125 ProtectHostname = true;
126 ProtectKernelLogs = !config.boot.isContainer;
127 ProtectKernelModules = !config.boot.isContainer;
128 ProtectKernelTunables = !config.boot.isContainer;
129 LockPersonality = true;
130 PrivateTmp = !config.boot.isContainer;
131 # needed for hardware acceleration
132 PrivateDevices = false;
137 "~@clock" "~@aio" "~@chown" "~@cpu-emulation" "~@debug" "~@keyring" "~@memlock" "~@module" "~@mount" "~@obsolete" "~@privileged" "~@raw-io" "~@reboot" "~@setuid" "~@swap"
139 SystemCallErrorNumber = "EPERM";
144 users.users = mkIf (cfg.user == "jellyfin") {
151 users.groups = mkIf (cfg.group == "jellyfin") {
155 networking.firewall = mkIf cfg.openFirewall {
156 # from https://jellyfin.org/docs/general/networking/index.html
157 allowedTCPPorts = [ 8096 8920 ];
158 allowedUDPPorts = [ 1900 7359 ];
163 meta.maintainers = with maintainers; [ minijackson fsnkty ];