From dda2f6415fc2b01bf3ee705e59778394c6edd0f9 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 26 Oct 2019 10:56:17 +0200 Subject: [PATCH 1/4] nixos/magnetico: fixes --- nixos/modules/services/torrent/magnetico.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/torrent/magnetico.nix b/nixos/modules/services/torrent/magnetico.nix index a7acdb78b316..860c9c3d08ed 100644 --- a/nixos/modules/services/torrent/magnetico.nix +++ b/nixos/modules/services/torrent/magnetico.nix @@ -35,6 +35,7 @@ let (if (cfg.web.credentialsFile != null || cfg.web.credentials != { }) then "--credentials=${toString credFile}" else "--no-auth") + "--addr=${address}:${toString port}" ] ++ extraOptions); in { @@ -202,7 +203,7 @@ in { assertions = [ { - assertion = cfg.web.credentialsFile != null || cfg.web.credentials != { }; + assertion = cfg.web.credentialsFile == null || cfg.web.credentials == { }; message = '' The options services.magnetico.web.credentialsFile and services.magnetico.web.credentials are mutually exclusives. From 6823199dbec1c14c69c65d063775599c62e77779 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sat, 26 Oct 2019 11:18:59 +0200 Subject: [PATCH 2/4] nixos/tests/magnetico: check for different web port --- nixos/tests/magnetico.nix | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/nixos/tests/magnetico.nix b/nixos/tests/magnetico.nix index bc7aef653ee5..2b1af8328da7 100644 --- a/nixos/tests/magnetico.nix +++ b/nixos/tests/magnetico.nix @@ -1,4 +1,9 @@ -import ./make-test.nix ({ pkgs, ...} : { +import ./make-test.nix ({ pkgs, ...} : + +let + port = 8081; +in +{ name = "magnetico"; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ rnhmjoj ]; @@ -12,6 +17,7 @@ import ./make-test.nix ({ pkgs, ...} : { services.magnetico = { enable = true; crawler.port = 9000; + web.port = port; web.credentials.user = "$2y$12$P88ZF6soFthiiAeXnz64aOWDsY3Dw7Yw8fZ6GtiqFNjknD70zDmNe"; }; }; @@ -21,8 +27,10 @@ import ./make-test.nix ({ pkgs, ...} : { startAll; $machine->waitForUnit("magneticod"); $machine->waitForUnit("magneticow"); - $machine->succeed("${pkgs.curl}/bin/curl -u user:password http://localhost:8080"); - $machine->succeed("${pkgs.curl}/bin/curl -u user:wrongpwd http://localhost:8080") =~ "Unauthorised." or die; + $machine->succeed("${pkgs.curl}/bin/curl ". + "-u user:password http://localhost:${toString port}"); + $machine->succeed("${pkgs.curl}/bin/curl ". + "-u user:wrongpwd http://localhost:${toString port}") =~ "Unauthorised." or die; $machine->shutdown(); ''; }) From f6a8eb2d00cd71e630484337cae29c37694037a6 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Wed, 13 Nov 2019 19:17:32 +0100 Subject: [PATCH 3/4] nixos/tests/magnetico: port to python --- nixos/tests/all-tests.nix | 1 + nixos/tests/magnetico.nix | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index a92a3ccd0d18..78bf7ea962aa 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -148,6 +148,7 @@ in loki = handleTest ./loki.nix {}; #logstash = handleTest ./logstash.nix {}; lorri = handleTest ./lorri/default.nix {}; + magnetico = handleTest ./magnetico.nix {}; mailcatcher = handleTest ./mailcatcher.nix {}; mathics = handleTest ./mathics.nix {}; matomo = handleTest ./matomo.nix {}; diff --git a/nixos/tests/magnetico.nix b/nixos/tests/magnetico.nix index 2b1af8328da7..6770d32358e8 100644 --- a/nixos/tests/magnetico.nix +++ b/nixos/tests/magnetico.nix @@ -1,4 +1,4 @@ -import ./make-test.nix ({ pkgs, ...} : +import ./make-test-python.nix ({ pkgs, ...} : let port = 8081; @@ -24,13 +24,17 @@ in testScript = '' - startAll; - $machine->waitForUnit("magneticod"); - $machine->waitForUnit("magneticow"); - $machine->succeed("${pkgs.curl}/bin/curl ". - "-u user:password http://localhost:${toString port}"); - $machine->succeed("${pkgs.curl}/bin/curl ". - "-u user:wrongpwd http://localhost:${toString port}") =~ "Unauthorised." or die; - $machine->shutdown(); + start_all() + machine.wait_for_unit("magneticod") + machine.wait_for_unit("magneticow") + machine.succeed( + "${pkgs.curl}/bin/curl " + + "-u user:password http://localhost:${toString port}" + ) + assert "Unauthorised." in machine.succeed( + "${pkgs.curl}/bin/curl " + + "-u user:wrongpwd http://localhost:${toString port}" + ) + machine.shutdown() ''; }) From 84648672421cb6a360cb226356c8209670fc8c27 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Wed, 13 Nov 2019 22:50:06 +0100 Subject: [PATCH 4/4] nixos/magnetico: order after network.target --- nixos/modules/services/torrent/magnetico.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/torrent/magnetico.nix b/nixos/modules/services/torrent/magnetico.nix index 860c9c3d08ed..719827713ff9 100644 --- a/nixos/modules/services/torrent/magnetico.nix +++ b/nixos/modules/services/torrent/magnetico.nix @@ -178,7 +178,7 @@ in { systemd.services.magneticod = { description = "Magnetico DHT crawler"; wantedBy = [ "multi-user.target" ]; - after = [ "network-online.target" ]; + after = [ "network.target" ]; serviceConfig = { User = "magnetico"; @@ -190,7 +190,7 @@ in { systemd.services.magneticow = { description = "Magnetico web interface"; wantedBy = [ "multi-user.target" ]; - after = [ "network-online.target" "magneticod.service"]; + after = [ "network.target" "magneticod.service"]; serviceConfig = { User = "magnetico";