nixos/deluge: support 2.x

This commit is contained in:
Milan Pässler 2020-03-19 03:19:26 +01:00 committed by Milan
parent fee776aae4
commit 16a4332d60
3 changed files with 109 additions and 41 deletions

View File

@ -203,6 +203,15 @@ environment.systemPackages = [
<link xlink:href="https://github.com/gollum/gollum/wiki/5.0-release-notes#migrating-your-wiki">here</link>. <link xlink:href="https://github.com/gollum/gollum/wiki/5.0-release-notes#migrating-your-wiki">here</link>.
</para> </para>
</listitem> </listitem>
<listitem>
<para>
Deluge 2.x was added and is used as default for new NixOS
installations where stateVersion is >= 20.09. If you are upgrading from a previous
NixOS version, you can set <literal>service.deluge.package = pkgs.deluge-2_x</literal>
to upgrade to Deluge 2.x and migrate the state to the new format.
Be aware that backwards state migrations are not supported by Deluge.
</para>
</listitem>
<listitem> <listitem>
<para> <para>
@ -246,7 +255,6 @@ environment.systemPackages = [
# sudo /run/current-system/fine-tune/child-1/bin/switch-to-configuration test # sudo /run/current-system/fine-tune/child-1/bin/switch-to-configuration test
</programlisting> </programlisting>
</para> </para>
</listitem>
</itemizedlist> </itemizedlist>
</section> </section>

View File

@ -5,6 +5,7 @@ with lib;
let let
cfg = config.services.deluge; cfg = config.services.deluge;
cfg_web = config.services.deluge.web; cfg_web = config.services.deluge.web;
isDeluge1 = versionOlder cfg.package.version "2.0.0";
openFilesLimit = 4096; openFilesLimit = 4096;
listenPortsDefault = [ 6881 6889 ]; listenPortsDefault = [ 6881 6889 ];
@ -18,11 +19,11 @@ let
preStart = if cfg.declarative then '' preStart = if cfg.declarative then ''
if [ -e ${declarativeLockFile} ]; then if [ -e ${declarativeLockFile} ]; then
# Was declarative before, no need to back up anything # Was declarative before, no need to back up anything
ln -sf ${configFile} ${configDir}/core.conf ${if isDeluge1 then "ln -sf" else "cp"} ${configFile} ${configDir}/core.conf
ln -sf ${cfg.authFile} ${configDir}/auth ln -sf ${cfg.authFile} ${configDir}/auth
else else
# Declarative for the first time, backup stateful files # Declarative for the first time, backup stateful files
ln -sb --suffix=.stateful ${configFile} ${configDir}/core.conf ${if isDeluge1 then "ln -s" else "cp"} -b --suffix=.stateful ${configFile} ${configDir}/core.conf
ln -sb --suffix=.stateful ${cfg.authFile} ${configDir}/auth ln -sb --suffix=.stateful ${cfg.authFile} ${configDir}/auth
echo "Autogenerated file that signifies that this server configuration is managed declaratively by NixOS" \ echo "Autogenerated file that signifies that this server configuration is managed declaratively by NixOS" \
> ${declarativeLockFile} > ${declarativeLockFile}
@ -144,6 +145,14 @@ in {
This always contains unzip, gnutar, xz, p7zip and bzip2. This always contains unzip, gnutar, xz, p7zip and bzip2.
''; '';
}; };
package = mkOption {
type = types.package;
example = literalExample "pkgs.deluge-1_x";
description = ''
Deluge package to use.
'';
};
}; };
deluge.web = { deluge.web = {
@ -170,6 +179,13 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
services.deluge.package = mkDefault (
if versionAtLeast config.system.stateVersion "20.09" then
pkgs.deluge-2_x
else
pkgs.deluge-1_x
);
# Provide a default set of `extraPackages`. # Provide a default set of `extraPackages`.
services.deluge.extraPackages = with pkgs; [ unzip gnutar xz p7zip bzip2 ]; services.deluge.extraPackages = with pkgs; [ unzip gnutar xz p7zip bzip2 ];
@ -189,10 +205,10 @@ in {
after = [ "network.target" ]; after = [ "network.target" ];
description = "Deluge BitTorrent Daemon"; description = "Deluge BitTorrent Daemon";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
path = [ pkgs.deluge ] ++ cfg.extraPackages; path = [ cfg.package ] ++ cfg.extraPackages;
serviceConfig = { serviceConfig = {
ExecStart = '' ExecStart = ''
${pkgs.deluge}/bin/deluged \ ${cfg.package}/bin/deluged \
--do-not-daemonize \ --do-not-daemonize \
--config ${configDir} --config ${configDir}
''; '';
@ -212,10 +228,11 @@ in {
requires = [ "deluged.service" ]; requires = [ "deluged.service" ];
description = "Deluge BitTorrent WebUI"; description = "Deluge BitTorrent WebUI";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
path = [ pkgs.deluge ]; path = [ cfg.package ];
serviceConfig = { serviceConfig = {
ExecStart = '' ExecStart = ''
${pkgs.deluge}/bin/deluge-web \ ${cfg.package}/bin/deluge-web \
${optionalString (!isDeluge1) "--do-not-daemonize"} \
--config ${configDir} \ --config ${configDir} \
--port ${toString cfg.web.port} --port ${toString cfg.web.port}
''; '';
@ -234,7 +251,7 @@ in {
}) })
]; ];
environment.systemPackages = [ pkgs.deluge ]; environment.systemPackages = [ cfg.package ];
users.users = mkIf (cfg.user == "deluge") { users.users = mkIf (cfg.user == "deluge") {
deluge = { deluge = {

View File

@ -5,9 +5,10 @@ import ./make-test-python.nix ({ pkgs, ...} : {
}; };
nodes = { nodes = {
simple = { simple1 = {
services.deluge = { services.deluge = {
enable = true; enable = true;
package = pkgs.deluge-1_x;
web = { web = {
enable = true; enable = true;
openFirewall = true; openFirewall = true;
@ -15,50 +16,92 @@ import ./make-test-python.nix ({ pkgs, ...} : {
}; };
}; };
declarative = declarative1 = {
{ ... }: services.deluge = {
enable = true;
package = pkgs.deluge-1_x;
openFirewall = true;
declarative = true;
config = {
allow_remote = true;
download_location = "/var/lib/deluge/my-download";
daemon_port = 58846;
listen_ports = [ 6881 6889 ];
};
web = {
enable = true;
port = 3142;
};
authFile = pkgs.writeText "deluge-auth" ''
localclient:a7bef72a890:10
andrew:password:10
user3:anotherpass:5
'';
};
};
{ simple2 = {
services.deluge = { services.deluge = {
enable = true;
package = pkgs.deluge-2_x;
web = {
enable = true; enable = true;
openFirewall = true; openFirewall = true;
declarative = true;
config = {
allow_remote = true;
download_location = "/var/lib/deluge/my-download";
daemon_port = 58846;
listen_ports = [ 6881 6889 ];
};
web = {
enable = true;
port = 3142;
};
authFile = pkgs.writeText "deluge-auth" ''
localclient:a7bef72a890:10
andrew:password:10
user3:anotherpass:5
'';
}; };
environment.systemPackages = [ pkgs.deluge ];
}; };
};
declarative2 = {
services.deluge = {
enable = true;
package = pkgs.deluge-2_x;
openFirewall = true;
declarative = true;
config = {
allow_remote = true;
download_location = "/var/lib/deluge/my-download";
daemon_port = 58846;
listen_ports = [ 6881 6889 ];
};
web = {
enable = true;
port = 3142;
};
authFile = pkgs.writeText "deluge-auth" ''
localclient:a7bef72a890:10
andrew:password:10
user3:anotherpass:5
'';
};
};
}; };
testScript = '' testScript = ''
start_all() start_all()
simple.wait_for_unit("deluged") simple1.wait_for_unit("deluged")
simple.wait_for_unit("delugeweb") simple2.wait_for_unit("deluged")
simple.wait_for_open_port("8112") simple1.wait_for_unit("delugeweb")
declarative.wait_for_unit("network.target") simple2.wait_for_unit("delugeweb")
declarative.wait_until_succeeds("curl --fail http://simple:8112") simple1.wait_for_open_port("8112")
simple2.wait_for_open_port("8112")
declarative1.wait_for_unit("network.target")
declarative2.wait_for_unit("network.target")
declarative1.wait_until_succeeds("curl --fail http://simple1:8112")
declarative2.wait_until_succeeds("curl --fail http://simple2:8112")
declarative.wait_for_unit("deluged") declarative1.wait_for_unit("deluged")
declarative.wait_for_unit("delugeweb") declarative2.wait_for_unit("deluged")
declarative.wait_until_succeeds("curl --fail http://declarative:3142") declarative1.wait_for_unit("delugeweb")
declarative.succeed("deluge-console 'help' | grep -q 'rm - Remove a torrent'") declarative2.wait_for_unit("delugeweb")
declarative.succeed( declarative1.wait_until_succeeds("curl --fail http://declarative1:3142")
"deluge-console 'connect 127.0.0.1:58846 andrew password; help' | grep -q 'rm - Remove a torrent'" declarative2.wait_until_succeeds("curl --fail http://declarative2:3142")
declarative1.succeed(
"deluge-console 'connect 127.0.0.1:58846 andrew password; help' | grep -q 'rm.*Remove a torrent'"
)
declarative2.succeed(
"deluge-console 'connect 127.0.0.1:58846 andrew password; help' | grep -q 'rm.*Remove a torrent'"
) )
''; '';
}) })