at 17.09-beta 2.5 kB view raw
1# Module for MiniDLNA, a simple DLNA server. 2 3{ config, lib, pkgs, ... }: 4 5with lib; 6 7let 8 9 cfg = config.services.minidlna; 10 11 port = 8200; 12 13in 14 15{ 16 17 ###### interface 18 19 options = { 20 21 services.minidlna.enable = mkOption { 22 type = types.bool; 23 default = false; 24 description = 25 '' 26 Whether to enable MiniDLNA, a simple DLNA server. It serves 27 media files such as video and music to DLNA client devices 28 such as televisions and media players. 29 ''; 30 }; 31 32 services.minidlna.mediaDirs = mkOption { 33 type = types.listOf types.str; 34 default = []; 35 example = [ "/data/media" "V,/home/alice/video" ]; 36 description = 37 '' 38 Directories to be scanned for media files. The prefixes 39 <literal>A,</literal>, <literal>V,</literal> and 40 <literal>P,</literal> restrict a directory to audio, video 41 or image files. The directories must be accessible to the 42 <literal>minidlna</literal> user account. 43 ''; 44 }; 45 46 services.minidlna.config = mkOption { 47 type = types.lines; 48 description = "The contents of MiniDLNA's configuration file."; 49 }; 50 51 }; 52 53 54 ###### implementation 55 56 config = mkIf cfg.enable { 57 58 services.minidlna.config = 59 '' 60 port=${toString port} 61 friendly_name=${config.networking.hostName} MiniDLNA 62 db_dir=/var/cache/minidlna 63 log_level=warn 64 inotify=yes 65 ${concatMapStrings (dir: '' 66 media_dir=${dir} 67 '') cfg.mediaDirs} 68 ''; 69 70 users.extraUsers.minidlna = { 71 description = "MiniDLNA daemon user"; 72 group = "minidlna"; 73 uid = config.ids.uids.minidlna; 74 }; 75 76 users.extraGroups.minidlna.gid = config.ids.gids.minidlna; 77 78 systemd.services.minidlna = 79 { description = "MiniDLNA Server"; 80 81 wantedBy = [ "multi-user.target" ]; 82 after = [ "network.target" "local-fs.target" ]; 83 84 preStart = 85 '' 86 mkdir -p /var/cache/minidlna 87 chown -R minidlna:minidlna /var/cache/minidlna 88 ''; 89 90 serviceConfig = 91 { User = "minidlna"; 92 Group = "minidlna"; 93 PermissionsStartOnly = true; 94 RuntimeDirectory = "minidlna"; 95 PIDFile = "/run/minidlna/pid"; 96 ExecStart = 97 "${pkgs.minidlna}/sbin/minidlnad -S -P /run/minidlna/pid" + 98 " -f ${pkgs.writeText "minidlna.conf" cfg.config}"; 99 }; 100 }; 101 102 }; 103 104}