diff --git a/nixos/modules/services/misc/mediatomb.nix b/nixos/modules/services/misc/mediatomb.nix index 529f584a201..ba2bbfbc221 100644 --- a/nixos/modules/services/misc/mediatomb.nix +++ b/nixos/modules/services/misc/mediatomb.nix @@ -6,37 +6,42 @@ let gid = config.ids.gids.mediatomb; cfg = config.services.mediatomb; + name = cfg.package.pname; + pkg = cfg.package; + optionYesNo = option: if option then "yes" else "no"; mtConf = pkgs.writeText "config.xml" '' + ${cfg.interface} - + ${cfg.serverName} uuid:${cfg.uuid} ${cfg.dataDir} - ${pkgs.mediatomb}/share/mediatomb/web + ${cfg.interface} + ${pkg}/share/${name}/web - mediatomb.db + ${name}.db - - ${if cfg.dsmSupport then '' + + ${lib.optionalString cfg.dsmSupport '' redsonic.com 105 - '' else ""} - ${if cfg.tg100Support then '' + ''} + ${optionalString cfg.tg100Support '' 101 - '' else ""} + ''} * @@ -48,10 +53,10 @@ let - ${pkgs.mediatomb}/share/mediatomb/js/common.js - ${pkgs.mediatomb}/share/mediatomb/js/playlists.js + ${pkg}/share/${name}/js/common.js + ${pkg}/share/${name}/js/playlists.js - ${pkgs.mediatomb}/share/mediatomb/js/import.js + ${pkg}/share/${name}/js/import.js @@ -75,12 +80,12 @@ let - ${if cfg.ps3Support then '' + ${optionalString cfg.ps3Support '' - '' else ""} - ${if cfg.dsmSupport then '' + ''} + ${optionalString cfg.dsmSupport '' - '' else ""} + ''} @@ -108,10 +113,10 @@ let - + - - + + @@ -158,18 +163,27 @@ in { type = types.bool; default = false; description = '' - Whether to enable the mediatomb DLNA server. + Whether to enable the Gerbera/Mediatomb DLNA server. ''; }; serverName = mkOption { type = types.str; - default = "mediatomb"; + default = "Gerbera (Mediatomb)"; description = '' How to identify the server on the network. ''; }; + package = mkOption { + type = types.package; + example = literalExample "pkgs.mediatomb"; + default = pkgs.gerbera; + description = '' + Underlying package to be used with the module (default: pkgs.gerbera). + ''; + }; + ps3Support = mkOption { type = types.bool; default = false; @@ -206,20 +220,20 @@ in { dataDir = mkOption { type = types.path; - default = "/var/lib/mediatomb"; + default = "/var/lib/${name}"; description = '' - The directory where mediatomb stores its state, data, etc. + The directory where ${cfg.serverName} stores its state, data, etc. ''; }; user = mkOption { default = "mediatomb"; - description = "User account under which mediatomb runs."; + description = "User account under which ${name} runs."; }; group = mkOption { default = "mediatomb"; - description = "Group account under which mediatomb runs."; + description = "Group account under which ${name} runs."; }; port = mkOption { @@ -247,7 +261,10 @@ in { type = types.bool; default = false; description = '' - Allow mediatomb to create and use its own config file inside ${cfg.dataDir}. + Allow ${name} to create and use its own config file inside ${cfg.dataDir}. + Deactivated by default, the service then runs with the configuration generated from this module. + Otherwise, when enabled, no service configuration is generated. Gerbera/Mediatomb then starts using + ${cfg.dataDir}/config.xml. It's up to the user to make a correct configuration file. ''; }; }; @@ -257,12 +274,11 @@ in { ###### implementation config = mkIf cfg.enable { - systemd.services.mediatomb = { - description = "MediaTomb media Server"; + systemd.services."${name}"= { + description = "${cfg.serverName} 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.ExecStart = "${pkg}/bin/${name} -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}"; }; @@ -276,11 +292,11 @@ in { group = cfg.group; home = "${cfg.dataDir}"; createHome = true; - description = "Mediatomb DLNA Server User"; + description = "${name} DLNA Server User"; }; }; - networking.firewall = { + networking.firewall.interfaces."${cfg.interface}" = { allowedUDPPorts = [ 1900 cfg.port ]; allowedTCPPorts = [ cfg.port ]; };