1 # Module for MiniDLNA, a simple DLNA server.
2 { config, lib, pkgs, ... }:
6 cfg = config.services.minidlna;
7 settingsFormat = pkgs.formats.keyValue { listsAsDuplicateKeys = true; };
8 settingsFile = settingsFormat.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;`
24 options.services.minidlna.openFirewall = mkOption {
28 Whether to open both HTTP (TCP) and SSDP (UDP) ports in the firewall.
32 options.services.minidlna.settings = mkOption {
35 The contents of MiniDLNA's configuration file.
36 When the service is activated, a basic template is generated from the current options opened here.
38 type = types.submodule {
39 freeformType = settingsFormat.type;
41 options.media_dir = mkOption {
42 type = types.listOf types.str;
44 example = [ "/data/media" "V,/home/alice/video" ];
46 Directories to be scanned for media files.
47 The `A,` `V,` `P,` prefixes restrict a directory to audio, video or image files.
48 The directories must be accessible to the `minidlna` user account.
51 options.notify_interval = mkOption {
55 The interval between announces (in seconds).
56 Instead of waiting for announces, you should set `openFirewall` option to use SSDP discovery.
57 Lower values (e.g. 30 seconds) should be used if your network blocks the discovery unicast.
58 Some relevant information can be found here:
59 https://sourceforge.net/p/minidlna/discussion/879957/thread/1389d197/
62 options.port = mkOption {
65 description = "Port number for HTTP traffic (descriptions, SOAP, media transfer).";
67 options.db_dir = mkOption {
69 default = "/var/cache/minidlna";
70 example = "/tmp/minidlna";
71 description = "Specify the directory where you want MiniDLNA to store its database and album art cache.";
73 options.friendly_name = mkOption {
75 default = config.networking.hostName;
76 defaultText = literalExpression "config.networking.hostName";
78 description = "Name that the DLNA server presents to clients.";
80 options.root_container = mkOption {
84 description = "Use a different container as the root of the directory tree presented to clients.";
86 options.log_level = mkOption {
89 example = "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn";
90 description = "Defines the type of messages that should be logged and down to which level of importance.";
92 options.inotify = mkOption {
93 type = types.enum [ "yes" "no" ];
95 description = "Whether to enable inotify monitoring to automatically discover new files.";
97 options.enable_tivo = mkOption {
98 type = types.enum [ "yes" "no" ];
100 description = "Support for streaming .jpg and .mp3 files to a TiVo supporting HMO.";
102 options.wide_links = mkOption {
103 type = types.enum [ "yes" "no" ];
105 description = "Set this to yes to allow symlinks that point outside user-defined `media_dir`.";
111 (mkRemovedOptionModule [ "services" "minidlna" "config" ] "")
112 (mkRemovedOptionModule [ "services" "minidlna" "extraConfig" ] "")
113 (mkRenamedOptionModule [ "services" "minidlna" "loglevel"] [ "services" "minidlna" "settings" "log_level" ])
114 (mkRenamedOptionModule [ "services" "minidlna" "rootContainer"] [ "services" "minidlna" "settings" "root_container" ])
115 (mkRenamedOptionModule [ "services" "minidlna" "mediaDirs"] [ "services" "minidlna" "settings" "media_dir" ])
116 (mkRenamedOptionModule [ "services" "minidlna" "friendlyName"] [ "services" "minidlna" "settings" "friendly_name" ])
117 (mkRenamedOptionModule [ "services" "minidlna" "announceInterval"] [ "services" "minidlna" "settings" "notify_interval" ])
120 ###### implementation
121 config = mkIf cfg.enable {
122 networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.port ];
123 networking.firewall.allowedUDPPorts = mkIf cfg.openFirewall [ 1900 ];
125 users.users.minidlna = {
126 description = "MiniDLNA daemon user";
128 uid = config.ids.uids.minidlna;
131 users.groups.minidlna.gid = config.ids.gids.minidlna;
133 systemd.services.minidlna = {
134 description = "MiniDLNA Server";
135 wantedBy = [ "multi-user.target" ];
136 after = [ "network.target" ];
141 CacheDirectory = "minidlna";
142 RuntimeDirectory = "minidlna";
143 PIDFile = "/run/minidlna/pid";
144 ExecStart = "${pkgs.minidlna}/sbin/minidlnad -S -P /run/minidlna/pid -f ${settingsFile}";