{ config, lib, pkgs, ... }: with lib; let gid = config.ids.gids.mediatomb; cfg = config.services.mediatomb; mtConf = pkgs.writeText "config.xml" '' ${cfg.serverName} uuid:${cfg.uuid} ${cfg.dataDir} ${pkgs.mediatomb}/share/mediatomb/web mediatomb.db ${if cfg.dsmSupport then '' redsonic.com 105 '' else ""} ${if cfg.tg100Support then '' 101 '' else ""} * video ${pkgs.mediatomb}/share/mediatomb/js/common.js ${pkgs.mediatomb}/share/mediatomb/js/playlists.js ${pkgs.mediatomb}/share/mediatomb/js/import.js ${if cfg.ps3Support then '' '' else ""} ${if cfg.dsmSupport then '' '' else ""} audio/L16 no yes no video/mpeg yes yes yes ''; in { ###### interface options = { services.mediatomb = { enable = mkOption { type = types.bool; default = false; description = '' Whether to enable the mediatomb DLNA server. ''; }; serverName = mkOption { type = types.str; default = "mediatomb"; description = '' How to identify the server on the network. ''; }; ps3Support = mkOption { type = types.bool; default = false; description = '' Whether to enable ps3 specific tweaks. WARNING: incompatible with DSM 320 support. ''; }; dsmSupport = mkOption { type = types.bool; default = false; description = '' Whether to enable D-Link DSM 320 specific tweaks. WARNING: incompatible with ps3 support. ''; }; tg100Support = mkOption { type = types.bool; default = false; description = '' Whether to enable Telegent TG100 specific tweaks. ''; }; transcoding = mkOption { type = types.bool; default = false; description = '' Whether to enable transcoding. ''; }; dataDir = mkOption { type = types.path; default = "/var/lib/mediatomb"; description = '' The directory where mediatomb stores its state, data, etc. ''; }; user = mkOption { default = "mediatomb"; description = "User account under which mediatomb runs."; }; group = mkOption { default = "mediatomb"; description = "Group account under which mediatomb runs."; }; port = mkOption { default = 49152; description = '' The network port to listen on. ''; }; interface = mkOption { default = ""; description = '' A specific interface to bind to. ''; }; uuid = mkOption { default = "fdfc8a4e-a3ad-4c1d-b43d-a2eedb03a687"; description = '' A unique (on your network) to identify the server by. ''; }; customCfg = mkOption { type = types.bool; default = false; description = '' Allow mediatomb to create and use its own config file inside ${cfg.dataDir}. ''; }; }; }; ###### implementation config = mkIf cfg.enable { systemd.services.mediatomb = { description = "MediaTomb media Server"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; path = [ pkgs.mediatomb ]; serviceConfig.ExecStart = "${pkgs.mediatomb}/bin/mediatomb -p ${toString cfg.port} ${if cfg.interface!="" then "-e ${cfg.interface}" else ""} ${if cfg.customCfg then "" else "-c ${mtConf}"} -m ${cfg.dataDir}"; serviceConfig.User = "${cfg.user}"; }; users.groups = optionalAttrs (cfg.group == "mediatomb") { mediatomb.gid = gid; }; users.users = optionalAttrs (cfg.user == "mediatomb") { mediatomb = { isSystemUser = true; group = cfg.group; home = "${cfg.dataDir}"; createHome = true; description = "Mediatomb DLNA Server User"; }; }; networking.firewall = { allowedUDPPorts = [ 1900 cfg.port ]; allowedTCPPorts = [ cfg.port ]; }; }; }