mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
nixos/services.mediatomb: remove with lib;
This commit is contained in:
parent
36eaab4720
commit
1fa5e5eb2c
1 changed files with 54 additions and 57 deletions
|
@ -1,7 +1,4 @@
|
||||||
{ config, lib, options, pkgs, ... }:
|
{ config, lib, options, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
gid = config.ids.gids.mediatomb;
|
gid = config.ids.gids.mediatomb;
|
||||||
|
@ -13,19 +10,19 @@ let
|
||||||
# configuration on media directory
|
# configuration on media directory
|
||||||
mediaDirectory = {
|
mediaDirectory = {
|
||||||
options = {
|
options = {
|
||||||
path = mkOption {
|
path = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
description = ''
|
description = ''
|
||||||
Absolute directory path to the media directory to index.
|
Absolute directory path to the media directory to index.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
recursive = mkOption {
|
recursive = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Whether the indexation must take place recursively or not.";
|
description = "Whether the indexation must take place recursively or not.";
|
||||||
};
|
};
|
||||||
hidden-files = mkOption {
|
hidden-files = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = "Whether to index the hidden files or not.";
|
description = "Whether to index the hidden files or not.";
|
||||||
};
|
};
|
||||||
|
@ -66,7 +63,7 @@ let
|
||||||
</transcoding>
|
</transcoding>
|
||||||
'';
|
'';
|
||||||
|
|
||||||
configText = optionalString (! cfg.customCfg) ''
|
configText = lib.optionalString (! cfg.customCfg) ''
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<config version="2" xmlns="http://mediatomb.cc/config/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mediatomb.cc/config/2 http://mediatomb.cc/config/2.xsd">
|
<config version="2" xmlns="http://mediatomb.cc/config/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mediatomb.cc/config/2 http://mediatomb.cc/config/2.xsd">
|
||||||
<server>
|
<server>
|
||||||
|
@ -87,7 +84,7 @@ let
|
||||||
</sqlite3>
|
</sqlite3>
|
||||||
</storage>
|
</storage>
|
||||||
<protocolInfo extend="${optionYesNo cfg.ps3Support}"/>
|
<protocolInfo extend="${optionYesNo cfg.ps3Support}"/>
|
||||||
${optionalString cfg.dsmSupport ''
|
${lib.optionalString cfg.dsmSupport ''
|
||||||
<custom-http-headers>
|
<custom-http-headers>
|
||||||
<add header="X-User-Agent: redsonic"/>
|
<add header="X-User-Agent: redsonic"/>
|
||||||
</custom-http-headers>
|
</custom-http-headers>
|
||||||
|
@ -95,7 +92,7 @@ let
|
||||||
<manufacturerURL>redsonic.com</manufacturerURL>
|
<manufacturerURL>redsonic.com</manufacturerURL>
|
||||||
<modelNumber>105</modelNumber>
|
<modelNumber>105</modelNumber>
|
||||||
''}
|
''}
|
||||||
${optionalString cfg.tg100Support ''
|
${lib.optionalString cfg.tg100Support ''
|
||||||
<upnp-string-limit>101</upnp-string-limit>
|
<upnp-string-limit>101</upnp-string-limit>
|
||||||
''}
|
''}
|
||||||
<extended-runtime-options>
|
<extended-runtime-options>
|
||||||
|
@ -109,7 +106,7 @@ let
|
||||||
</server>
|
</server>
|
||||||
<import hidden-files="no">
|
<import hidden-files="no">
|
||||||
<autoscan use-inotify="auto">
|
<autoscan use-inotify="auto">
|
||||||
${concatMapStrings toMediaDirectory cfg.mediaDirectories}
|
${lib.concatMapStrings toMediaDirectory cfg.mediaDirectories}
|
||||||
</autoscan>
|
</autoscan>
|
||||||
<scripting script-charset="UTF-8">
|
<scripting script-charset="UTF-8">
|
||||||
<common-script>${pkg}/share/${name}/js/common.js</common-script>
|
<common-script>${pkg}/share/${name}/js/common.js</common-script>
|
||||||
|
@ -139,10 +136,10 @@ let
|
||||||
<map from="flv" to="video/x-flv"/>
|
<map from="flv" to="video/x-flv"/>
|
||||||
<map from="mkv" to="video/x-matroska"/>
|
<map from="mkv" to="video/x-matroska"/>
|
||||||
<map from="mka" to="audio/x-matroska"/>
|
<map from="mka" to="audio/x-matroska"/>
|
||||||
${optionalString cfg.ps3Support ''
|
${lib.optionalString cfg.ps3Support ''
|
||||||
<map from="avi" to="video/divx"/>
|
<map from="avi" to="video/divx"/>
|
||||||
''}
|
''}
|
||||||
${optionalString cfg.dsmSupport ''
|
${lib.optionalString cfg.dsmSupport ''
|
||||||
<map from="avi" to="video/avi"/>
|
<map from="avi" to="video/avi"/>
|
||||||
''}
|
''}
|
||||||
</extension-mimetype>
|
</extension-mimetype>
|
||||||
|
@ -199,26 +196,26 @@ in {
|
||||||
|
|
||||||
services.mediatomb = {
|
services.mediatomb = {
|
||||||
|
|
||||||
enable = mkOption {
|
enable = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Whether to enable the Gerbera/Mediatomb DLNA server.
|
Whether to enable the Gerbera/Mediatomb DLNA server.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
serverName = mkOption {
|
serverName = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "Gerbera (Mediatomb)";
|
default = "Gerbera (Mediatomb)";
|
||||||
description = ''
|
description = ''
|
||||||
How to identify the server on the network.
|
How to identify the server on the network.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
package = mkPackageOption pkgs "gerbera" { };
|
package = lib.mkPackageOption pkgs "gerbera" { };
|
||||||
|
|
||||||
ps3Support = mkOption {
|
ps3Support = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Whether to enable ps3 specific tweaks.
|
Whether to enable ps3 specific tweaks.
|
||||||
|
@ -226,8 +223,8 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
dsmSupport = mkOption {
|
dsmSupport = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Whether to enable D-Link DSM 320 specific tweaks.
|
Whether to enable D-Link DSM 320 specific tweaks.
|
||||||
|
@ -235,69 +232,69 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
tg100Support = mkOption {
|
tg100Support = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Whether to enable Telegent TG100 specific tweaks.
|
Whether to enable Telegent TG100 specific tweaks.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
transcoding = mkOption {
|
transcoding = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Whether to enable transcoding.
|
Whether to enable transcoding.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
dataDir = mkOption {
|
dataDir = lib.mkOption {
|
||||||
type = types.path;
|
type = lib.types.path;
|
||||||
default = "/var/lib/${name}";
|
default = "/var/lib/${name}";
|
||||||
defaultText = literalExpression ''"/var/lib/''${config.${opt.package}.pname}"'';
|
defaultText = lib.literalExpression ''"/var/lib/''${config.${opt.package}.pname}"'';
|
||||||
description = ''
|
description = ''
|
||||||
The directory where Gerbera/Mediatomb stores its state, data, etc.
|
The directory where Gerbera/Mediatomb stores its state, data, etc.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
pcDirectoryHide = mkOption {
|
pcDirectoryHide = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = ''
|
description = ''
|
||||||
Whether to list the top-level directory or not (from upnp client standpoint).
|
Whether to list the top-level directory or not (from upnp client standpoint).
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
user = mkOption {
|
user = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "mediatomb";
|
default = "mediatomb";
|
||||||
description = "User account under which the service runs.";
|
description = "User account under which the service runs.";
|
||||||
};
|
};
|
||||||
|
|
||||||
group = mkOption {
|
group = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "mediatomb";
|
default = "mediatomb";
|
||||||
description = "Group account under which the service runs.";
|
description = "Group account under which the service runs.";
|
||||||
};
|
};
|
||||||
|
|
||||||
port = mkOption {
|
port = lib.mkOption {
|
||||||
type = types.port;
|
type = lib.types.port;
|
||||||
default = 49152;
|
default = 49152;
|
||||||
description = ''
|
description = ''
|
||||||
The network port to listen on.
|
The network port to listen on.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
interface = mkOption {
|
interface = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
A specific interface to bind to.
|
A specific interface to bind to.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
openFirewall = mkOption {
|
openFirewall = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
If false (the default), this is up to the user to declare the firewall rules.
|
If false (the default), this is up to the user to declare the firewall rules.
|
||||||
|
@ -310,16 +307,16 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
uuid = mkOption {
|
uuid = lib.mkOption {
|
||||||
type = types.str;
|
type = lib.types.str;
|
||||||
default = "fdfc8a4e-a3ad-4c1d-b43d-a2eedb03a687";
|
default = "fdfc8a4e-a3ad-4c1d-b43d-a2eedb03a687";
|
||||||
description = ''
|
description = ''
|
||||||
A unique (on your network) to identify the server by.
|
A unique (on your network) to identify the server by.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
mediaDirectories = mkOption {
|
mediaDirectories = lib.mkOption {
|
||||||
type = with types; listOf (submodule mediaDirectory);
|
type = with lib.types; listOf (submodule mediaDirectory);
|
||||||
default = [];
|
default = [];
|
||||||
description = ''
|
description = ''
|
||||||
Declare media directories to index.
|
Declare media directories to index.
|
||||||
|
@ -330,8 +327,8 @@ in {
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
customCfg = mkOption {
|
customCfg = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Allow the service to create and use its own config file inside the `dataDir` as
|
Allow the service to create and use its own config file inside the `dataDir` as
|
||||||
|
@ -350,9 +347,9 @@ in {
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = let binaryCommand = "${pkg}/bin/${name}";
|
config = let binaryCommand = "${pkg}/bin/${name}";
|
||||||
interfaceFlag = optionalString ( cfg.interface != "") "--interface ${cfg.interface}";
|
interfaceFlag = lib.optionalString ( cfg.interface != "") "--interface ${cfg.interface}";
|
||||||
configFlag = optionalString (! cfg.customCfg) "--config ${pkgs.writeText "config.xml" configText}";
|
configFlag = lib.optionalString (! cfg.customCfg) "--config ${pkgs.writeText "config.xml" configText}";
|
||||||
in mkIf cfg.enable {
|
in lib.mkIf cfg.enable {
|
||||||
systemd.services.mediatomb = {
|
systemd.services.mediatomb = {
|
||||||
description = "${cfg.serverName} media Server";
|
description = "${cfg.serverName} media Server";
|
||||||
# Gerbera might fail if the network interface is not available on startup
|
# Gerbera might fail if the network interface is not available on startup
|
||||||
|
@ -365,11 +362,11 @@ in {
|
||||||
serviceConfig.Group = cfg.group;
|
serviceConfig.Group = cfg.group;
|
||||||
};
|
};
|
||||||
|
|
||||||
users.groups = optionalAttrs (cfg.group == "mediatomb") {
|
users.groups = lib.optionalAttrs (cfg.group == "mediatomb") {
|
||||||
mediatomb.gid = gid;
|
mediatomb.gid = gid;
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users = optionalAttrs (cfg.user == "mediatomb") {
|
users.users = lib.optionalAttrs (cfg.user == "mediatomb") {
|
||||||
mediatomb = {
|
mediatomb = {
|
||||||
isSystemUser = true;
|
isSystemUser = true;
|
||||||
group = cfg.group;
|
group = cfg.group;
|
||||||
|
@ -380,11 +377,11 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
# Open firewall only if users enable it
|
# Open firewall only if users enable it
|
||||||
networking.firewall = mkMerge [
|
networking.firewall = lib.mkMerge [
|
||||||
(mkIf (cfg.openFirewall && cfg.interface != "") {
|
(lib.mkIf (cfg.openFirewall && cfg.interface != "") {
|
||||||
interfaces."${cfg.interface}" = defaultFirewallRules;
|
interfaces."${cfg.interface}" = defaultFirewallRules;
|
||||||
})
|
})
|
||||||
(mkIf (cfg.openFirewall && cfg.interface == "") defaultFirewallRules)
|
(lib.mkIf (cfg.openFirewall && cfg.interface == "") defaultFirewallRules)
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue