···
1
-
# Module for MiniDLNA, a simple DLNA server.
{ config, lib, pkgs, ... }:
cfg = config.services.minidlna;
7
-
settingsFormat = pkgs.formats.keyValue { listsAsDuplicateKeys = true; };
8
-
settingsFile = settingsFormat.generate "minidlna.conf" cfg.settings;
5
+
format = pkgs.formats.keyValue { listsAsDuplicateKeys = true; };
6
+
cfgfile = format.generate "minidlna.conf" cfg.settings;
13
-
options.services.minidlna.enable = mkOption {
17
-
Whether to enable MiniDLNA, a simple DLNA server.
18
-
It serves media files such as video and music to DLNA client devices
19
-
such as televisions and media players. If you use the firewall, consider
20
-
adding the following: `services.minidlna.openFirewall = true;`
9
+
options.services.minidlna.enable = lib.mkEnableOption "MiniDLNA, a simple DLNA server. Consider adding `openFirewall = true` into your config";
10
+
options.services.minidlna.openFirewall = lib.mkEnableOption "opening HTTP (TCP) and SSDP (UDP) ports in the firewall";
11
+
options.services.minidlna.package = lib.mkPackageOption pkgs "minidlna" {};
24
-
options.services.minidlna.package = lib.mkPackageOption pkgs "minidlna" { };
26
-
options.services.minidlna.openFirewall = mkOption {
30
-
Whether to open both HTTP (TCP) and SSDP (UDP) ports in the firewall.
34
-
options.services.minidlna.settings = mkOption {
13
+
options.services.minidlna.settings = lib.mkOption {
37
-
The contents of MiniDLNA's configuration file.
38
-
When the service is activated, a basic template is generated from the current options opened here.
40
-
type = types.submodule {
41
-
freeformType = settingsFormat.type;
15
+
description = "Configuration for `minidlna.conf(5)`.";
16
+
type = lib.types.submodule {
17
+
freeformType = format.type;
43
-
options.media_dir = mkOption {
44
-
type = types.listOf types.str;
19
+
options.media_dir = lib.mkOption {
20
+
type = lib.types.listOf lib.types.str;
example = [ "/data/media" "V,/home/alice/video" ];
···
The directories must be accessible to the `minidlna` user account.
53
-
options.notify_interval = mkOption {
29
+
options.notify_interval = lib.mkOption {
30
+
type = lib.types.int;
The interval between announces (in seconds).
Instead of waiting for announces, you should set `openFirewall` option to use SSDP discovery.
59
-
Lower values (e.g. 30 seconds) should be used if your network blocks the discovery unicast.
60
-
Some relevant information can be found here:
61
-
https://sourceforge.net/p/minidlna/discussion/879957/thread/1389d197/
35
+
Lower values (e.g. 30 seconds) should be used if your network is blocking the SSDP multicast.
36
+
Some relevant information can be found [here](https://sourceforge.net/p/minidlna/discussion/879957/thread/1389d197/).
64
-
options.port = mkOption {
39
+
options.port = lib.mkOption {
40
+
type = lib.types.port;
description = "Port number for HTTP traffic (descriptions, SOAP, media transfer).";
69
-
options.db_dir = mkOption {
44
+
options.db_dir = lib.mkOption {
45
+
type = lib.types.path;
default = "/var/cache/minidlna";
example = "/tmp/minidlna";
73
-
description = "Specify the directory where you want MiniDLNA to store its database and album art cache.";
48
+
description = "Specify the directory to store database and album art cache.";
75
-
options.friendly_name = mkOption {
50
+
options.friendly_name = lib.mkOption {
51
+
type = lib.types.str;
default = config.networking.hostName;
78
-
defaultText = literalExpression "config.networking.hostName";
53
+
defaultText = lib.literalExpression "config.networking.hostName";
80
-
description = "Name that the DLNA server presents to clients.";
55
+
description = "Name that the server presents to clients.";
82
-
options.root_container = mkOption {
57
+
options.root_container = lib.mkOption {
58
+
type = lib.types.str;
description = "Use a different container as the root of the directory tree presented to clients.";
88
-
options.log_level = mkOption {
63
+
options.log_level = lib.mkOption {
64
+
type = lib.types.str;
example = "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn";
description = "Defines the type of messages that should be logged and down to which level of importance.";
94
-
options.inotify = mkOption {
95
-
type = types.enum [ "yes" "no" ];
69
+
options.enable_subtitles = lib.mkOption {
70
+
type = lib.types.enum [ "yes" "no" ];
72
+
description = "Enable subtitle support on unknown clients.";
74
+
options.inotify = lib.mkOption {
75
+
type = lib.types.enum [ "yes" "no" ];
description = "Whether to enable inotify monitoring to automatically discover new files.";
99
-
options.enable_tivo = mkOption {
100
-
type = types.enum [ "yes" "no" ];
79
+
options.enable_tivo = lib.mkOption {
80
+
type = lib.types.enum [ "yes" "no" ];
description = "Support for streaming .jpg and .mp3 files to a TiVo supporting HMO.";
104
-
options.wide_links = mkOption {
105
-
type = types.enum [ "yes" "no" ];
84
+
options.wide_links = lib.mkOption {
85
+
type = lib.types.enum [ "yes" "no" ];
description = "Set this to yes to allow symlinks that point outside user-defined `media_dir`.";
113
-
(mkRemovedOptionModule [ "services" "minidlna" "config" ] "")
114
-
(mkRemovedOptionModule [ "services" "minidlna" "extraConfig" ] "")
115
-
(mkRenamedOptionModule [ "services" "minidlna" "loglevel"] [ "services" "minidlna" "settings" "log_level" ])
116
-
(mkRenamedOptionModule [ "services" "minidlna" "rootContainer"] [ "services" "minidlna" "settings" "root_container" ])
117
-
(mkRenamedOptionModule [ "services" "minidlna" "mediaDirs"] [ "services" "minidlna" "settings" "media_dir" ])
118
-
(mkRenamedOptionModule [ "services" "minidlna" "friendlyName"] [ "services" "minidlna" "settings" "friendly_name" ])
119
-
(mkRenamedOptionModule [ "services" "minidlna" "announceInterval"] [ "services" "minidlna" "settings" "notify_interval" ])
92
+
config = lib.mkIf cfg.enable {
93
+
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.settings.port ];
94
+
networking.firewall.allowedUDPPorts = lib.mkIf cfg.openFirewall [ 1900 ];
122
-
###### implementation
123
-
config = mkIf cfg.enable {
124
-
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.port ];
125
-
networking.firewall.allowedUDPPorts = mkIf cfg.openFirewall [ 1900 ];
96
+
users.groups.minidlna.gid = config.ids.gids.minidlna;
description = "MiniDLNA daemon user";
uid = config.ids.uids.minidlna;
133
-
users.groups.minidlna.gid = config.ids.gids.minidlna;
systemd.services.minidlna = {
description = "MiniDLNA Server";
···
CacheDirectory = "minidlna";
RuntimeDirectory = "minidlna";
PIDFile = "/run/minidlna/pid";
146
-
ExecStart = "${lib.getExe cfg.package} -S -P /run/minidlna/pid -f ${settingsFile}";
114
+
ExecStart = "${lib.getExe cfg.package} -S -P /run/minidlna/pid -f ${cfgfile}";