nixpkgs/nixos/modules/services/networking/minidlna.nix

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

140 lines
4.8 KiB
Nix
Raw Permalink Normal View History

{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.minidlna;
2024-10-05 11:28:22 +03:00
format = pkgs.formats.keyValue { listsAsDuplicateKeys = true; };
cfgfile = format.generate "minidlna.conf" cfg.settings;
2024-10-05 11:28:22 +03:00
in
{
options.services.minidlna.enable = lib.mkEnableOption "MiniDLNA, a simple DLNA server. Consider adding `openFirewall = true` into your config";
options.services.minidlna.openFirewall = lib.mkEnableOption "opening HTTP (TCP) and SSDP (UDP) ports in the firewall";
options.services.minidlna.package = lib.mkPackageOption pkgs "minidlna" { };
2024-09-08 13:34:19 +03:00
options.services.minidlna.settings = lib.mkOption {
default = { };
2025-01-27 02:10:23 +01:00
description = "Configuration for {manpage}`minidlna.conf(5)`.";
2024-09-08 13:34:19 +03:00
type = lib.types.submodule {
2024-10-05 11:28:22 +03:00
freeformType = format.type;
2024-09-08 13:34:19 +03:00
options.media_dir = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
example = [
"/data/media"
"V,/home/alice/video"
];
description = ''
Directories to be scanned for media files.
2022-08-02 00:26:23 +03:00
The `A,` `V,` `P,` prefixes restrict a directory to audio, video or image files.
The directories must be accessible to the `minidlna` user account.
'';
};
2024-09-08 13:34:19 +03:00
options.notify_interval = lib.mkOption {
type = lib.types.int;
default = 90000;
description = ''
The interval between announces (in seconds).
2022-08-02 00:26:23 +03:00
Instead of waiting for announces, you should set `openFirewall` option to use SSDP discovery.
2024-10-05 11:28:22 +03:00
Lower values (e.g. 30 seconds) should be used if your network is blocking the SSDP multicast.
Some relevant information can be found [here](https://sourceforge.net/p/minidlna/discussion/879957/thread/1389d197/).
'';
};
2024-09-08 13:34:19 +03:00
options.port = lib.mkOption {
type = lib.types.port;
default = 8200;
description = "Port number for HTTP traffic (descriptions, SOAP, media transfer).";
};
2024-09-08 13:34:19 +03:00
options.db_dir = lib.mkOption {
type = lib.types.path;
default = "/var/cache/minidlna";
example = "/tmp/minidlna";
2024-10-05 11:28:22 +03:00
description = "Specify the directory to store database and album art cache.";
};
2024-09-08 13:34:19 +03:00
options.friendly_name = lib.mkOption {
type = lib.types.str;
2022-08-02 00:26:23 +03:00
default = config.networking.hostName;
2024-09-08 13:34:19 +03:00
defaultText = lib.literalExpression "config.networking.hostName";
example = "rpi3";
2024-10-05 11:28:22 +03:00
description = "Name that the server presents to clients.";
};
2024-09-08 13:34:19 +03:00
options.root_container = lib.mkOption {
type = lib.types.str;
2023-01-12 10:51:00 +03:00
default = "B";
example = ".";
description = "Use a different container as the root of the directory tree presented to clients.";
};
2024-09-08 13:34:19 +03:00
options.log_level = lib.mkOption {
type = lib.types.str;
default = "warn";
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.";
};
2024-10-05 11:27:56 +03:00
options.enable_subtitles = lib.mkOption {
type = lib.types.enum [
"yes"
"no"
];
default = "yes";
description = "Enable subtitle support on unknown clients.";
};
2024-09-08 13:34:19 +03:00
options.inotify = lib.mkOption {
type = lib.types.enum [
"yes"
"no"
];
default = "no";
description = "Whether to enable inotify monitoring to automatically discover new files.";
};
2024-09-08 13:34:19 +03:00
options.enable_tivo = lib.mkOption {
type = lib.types.enum [
"yes"
"no"
];
default = "no";
description = "Support for streaming .jpg and .mp3 files to a TiVo supporting HMO.";
};
2024-09-08 13:34:19 +03:00
options.wide_links = lib.mkOption {
type = lib.types.enum [
"yes"
"no"
];
default = "no";
2022-08-02 00:26:23 +03:00
description = "Set this to yes to allow symlinks that point outside user-defined `media_dir`.";
};
};
};
2024-09-08 13:34:19 +03:00
config = lib.mkIf cfg.enable {
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.settings.port ];
networking.firewall.allowedUDPPorts = lib.mkIf cfg.openFirewall [ 1900 ];
2024-10-05 11:28:22 +03:00
users.groups.minidlna.gid = config.ids.gids.minidlna;
users.users.minidlna = {
2013-08-26 15:20:25 +02:00
description = "MiniDLNA daemon user";
group = "minidlna";
uid = config.ids.uids.minidlna;
};
2023-01-12 10:51:00 +03:00
systemd.services.minidlna = {
description = "MiniDLNA Server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
2023-01-12 10:51:00 +03:00
serviceConfig = {
User = "minidlna";
Group = "minidlna";
CacheDirectory = "minidlna";
RuntimeDirectory = "minidlna";
PIDFile = "/run/minidlna/pid";
2024-10-05 11:28:22 +03:00
ExecStart = "${lib.getExe cfg.package} -S -P /run/minidlna/pid -f ${cfgfile}";
};
2023-01-12 10:51:00 +03:00
};
};
}