{ lib, config, ... }: let maxVMs = 3; in { options = { abra.testing.enable = lib.mkOption { type = lib.types.bool; default = false; description = "Enable the abra integration testing framework"; }; abra.testing.externalInterface = lib.mkOption { type = lib.types.str; default = null; description = "Change this to the interface with upstream Internet access"; }; }; config = lib.mkIf config.abra.testing.enable { networking.useNetworkd = true; systemd.network.wait-online.enable = false; systemd.network.networks = builtins.listToAttrs ( map (index: { name = "30-vm${toString index}"; value = { matchConfig.Name = "vm${toString index}"; # Host's addresses address = [ "10.0.0.0/32" "fec0::/128" ]; # Setup routes to the VM routes = [ { Destination = "10.0.0.${toString index}/32"; } { Destination = "fec0::${lib.toHexString index}/128"; } ]; # Enable routing networkConfig = { IPv4Forwarding = true; IPv6Forwarding = true; }; }; }) (lib.genList (i: i + 1) maxVMs) ); networking.nat = { enable = true; internalIPs = [ "10.0.0.0/24" ]; externalInterface = config.abra.testing.externalInterface; }; }; }