diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index b03107610fe4..acb4af7a933d 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -212,6 +212,7 @@ uptimed = 184; zope2 = 185; ripple-data-api = 186; + mediatomb = 187; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! @@ -401,6 +402,7 @@ #uptimed = 184; # unused #zope2 = 185; # unused #ripple-data-api = 186; #unused + mediatomb = 187; # When adding a gid, make sure it doesn't match an existing # uid. Users and groups with the same name should have equal diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index cca1c1a73d39..738faa79e29b 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -191,6 +191,7 @@ ./services/misc/gitlab.nix ./services/misc/gitolite.nix ./services/misc/gpsd.nix + ./services/misc/mediatomb.nix ./services/misc/mesos-master.nix ./services/misc/mesos-slave.nix ./services/misc/nix-daemon.nix diff --git a/nixos/modules/services/misc/mediatomb.nix b/nixos/modules/services/misc/mediatomb.nix new file mode 100644 index 000000000000..23227548039c --- /dev/null +++ b/nixos/modules/services/misc/mediatomb.nix @@ -0,0 +1,282 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + uid = config.ids.uids.mediatomb; + 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 + + + + + + + /nix/store/cngbzn39vidd6jm4wgzxfafqll74ybfa-mediatomb-0.12.1/share/mediatomb/js/common.js + /nix/store/cngbzn39vidd6jm4wgzxfafqll74ybfa-mediatomb-0.12.1/share/mediatomb/js/playlists.js + + /nix/store/cngbzn39vidd6jm4wgzxfafqll74ybfa-mediatomb-0.12.1/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.string; + 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. + ''; + }; + + 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 = [ "local-fs.target" "network.target" ]; + wantedBy = [ "multi-user.target" ]; + path = [ pkgs.mediatomb ]; + serviceConfig.ExecStart = "${pkgs.mediatomb}/bin/mediatomb -p ${toString cfg.port} ${if cfg.customCfg then "" else "-c ${mtConf}"} -m ${cfg.dataDir}"; + serviceConfig.User = "${cfg.user}"; + }; + + users.extraGroups = optionalAttrs (cfg.group == "mediatomb") (singleton { + name = "mediatomb"; + gid = gid; + }); + + users.extraUsers = optionalAttrs (cfg.user == "mediatomb") (singleton { + name = "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 ]; + }; + }; +}