support USB ethernet in bordervm

module-based-network
Daniel Barlow 2023-05-09 22:58:56 +01:00
parent 55387b0ee3
commit b70c8ee258
3 changed files with 39 additions and 17 deletions

View File

@ -1,7 +1,7 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
let let
cfg = config.bordervm; cfg = config.bordervm;
inherit (lib) mkOption mdDoc types; inherit (lib) mkOption mkEnableOption mdDoc types optional optionals;
in { in {
options.bordervm = { options.bordervm = {
l2tp = { l2tp = {
@ -22,14 +22,28 @@ in {
}; };
}; };
ethernet = { ethernet = {
pciId = mkOption { pci = {
description = '' enable = mkEnableOption "passthru PCI ethernet";
Host PCI ID (as shown by `lspci`) of the ethernet adaptor id = mkOption {
to be used by the VM. This uses VFIO and requires setup description = ''
on the emulation host before it will work! Host PCI ID (as shown by `lspci`) of the ethernet adaptor
''; to be used by the VM. This uses VFIO and requires setup
type = types.str; on the emulation host before it will work!
example = "04:00.0"; '';
type = types.str;
example = "04:00.0";
};
};
usb = {
enable = mkEnableOption "passthru USB ethernet";
vendor = mkOption {
type = types.str;
example = "0x0bda";
};
product = mkOption {
type = types.str;
example = "0x8153";
};
}; };
}; };
}; };
@ -66,11 +80,16 @@ in {
virtualisation = { virtualisation = {
qemu = { qemu = {
networkingOptions = []; networkingOptions = [];
options = [ options = [] ++
"-device vfio-pci,host=${cfg.ethernet.pciId}" optional cfg.ethernet.pci.enable
"-nographic" "-device vfio-pci,host=${cfg.ethernet.pci.id}" ++
"-serial mon:stdio" optionals cfg.ethernet.usb.enable [
]; "-device usb-ehci,id=ehci"
"-device usb-host,bus=ehci.0,vendorid=${cfg.ethernet.usb.vendor},productid=${cfg.ethernet.usb.product}"
] ++ [
"-nographic"
"-serial mon:stdio"
];
}; };
sharedDirectories = { sharedDirectories = {
liminix = { liminix = {

View File

@ -1,7 +1,8 @@
{...}: {...}:
{ {
bordervm = { bordervm = {
ethernet.pciId = "01:00.0"; # ethernet.pci = { id = "01:00.0"; enable = true; };
ethernet.usb = { vendor = "0x0bda"; product = "0x8153"; enable = true; };
l2tp = { l2tp = {
host = "l2tp.aa.net.uk"; host = "l2tp.aa.net.uk";
}; };

View File

@ -139,11 +139,13 @@ router from the internet so you can borrow the cable/fibre/DSL.
``bordervm`` is included for this purpose. You will need ``bordervm`` is included for this purpose. You will need
* a Linux machine with a spare PCI ethernet card which you can dedicate to Liminix * a Linux machine with a spare (PCI or USB) ethernet device which you can dedicate to Liminix
* an L2TP service such as https://www.aa.net.uk/broadband/l2tp-service/ * an L2TP service such as https://www.aa.net.uk/broadband/l2tp-service/
You need to configure the Ethernet card for VFIO passthru, then You need to "hide" the Ethernet device from the host - for PCI this
means configuring it for VFIO passthru; for USB you need to
unload the module(s) it uses. Then
you can execute :command:`run-border-vm` in a ``buildEnv`` shell, you can execute :command:`run-border-vm` in a ``buildEnv`` shell,
which starts up QEMU using the NixOS configuration in which starts up QEMU using the NixOS configuration in
:file:`bordervm-configuration.nix`. :file:`bordervm-configuration.nix`.