From b5d42cc7114871417d3d15202390161d8cfc197a Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Tue, 12 Jan 2021 12:39:35 +0100 Subject: [PATCH] nixos: move Nic drivers to core children --- nixos-modules/genode-init.nix | 16 ++++++- nixos-modules/hardware/nic.nix | 88 +++++++++++++++++----------------- tests/networking.nix | 5 +- 3 files changed, 63 insertions(+), 46 deletions(-) diff --git a/nixos-modules/genode-init.nix b/nixos-modules/genode-init.nix index 1268dd0..9a326f4 100644 --- a/nixos-modules/genode-init.nix +++ b/nixos-modules/genode-init.nix @@ -120,14 +120,28 @@ in { lib.mapAttrsToList (name: value: ", `${name}` = ${value.configFile}") cfg.children; + nicRoutes = lib.mapAttrsToList (child: value: + (map (label: '' + , { service = + { name = "Nic" + , label = Genode.Init.LabelSelector.prefix "${child}" + } + , route = Genode.Init.Route.parent (None Text) + } + '') value.routeToNics)) config.genode.init.children; + in pkgs.writeText "init.dhall" '' let Genode = env:DHALL_GENODE + let baseConfig = ${cfg.baseConfig} in baseConfig // { , verbose = ${if config.genode.init.verbose then "True" else "False"} , children = baseConfig.children # toMap {${toString children} } - } + , routes = baseConfig.routes # [${ + toString nicRoutes + }] : List Genode.Init.ServiceRoute.Type + } : Genode.Init.Type ''; }; diff --git a/nixos-modules/hardware/nic.nix b/nixos-modules/hardware/nic.nix index c6e6435..5c0f357 100644 --- a/nixos-modules/hardware/nic.nix +++ b/nixos-modules/hardware/nic.nix @@ -37,7 +37,7 @@ with lib; }; policyCheck = name: interface: let - clientList = filter (x x != null) (lib.mapAttrsToList + clientList = filter (x: x != null) (lib.mapAttrsToList (childName: value: if any (nic: nic == name) value.routeToNics then childName @@ -74,52 +74,51 @@ with lib; } '') (builtins.attrNames config.networking.interfaces); - genode.init.children = let - - nics = mapAttrs' (name: interface: - let name' = name + ".driver"; + genode.core.children = mapAttrs' (name: interface: + let name' = name + ".driver"; + in { + name = name'; + value = let + binary = with pkgs.genodePackages; + { + ipxe = ipxe_nic_drv; + virtio = virtio_nic_drv; + }.${interface.genode.driver}; in { - name = name'; - value = let - binary = with pkgs.genodePackages; - { - ipxe = ipxe_nic_drv; - virtio = virtio_nic_drv; - }.${interface.genode.driver}; - in { - inputs = [ binary ]; - configFile = let - policy = lib.mapAttrsToList (childName: value: - if any (nic: nic == name) value.routeToNics then '' - Init.Config.Policy::{ - , service = "Nic" - , label = Init.LabelSelector.prefix "${childName}" - } - '' else - "") config.genode.init.children; + inputs = [ binary ]; + configFile = let + policy = lib.mapAttrsToList (childName: value: + if any (nic: nic == name) value.routeToNics then '' + Init.Config.Policy::{ + , service = "Nic" + , label = Init.LabelSelector.prefix "nixos -> ${childName}" + } + '' else + "") config.genode.init.children; - in pkgs.writeText "${name'}.dhall" '' - let Genode = env:DHALL_GENODE + in pkgs.writeText "${name'}.dhall" '' + let Genode = env:DHALL_GENODE - let Init = Genode.Init + let Init = Genode.Init - in Init.Child.flat - Init.Child.Attributes::{ - , binary = "${binary.pname}" - , provides = [ "Nic" ] - , resources = Init.Resources::{ caps = 128, ram = Genode.units.MiB 4 } - , routes = [ Init.ServiceRoute.parent "IO_MEM" ] - , config = Init.Config::{ - , attributes = toMap { verbose = "true" } - , policies = [ ${ - toString policy - } ] : List Init.Config.Policy.Type - } + in Init.Child.flat + Init.Child.Attributes::{ + , binary = "${binary.pname}" + , provides = [ "Nic" ] + , resources = Init.Resources::{ caps = 128, ram = Genode.units.MiB 4 } + , routes = [ Init.ServiceRoute.parent "IO_MEM" ] + , config = Init.Config::{ + , attributes = toMap { verbose = "true" } + , policies = [ ${ + toString policy + } ] : List Init.Config.Policy.Type } - ''; - }; - }) config.networking.interfaces; + } + ''; + }; + }) config.networking.interfaces; + genode.init.children = let sockets = mapAttrs' (name: interface: let name' = name + ".sockets"; in { @@ -142,7 +141,10 @@ with lib; lxip = 32; }.${interface.genode.stack}; settings = with builtins; - lib.optionals (interface.ipv4.addresses != [ ]) + [{ + name = "label"; + value = name; + }] ++ lib.optionals (interface.ipv4.addresses != [ ]) (let addr = head interface.ipv4.addresses; in [ { @@ -204,7 +206,7 @@ with lib; }; }) config.networking.interfaces; - in nics // (lib.filterAttrs (n: v: v != null) sockets); + in lib.filterAttrs (n: v: v != null) sockets; }; diff --git a/tests/networking.nix b/tests/networking.nix index 930b5c1..450a08b 100644 --- a/tests/networking.nix +++ b/tests/networking.nix @@ -28,7 +28,6 @@ Child.Attributes::{ , binary = "ping" , resources = Init.Resources::{ ram = Genode.units.MiB 8 } - , routes = [ Init.ServiceRoute.child "Nic" "eth1.driver" ] , config = Init.Config::{ , attributes = toMap { interface = "${ipA.address}/${ @@ -47,7 +46,9 @@ }; testScript = '' - start_all() + a.start() + a.wait_until_serial_output('lwIP Nic interface up address=192.168.1.1') + b.start() b.wait_until_serial_output('child "ping" exited with exit value 0') ''; }