From 547251956b2dad7de893eb09e876a8e79df6f9b9 Mon Sep 17 00:00:00 2001 From: bb2020 Date: Sun, 8 Sep 2024 13:34:19 +0300 Subject: [PATCH 1/3] nixos/minidlna: remove with lib --- .../modules/services/networking/minidlna.nix | 75 +++++++++---------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/nixos/modules/services/networking/minidlna.nix b/nixos/modules/services/networking/minidlna.nix index caebb3f08fc2..999de02f3e06 100644 --- a/nixos/modules/services/networking/minidlna.nix +++ b/nixos/modules/services/networking/minidlna.nix @@ -1,6 +1,5 @@ # Module for MiniDLNA, a simple DLNA server. { config, lib, pkgs, ... }: -with lib; let cfg = config.services.minidlna; @@ -10,8 +9,8 @@ in { ###### interface - options.services.minidlna.enable = mkOption { - type = types.bool; + options.services.minidlna.enable = lib.mkOption { + type = lib.types.bool; default = false; description = '' Whether to enable MiniDLNA, a simple DLNA server. @@ -23,25 +22,25 @@ in options.services.minidlna.package = lib.mkPackageOption pkgs "minidlna" { }; - options.services.minidlna.openFirewall = mkOption { - type = types.bool; + options.services.minidlna.openFirewall = lib.mkOption { + type = lib.types.bool; default = false; description = '' Whether to open both HTTP (TCP) and SSDP (UDP) ports in the firewall. ''; }; - options.services.minidlna.settings = mkOption { + options.services.minidlna.settings = lib.mkOption { default = {}; description = '' 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 { + type = lib.types.submodule { freeformType = settingsFormat.type; - options.media_dir = mkOption { - type = types.listOf types.str; + options.media_dir = lib.mkOption { + type = lib.types.listOf lib.types.str; default = []; example = [ "/data/media" "V,/home/alice/video" ]; description = '' @@ -50,8 +49,8 @@ in The directories must be accessible to the `minidlna` user account. ''; }; - options.notify_interval = mkOption { - type = types.int; + options.notify_interval = lib.mkOption { + type = lib.types.int; default = 90000; description = '' The interval between announces (in seconds). @@ -61,48 +60,48 @@ in https://sourceforge.net/p/minidlna/discussion/879957/thread/1389d197/ ''; }; - options.port = mkOption { - type = types.port; + options.port = lib.mkOption { + type = lib.types.port; default = 8200; description = "Port number for HTTP traffic (descriptions, SOAP, media transfer)."; }; - options.db_dir = mkOption { - type = types.path; + options.db_dir = lib.mkOption { + type = lib.types.path; default = "/var/cache/minidlna"; example = "/tmp/minidlna"; description = "Specify the directory where you want MiniDLNA to store its database and album art cache."; }; - options.friendly_name = mkOption { - type = types.str; + options.friendly_name = lib.mkOption { + type = lib.types.str; default = config.networking.hostName; - defaultText = literalExpression "config.networking.hostName"; + defaultText = lib.literalExpression "config.networking.hostName"; example = "rpi3"; description = "Name that the DLNA server presents to clients."; }; - options.root_container = mkOption { - type = types.str; + options.root_container = lib.mkOption { + type = lib.types.str; default = "B"; example = "."; description = "Use a different container as the root of the directory tree presented to clients."; }; - options.log_level = mkOption { - type = types.str; + 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."; }; - options.inotify = mkOption { - type = types.enum [ "yes" "no" ]; + options.inotify = lib.mkOption { + type = lib.types.enum [ "yes" "no" ]; default = "no"; description = "Whether to enable inotify monitoring to automatically discover new files."; }; - options.enable_tivo = mkOption { - type = types.enum [ "yes" "no" ]; + 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."; }; - options.wide_links = mkOption { - type = types.enum [ "yes" "no" ]; + options.wide_links = lib.mkOption { + type = lib.types.enum [ "yes" "no" ]; default = "no"; description = "Set this to yes to allow symlinks that point outside user-defined `media_dir`."; }; @@ -110,19 +109,19 @@ in }; 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" ]) + (lib.mkRemovedOptionModule [ "services" "minidlna" "config" ] "") + (lib.mkRemovedOptionModule [ "services" "minidlna" "extraConfig" ] "") + (lib.mkRenamedOptionModule [ "services" "minidlna" "loglevel"] [ "services" "minidlna" "settings" "log_level" ]) + (lib.mkRenamedOptionModule [ "services" "minidlna" "rootContainer"] [ "services" "minidlna" "settings" "root_container" ]) + (lib.mkRenamedOptionModule [ "services" "minidlna" "mediaDirs"] [ "services" "minidlna" "settings" "media_dir" ]) + (lib.mkRenamedOptionModule [ "services" "minidlna" "friendlyName"] [ "services" "minidlna" "settings" "friendly_name" ]) + (lib.mkRenamedOptionModule [ "services" "minidlna" "announceInterval"] [ "services" "minidlna" "settings" "notify_interval" ]) ]; ###### implementation - config = mkIf cfg.enable { - networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.port ]; - networking.firewall.allowedUDPPorts = mkIf cfg.openFirewall [ 1900 ]; + config = lib.mkIf cfg.enable { + networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.settings.port ]; + networking.firewall.allowedUDPPorts = lib.mkIf cfg.openFirewall [ 1900 ]; users.users.minidlna = { description = "MiniDLNA daemon user"; From 93d38a29e0e473731b36e5d6f8e7ea12c3e58f3d Mon Sep 17 00:00:00 2001 From: bb2020 Date: Sat, 5 Oct 2024 11:27:56 +0300 Subject: [PATCH 2/3] nixos/minidlna: add option --- nixos/modules/services/networking/minidlna.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nixos/modules/services/networking/minidlna.nix b/nixos/modules/services/networking/minidlna.nix index 999de02f3e06..efdc9a467761 100644 --- a/nixos/modules/services/networking/minidlna.nix +++ b/nixos/modules/services/networking/minidlna.nix @@ -90,6 +90,11 @@ in 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."; }; + options.enable_subtitles = lib.mkOption { + type = lib.types.enum [ "yes" "no" ]; + default = "yes"; + description = "Enable subtitle support on unknown clients."; + }; options.inotify = lib.mkOption { type = lib.types.enum [ "yes" "no" ]; default = "no"; From cf63529fc55b4d1088cb9d724a623b8679e2b721 Mon Sep 17 00:00:00 2001 From: bb2020 Date: Sat, 5 Oct 2024 11:28:22 +0300 Subject: [PATCH 3/3] nixos/minidlna: refactor --- .../modules/services/networking/minidlna.nix | 64 ++++--------------- 1 file changed, 14 insertions(+), 50 deletions(-) diff --git a/nixos/modules/services/networking/minidlna.nix b/nixos/modules/services/networking/minidlna.nix index efdc9a467761..8363f7950147 100644 --- a/nixos/modules/services/networking/minidlna.nix +++ b/nixos/modules/services/networking/minidlna.nix @@ -1,43 +1,20 @@ -# Module for MiniDLNA, a simple DLNA server. { config, lib, pkgs, ... }: let cfg = config.services.minidlna; - settingsFormat = pkgs.formats.keyValue { listsAsDuplicateKeys = true; }; - settingsFile = settingsFormat.generate "minidlna.conf" cfg.settings; -in + format = pkgs.formats.keyValue { listsAsDuplicateKeys = true; }; + cfgfile = format.generate "minidlna.conf" cfg.settings; -{ - ###### interface - options.services.minidlna.enable = lib.mkOption { - type = lib.types.bool; - default = false; - description = '' - 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 - adding the following: `services.minidlna.openFirewall = true;` - ''; - }; - - options.services.minidlna.package = lib.mkPackageOption pkgs "minidlna" { }; - - options.services.minidlna.openFirewall = lib.mkOption { - type = lib.types.bool; - default = false; - description = '' - Whether to open both HTTP (TCP) and SSDP (UDP) ports in the firewall. - ''; - }; +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" {}; options.services.minidlna.settings = lib.mkOption { default = {}; - description = '' - The contents of MiniDLNA's configuration file. - When the service is activated, a basic template is generated from the current options opened here. - ''; + description = "Configuration for `minidlna.conf(5)`."; type = lib.types.submodule { - freeformType = settingsFormat.type; + freeformType = format.type; options.media_dir = lib.mkOption { type = lib.types.listOf lib.types.str; @@ -55,9 +32,8 @@ in description = '' The interval between announces (in seconds). Instead of waiting for announces, you should set `openFirewall` option to use SSDP discovery. - Lower values (e.g. 30 seconds) should be used if your network blocks the discovery unicast. - Some relevant information can be found here: - https://sourceforge.net/p/minidlna/discussion/879957/thread/1389d197/ + 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/). ''; }; options.port = lib.mkOption { @@ -69,14 +45,14 @@ in type = lib.types.path; default = "/var/cache/minidlna"; example = "/tmp/minidlna"; - description = "Specify the directory where you want MiniDLNA to store its database and album art cache."; + description = "Specify the directory to store database and album art cache."; }; options.friendly_name = lib.mkOption { type = lib.types.str; default = config.networking.hostName; defaultText = lib.literalExpression "config.networking.hostName"; example = "rpi3"; - description = "Name that the DLNA server presents to clients."; + description = "Name that the server presents to clients."; }; options.root_container = lib.mkOption { type = lib.types.str; @@ -113,29 +89,17 @@ in }; }; - imports = [ - (lib.mkRemovedOptionModule [ "services" "minidlna" "config" ] "") - (lib.mkRemovedOptionModule [ "services" "minidlna" "extraConfig" ] "") - (lib.mkRenamedOptionModule [ "services" "minidlna" "loglevel"] [ "services" "minidlna" "settings" "log_level" ]) - (lib.mkRenamedOptionModule [ "services" "minidlna" "rootContainer"] [ "services" "minidlna" "settings" "root_container" ]) - (lib.mkRenamedOptionModule [ "services" "minidlna" "mediaDirs"] [ "services" "minidlna" "settings" "media_dir" ]) - (lib.mkRenamedOptionModule [ "services" "minidlna" "friendlyName"] [ "services" "minidlna" "settings" "friendly_name" ]) - (lib.mkRenamedOptionModule [ "services" "minidlna" "announceInterval"] [ "services" "minidlna" "settings" "notify_interval" ]) - ]; - - ###### implementation config = lib.mkIf cfg.enable { networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.settings.port ]; networking.firewall.allowedUDPPorts = lib.mkIf cfg.openFirewall [ 1900 ]; + users.groups.minidlna.gid = config.ids.gids.minidlna; users.users.minidlna = { description = "MiniDLNA daemon user"; group = "minidlna"; uid = config.ids.uids.minidlna; }; - users.groups.minidlna.gid = config.ids.gids.minidlna; - systemd.services.minidlna = { description = "MiniDLNA Server"; wantedBy = [ "multi-user.target" ]; @@ -147,7 +111,7 @@ in CacheDirectory = "minidlna"; RuntimeDirectory = "minidlna"; PIDFile = "/run/minidlna/pid"; - ExecStart = "${lib.getExe cfg.package} -S -P /run/minidlna/pid -f ${settingsFile}"; + ExecStart = "${lib.getExe cfg.package} -S -P /run/minidlna/pid -f ${cfgfile}"; }; }; };