nixosTests.bittorrent: Format

This commit is contained in:
Jacek Galowicz 2024-09-12 16:27:26 +02:00
parent 6618ec06cc
commit 60ed2a00ed

View File

@ -6,7 +6,8 @@
# which only works if the first client successfully uses the UPnP-IGD
# protocol to poke a hole in the NAT.
import ./make-test-python.nix ({ pkgs, ... }:
import ./make-test-python.nix (
{ pkgs, ... }:
let
@ -20,7 +21,9 @@ let
externalTrackerAddress = "80.100.100.3";
download-dir = "/var/lib/transmission/Downloads";
transmissionConfig = { pkgs, ... }: {
transmissionConfig =
{ pkgs, ... }:
{
environment.systemPackages = [ pkgs.transmission_3 ];
services.transmission = {
enable = true;
@ -36,17 +39,26 @@ in
{
name = "bittorrent";
meta = with pkgs.lib.maintainers; {
maintainers = [ domenkozar rob bobvanderlinden ];
maintainers = [
domenkozar
rob
bobvanderlinden
];
};
nodes = {
tracker = { pkgs, ... }: {
tracker =
{ pkgs, ... }:
{
imports = [ transmissionConfig ];
virtualisation.vlans = [ 1 ];
networking.firewall.enable = false;
networking.interfaces.eth1.ipv4.addresses = [
{ address = externalTrackerAddress; prefixLength = 24; }
{
address = externalTrackerAddress;
prefixLength = 24;
}
];
# We need Apache on the tracker to serve the torrents.
@ -62,8 +74,13 @@ in
services.opentracker.enable = true;
};
router = { pkgs, nodes, ... }: {
virtualisation.vlans = [ 1 2 ];
router =
{ pkgs, nodes, ... }:
{
virtualisation.vlans = [
1
2
];
networking.nat.enable = true;
networking.nat.internalInterfaces = [ "eth2" ];
networking.nat.externalInterface = "eth1";
@ -71,10 +88,16 @@ in
networking.firewall.trustedInterfaces = [ "eth2" ];
networking.interfaces.eth0.ipv4.addresses = [ ];
networking.interfaces.eth1.ipv4.addresses = [
{ address = externalRouterAddress; prefixLength = 24; }
{
address = externalRouterAddress;
prefixLength = 24;
}
];
networking.interfaces.eth2.ipv4.addresses = [
{ address = internalRouterAddress; prefixLength = 24; }
{
address = internalRouterAddress;
prefixLength = 24;
}
];
services.miniupnpd = {
enable = true;
@ -86,32 +109,44 @@ in
};
};
client1 = { pkgs, nodes, ... }: {
client1 =
{ pkgs, nodes, ... }:
{
imports = [ transmissionConfig ];
environment.systemPackages = [ pkgs.miniupnpc ];
virtualisation.vlans = [ 2 ];
networking.interfaces.eth0.ipv4.addresses = [ ];
networking.interfaces.eth1.ipv4.addresses = [
{ address = internalClient1Address; prefixLength = 24; }
{
address = internalClient1Address;
prefixLength = 24;
}
];
networking.defaultGateway = internalRouterAddress;
networking.firewall.enable = false;
};
client2 = { pkgs, ... }: {
client2 =
{ pkgs, ... }:
{
imports = [ transmissionConfig ];
virtualisation.vlans = [ 1 ];
networking.interfaces.eth0.ipv4.addresses = [ ];
networking.interfaces.eth1.ipv4.addresses = [
{ address = externalClient2Address; prefixLength = 24; }
{
address = externalClient2Address;
prefixLength = 24;
}
];
networking.firewall.enable = false;
};
};
testScript = { nodes, ... }: ''
testScript =
{ nodes, ... }:
''
start_all()
# Wait for network and miniupnpd.
@ -165,4 +200,5 @@ in
"cmp ${download-dir}/test.tar.bz2 ${file}"
)
'';
})
}
)