From d8d512ab31a4492d99ce66dd1c2c4b9f380820a5 Mon Sep 17 00:00:00 2001 From: catvayor Date: Thu, 12 Sep 2024 19:46:13 +0200 Subject: [PATCH] feat(ci): netdevice on vms --- .forgejo/ci-files/border.nix | 16 ++++++++++++- .forgejo/ci-files/client.nix | 5 +++- .forgejo/ci-files/default.nix | 45 +++++++++++++++++++++++++++-------- .forgejo/ci-files/vm-base.nix | 8 +++++++ 4 files changed, 62 insertions(+), 12 deletions(-) diff --git a/.forgejo/ci-files/border.nix b/.forgejo/ci-files/border.nix index 5521c96..86bc457 100644 --- a/.forgejo/ci-files/border.nix +++ b/.forgejo/ci-files/border.nix @@ -1,4 +1,18 @@ { lib, pkgs, ... }: { - networking.hostName = "border-vm"; + networking = { + hostName = "border-vm"; + useDHCP = false; + }; + + systemd.network = { + enable = true; + networks."10-ens3" = { + name = "ens3"; + networkConfig = { + DHCPServer = "yes"; + }; + address = [ "192.168.242.1/24" ]; + }; + }; } diff --git a/.forgejo/ci-files/client.nix b/.forgejo/ci-files/client.nix index a17faa6..7afe61e 100644 --- a/.forgejo/ci-files/client.nix +++ b/.forgejo/ci-files/client.nix @@ -1,4 +1,7 @@ { lib, pkgs, ... }: { - networking.hostName = "client-vm"; + networking = { + hostName = "client-vm"; + useDHCP = true; + }; } diff --git a/.forgejo/ci-files/default.nix b/.forgejo/ci-files/default.nix index 04cbc6b..0507703 100644 --- a/.forgejo/ci-files/default.nix +++ b/.forgejo/ci-files/default.nix @@ -3,13 +3,21 @@ lib ? pkgs.lib, }: let - base-cmd = vm: '' - ${pkgs.qemu}/bin/qemu-system-x86_64 -m 4G \ - -kernel ${vm.kernel}/bzImage \ - -initrd ${vm.ramdisk}/initrd \ - -append "init=${vm.toplevel}/init loglevel=4 console=ttyS0" \ - -display none -serial mon:stdio - ''; + base-cmd = + { + apnet-mac, + apnet-port, + vm, + }: + '' + ${pkgs.qemu}/bin/qemu-system-x86_64 -m 4G \ + -kernel ${vm.kernel}/bzImage \ + -initrd ${vm.ramdisk}/initrd \ + -append "init=${vm.toplevel}/init loglevel=4 console=ttyS0" \ + -display none -serial mon:stdio \ + -netdev socket,mcast=230.0.0.1:${toString apnet-port},localaddr=127.0.0.1,id=apnet \ + -device virtio-net,disable-legacy=on,disable-modern=off,netdev=apnet,mac=${apnet-mac} + ''; border-vm = (import (pkgs.path + "/nixos/lib/eval-config.nix") { @@ -30,11 +38,28 @@ let }).config.system.build; border-launch = pkgs.writeShellScript "lauch-border" '' - ${base-cmd border-vm} + ${base-cmd { + vm = border-vm; + apnet-port = 1234; + apnet-mac = "ba:ad:3d:ea:21:02"; + }} ''; client-launch = pkgs.writeShellScript "lauch-client" '' - ${base-cmd client-vm} + ${base-cmd { + vm = client-vm; + apnet-port = 1235; + apnet-mac = "ba:ad:3d:ea:21:01"; + }} ''; in -{ } +pkgs.linkFarm "vms" [ + { + name = "border"; + path = border-launch; + } + { + name = "client"; + path = client-launch; + } +] diff --git a/.forgejo/ci-files/vm-base.nix b/.forgejo/ci-files/vm-base.nix index 9886c1f..52130fb 100644 --- a/.forgejo/ci-files/vm-base.nix +++ b/.forgejo/ci-files/vm-base.nix @@ -2,6 +2,7 @@ config, lib, pkgs, + modulesPath, ... }: let @@ -13,6 +14,13 @@ let }; in { + imports = [ (modulesPath + "/profiles/qemu-guest.nix") ]; + environment.systemPackages = with pkgs; [ tcpdump ]; + networking = { + useNetworkd = true; + firewall.enable = false; + }; + system.build.ramdisk = pkgs.makeInitrdNG { inherit (config.boot.initrd) compressor; prepend = [ "${config.system.build.initialRamdisk}/initrd" ];