ma airdcpp module: add hubs

This commit is contained in:
makefu 2018-09-24 11:16:16 +02:00
parent 1996b59748
commit 3285aefea4
No known key found for this signature in database
GPG Key ID: 36F7711F3FC0F225

View File

@ -37,6 +37,51 @@ let
type = str; type = str;
default = "/var/lib/airdcpp"; default = "/var/lib/airdcpp";
}; };
hubs = mkOption {
type = attrsOf (submodule ( { config, ... }: {
options = {
Nick = mkOption {
description = ''
Nick Name for hub
'';
type = str;
default = cfg.Nick;
};
Password = mkOption {
description = ''
Password to be used
WARNING: will be stored in plain text in /nix/store
'';
type = str;
default = "";
};
Server = mkOption {
description = ''
URL to the hub (must be provided)
'';
type = str;
};
AutoConnect = mkOption {
description = ''
automatically connect to the hub
'';
type = bool;
default = false;
};
};
}));
description = "hubs which should be configured via Favorites.xml,
Options are only used if no initial Favorites.xml file is provided and none exists";
default = {};
};
initialFavoritesConfigFile = mkOption {
description = ''
path inital Favorites.xml configuration if none exists
'';
type = nullOr path;
default = null;
};
dcpp = { dcpp = {
Nick = mkOption { Nick = mkOption {
description = '' description = ''
@ -133,11 +178,6 @@ let
genUsers = users: concatMapStringsSep "\n" (user: genUsers = users: concatMapStringsSep "\n" (user:
''<WebUser Username="${user.name}" Password="${user.password}" LastLogin="0" Permissions="${user.permissions}"/>'' ) ''<WebUser Username="${user.name}" Password="${user.password}" LastLogin="0" Permissions="${user.permissions}"/>'' )
(mapAttrsToList (name: val: val // { inherit name; }) users); (mapAttrsToList (name: val: val // { inherit name; }) users);
genShares = shares: concatMapStringsSep "\n" (share:
''<Directory Virtual="stockholm" Incoming="${
if share.incoming then "1" else "0"
}" LastRefreshTime="0">${share.path}</Directory>'' )
(mapAttrsToList (name: val: val // { inherit name; }) shares);
webConfigFile = if (cfg.web.initialConfigFile == null) then builtins.trace "warning: airdcpp passwords are stored in plain text" pkgs.writeText "initial-config" '' webConfigFile = if (cfg.web.initialConfigFile == null) then builtins.trace "warning: airdcpp passwords are stored in plain text" pkgs.writeText "initial-config" ''
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<WebServer> <WebServer>
@ -149,16 +189,33 @@ let
</WebUsers> </WebUsers>
</WebServer> </WebServer>
'' else cfg.web.initialConfigFile; '' else cfg.web.initialConfigFile;
genHubs = hubs: concatMapStringsSep "\n" (hub:
''<Hub Name="${hub.name}" Connect="${
if hub.AutoConnect then "1" else "0"
}" Description="" Password="${hub.Password}" Server="${hub.Server}" ChatUserSplit="0" UserListState="1" HubFrameOrder="" HubFrameWidths="" HubFrameVisible="" Group="" Bottom="0" Top="0" Right="0" Left="0" Nick="${hub.Nick}"/>'' )
(mapAttrsToList (name: val: val // { inherit name; }) cfg.hubs);
favoritesConfigFile = if (cfg.initialFavoritesConfigFile == null) then
builtins.trace "warning: airdcpp hub passwords are stored in plain text" pkgs.writeText "initial-config" ''
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Favorites>
<Hubs>
${genHubs cfg.hubs}
</Hubs>
</Favorites>
'' else cfg.initialFavoritesConfigFile;
genShares = shares: concatMapStringsSep "\n" (share:
''<Directory Virtual="stockholm" Incoming="${
if share.incoming then "1" else "0"
}" LastRefreshTime="0">${share.path}</Directory>'' )
(mapAttrsToList (name: val: val // { inherit name; }) shares);
dcppConfigFile = if (cfg.dcpp.initialConfigFile == null) then pkgs.writeText "initial-config" '' dcppConfigFile = if (cfg.dcpp.initialConfigFile == null) then pkgs.writeText "initial-config" ''
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<DCPlusPlus> <DCPlusPlus>
<Settings> <Settings>
<Nick type="string">${cfg.dcpp.Nick}</Nick> <Nick type="string">${cfg.dcpp.Nick}</Nick>
<ConfigVersion type="string">${cfg.package.version}</ConfigVersion>
<InPort type="int">${toString cfg.dcpp.InPort}</InPort> <InPort type="int">${toString cfg.dcpp.InPort}</InPort>
<UDPPort type="int">${toString cfg.dcpp.UDPPort}</UDPPort> <UDPPort type="int">${toString cfg.dcpp.UDPPort}</UDPPort>
<TLSPort type="int">${toString cfg.dcpp.TLSPort}</TLSPort> <TLSPort type="int">${toString cfg.dcpp.TLSPort}</TLSPort>
<ConfigBuildNumber type="int">0</ConfigBuildNumber>
<AutoDetectIncomingConnection type="int">0</AutoDetectIncomingConnection> <AutoDetectIncomingConnection type="int">0</AutoDetectIncomingConnection>
<NoIpOverride type="int">1</NoIpOverride> <NoIpOverride type="int">1</NoIpOverride>
<WizardRunNew type="int">0</WizardRunNew> <WizardRunNew type="int">0</WizardRunNew>
@ -187,6 +244,8 @@ let
test -e $d || install -m700 -o${cfg.user} ${webConfigFile} $d test -e $d || install -m700 -o${cfg.user} ${webConfigFile} $d
d=${cfg.stateDir}/DCPlusPlus.xml d=${cfg.stateDir}/DCPlusPlus.xml
test -e $d || install -m700 -o${cfg.user} ${dcppConfigFile} $d test -e $d || install -m700 -o${cfg.user} ${dcppConfigFile} $d
d=${cfg.stateDir}/Favorites.xml
test -e $d || install -m700 -o${cfg.user} ${favoritesConfigFile} $d
''; '';
PermissionsStartOnly = true; PermissionsStartOnly = true;
ExecStart = "${cfg.package}/bin/airdcppd -c=${cfg.stateDir} -p=${cfg.stateDir}/airdcpp.pid"; ExecStart = "${cfg.package}/bin/airdcppd -c=${cfg.stateDir} -p=${cfg.stateDir}/airdcpp.pid";