2013-02-16 22:08:53 +00:00
|
|
|
# Module for MiniDLNA, a simple DLNA server.
|
2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-02-16 22:08:53 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2013-02-16 22:08:53 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.minidlna;
|
2021-11-19 14:44:09 +00:00
|
|
|
settingsFormat = pkgs.formats.keyValue { listsAsDuplicateKeys = true; };
|
|
|
|
settingsFile = settingsFormat.generate "minidlna.conf" cfg.settings;
|
2013-02-16 22:08:53 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
###### interface
|
2021-11-19 14:44:09 +00:00
|
|
|
options.services.minidlna.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-11-19 14:44:09 +00:00
|
|
|
Whether to enable MiniDLNA, a simple DLNA server.
|
|
|
|
It serves media files such as video and music to DLNA client devices
|
|
|
|
such as televisions and media players. If you use the firewall consider
|
2022-07-28 21:19:15 +00:00
|
|
|
adding the following: `services.minidlna.openFirewall = true;`
|
2021-11-19 14:44:09 +00:00
|
|
|
'';
|
|
|
|
};
|
2013-02-16 22:08:53 +00:00
|
|
|
|
2021-11-19 14:44:09 +00:00
|
|
|
options.services.minidlna.openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-11-19 14:44:09 +00:00
|
|
|
Whether to open both HTTP (TCP) and SSDP (UDP) ports in the firewall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
options.services.minidlna.settings = mkOption {
|
|
|
|
default = {};
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-11-19 14:44:09 +00:00
|
|
|
The contents of MiniDLNA's configuration file.
|
|
|
|
When the service is activated, a basic template is generated
|
|
|
|
from the current options opened here.
|
|
|
|
'';
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = settingsFormat.type;
|
|
|
|
|
|
|
|
options.media_dir = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "/data/media" "V,/home/alice/video" ];
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-11-19 14:44:09 +00:00
|
|
|
Directories to be scanned for media files.
|
2022-07-28 21:19:15 +00:00
|
|
|
The prefixes `A,`,`V,` and
|
|
|
|
`P,` restrict a directory to audio, video
|
2021-11-19 14:44:09 +00:00
|
|
|
or image files. The directories must be accessible to the
|
2022-07-28 21:19:15 +00:00
|
|
|
`minidlna` user account.
|
2013-02-16 22:08:53 +00:00
|
|
|
'';
|
2021-11-19 14:44:09 +00:00
|
|
|
};
|
|
|
|
options.notify_interval = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 90000;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-01-19 13:06:27 +00:00
|
|
|
The interval between announces (in seconds).
|
2021-11-19 14:44:09 +00:00
|
|
|
Instead of waiting on announces, one can open port UDP 1900 or
|
2022-07-28 21:19:15 +00:00
|
|
|
set `openFirewall` option to use SSDP discovery.
|
2021-11-19 14:44:09 +00:00
|
|
|
Furthermore announce interval has now been set as 90000 in order
|
|
|
|
to prevent disconnects with certain clients and to rely solely
|
|
|
|
on the SSDP method.
|
|
|
|
|
|
|
|
Lower values (e.g. 60 seconds) should be used if one does not
|
|
|
|
want to utilize SSDP. By default miniDLNA will announce its
|
|
|
|
presence on the network approximately every 15 minutes. Many
|
|
|
|
people prefer shorter announce intervals on their home networks,
|
|
|
|
especially when DLNA clients are started on demand.
|
2021-07-22 21:02:08 +00:00
|
|
|
|
|
|
|
Some relevant information can be found here:
|
|
|
|
https://sourceforge.net/p/minidlna/discussion/879957/thread/1389d197/
|
|
|
|
'';
|
|
|
|
};
|
2021-11-19 14:44:09 +00:00
|
|
|
options.port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8200;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Port number for HTTP traffic (descriptions, SOAP, media transfer).";
|
2021-11-19 14:44:09 +00:00
|
|
|
};
|
|
|
|
options.db_dir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/cache/minidlna";
|
|
|
|
example = "/tmp/minidlna";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Specify the directory where you want MiniDLNA to store its database and album art cache.";
|
2021-11-19 14:44:09 +00:00
|
|
|
};
|
|
|
|
options.friendly_name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "${config.networking.hostName} MiniDLNA";
|
|
|
|
defaultText = literalExpression "config.networking.hostName";
|
|
|
|
example = "rpi3";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Name that the DLNA server presents to clients.";
|
2021-11-19 14:44:09 +00:00
|
|
|
};
|
|
|
|
options.root_container = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = ".";
|
|
|
|
example = "B";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Use a different container as the root of the directory tree presented to clients.";
|
2021-11-19 14:44:09 +00:00
|
|
|
};
|
|
|
|
options.log_level = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "warn";
|
|
|
|
example = "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Defines the type of messages that should be logged and down to which level of importance.";
|
2021-11-19 14:44:09 +00:00
|
|
|
};
|
|
|
|
options.inotify = mkOption {
|
|
|
|
type = types.enum [ "yes" "no" ];
|
|
|
|
default = "no";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Whether to enable inotify monitoring to automatically discover new files.";
|
2021-11-19 14:44:09 +00:00
|
|
|
};
|
|
|
|
options.enable_tivo = mkOption {
|
|
|
|
type = types.enum [ "yes" "no" ];
|
|
|
|
default = "no";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Support for streaming .jpg and .mp3 files to a TiVo supporting HMO.";
|
2021-11-19 14:44:09 +00:00
|
|
|
};
|
|
|
|
options.wide_links = mkOption {
|
|
|
|
type = types.enum [ "yes" "no" ];
|
|
|
|
default = "no";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Set this to yes to allow symlinks that point outside user-defined media_dirs.";
|
2021-11-19 14:44:09 +00:00
|
|
|
};
|
2013-02-16 22:08:53 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-11-19 14:44:09 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "minidlna" "config" ] "")
|
|
|
|
(mkRemovedOptionModule [ "services" "minidlna" "extraConfig" ] "")
|
|
|
|
(mkRenamedOptionModule [ "services" "minidlna" "loglevel"] [ "services" "minidlna" "settings" "log_level" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "minidlna" "rootContainer"] [ "services" "minidlna" "settings" "root_container" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "minidlna" "mediaDirs"] [ "services" "minidlna" "settings" "media_dir" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "minidlna" "friendlyName"] [ "services" "minidlna" "settings" "friendly_name" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "minidlna" "announceInterval"] [ "services" "minidlna" "settings" "notify_interval" ])
|
|
|
|
];
|
|
|
|
|
2013-02-16 22:08:53 +00:00
|
|
|
###### implementation
|
|
|
|
config = mkIf cfg.enable {
|
2021-11-19 14:44:09 +00:00
|
|
|
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.port ];
|
2021-07-22 21:02:08 +00:00
|
|
|
networking.firewall.allowedUDPPorts = mkIf cfg.openFirewall [ 1900 ];
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.users.minidlna = {
|
2013-08-26 13:20:25 +00:00
|
|
|
description = "MiniDLNA daemon user";
|
|
|
|
group = "minidlna";
|
|
|
|
uid = config.ids.uids.minidlna;
|
|
|
|
};
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.groups.minidlna.gid = config.ids.gids.minidlna;
|
2013-02-16 22:08:53 +00:00
|
|
|
|
|
|
|
systemd.services.minidlna =
|
|
|
|
{ description = "MiniDLNA Server";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2019-09-01 01:07:23 +00:00
|
|
|
after = [ "network.target" ];
|
2013-02-16 22:08:53 +00:00
|
|
|
|
|
|
|
serviceConfig =
|
|
|
|
{ User = "minidlna";
|
2016-04-08 20:37:11 +00:00
|
|
|
Group = "minidlna";
|
2019-02-24 12:17:37 +00:00
|
|
|
CacheDirectory = "minidlna";
|
2016-04-08 20:37:11 +00:00
|
|
|
RuntimeDirectory = "minidlna";
|
2013-02-16 22:08:53 +00:00
|
|
|
PIDFile = "/run/minidlna/pid";
|
|
|
|
ExecStart =
|
2016-04-08 20:37:11 +00:00
|
|
|
"${pkgs.minidlna}/sbin/minidlnad -S -P /run/minidlna/pid" +
|
2021-11-19 14:44:09 +00:00
|
|
|
" -f ${settingsFile}";
|
2013-02-16 22:08:53 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|