From 8354070b48ee3fd1f0923111500974e03fad5b0d Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Mon, 21 Dec 2020 13:31:11 +0100 Subject: [PATCH] nixos: add routeToNics to vbox guests --- nixos-modules/guest-vbox-linux.nix | 12 ++++++++++ nixos-modules/vbox-guest.dhall | 37 ++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/nixos-modules/guest-vbox-linux.nix b/nixos-modules/guest-vbox-linux.nix index 2e0de4d..e78e66b 100644 --- a/nixos-modules/guest-vbox-linux.nix +++ b/nixos-modules/guest-vbox-linux.nix @@ -22,6 +22,15 @@ in { ''; }; + routeToNics = lib.mkOption { + type = with types; listOf str; + default = [ "eth0" ]; + example = [ "eth0" "br0" ]; + description = '' + Grant access to these Nic interfaces. + ''; + }; + config = mkOption { description = '' A specification of the desired configuration of this @@ -88,6 +97,8 @@ in { in { + inherit (cfg) routeToNics; + inputs = with pkgs.genodePackages; [ libiconv vbox5 vfs_pipe ]; coreROMs = [ "platform_info" ]; @@ -99,6 +110,7 @@ in { , bootPkg = "${boot.storeRoot}" , bootUuid = ${boot.uuid} , memorySize = ${toString cfg.memorySize} + , nicLabels = ${builtins.toJSON cfg.routeToNics} : List Text , vmName = "${vmName}" } ''; diff --git a/nixos-modules/vbox-guest.dhall b/nixos-modules/vbox-guest.dhall index b54d202..7a56949 100644 --- a/nixos-modules/vbox-guest.dhall +++ b/nixos-modules/vbox-guest.dhall @@ -25,6 +25,7 @@ let Params , bootUuid : Text , bootFormat : BootFormat , memorySize : Natural + , nicLabels : List Text , vmName : Text } @@ -86,6 +87,36 @@ let toVbox ] } + let network = + XML.element + { name = "Network" + , attributes = XML.emptyAttributes + , content = + Prelude.List.map + { index : Natural, value : Text } + XML.Type + ( λ(label : { index : Natural, value : Text }) → + let index = Natural/show label.index + + in { name = "Adapter" + , attributes = toMap + { slot = index + , enabled = "true" + , MACAddress = "0800271D790${index}" + , cable = "true" + , type = "82540EM" + } + , content = + [ XML.leaf + { name = "BridgedInterface" + , attributes = XML.emptyAttributes + } + ] + } + ) + (Prelude.List.indexed Text params.nicLabels) + } + in '' @@ -110,11 +141,7 @@ let toVbox - - - - - + ${network}