nixos: move Nic drivers to core children

This commit is contained in:
Ehmry - 2021-01-12 12:39:35 +01:00
parent 07645a3930
commit b5d42cc711
3 changed files with 63 additions and 46 deletions

View File

@ -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
'';
};

View File

@ -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;
};

View File

@ -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')
'';
}