assimilate networking
This commit is contained in:
parent
3d5b687b4b
commit
d37517ebe6
|
@ -82,6 +82,8 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
initInputs = unique config.genode.init.inputs;
|
||||||
|
|
||||||
mergeManifests = inputs:
|
mergeManifests = inputs:
|
||||||
localPackages.writeTextFile {
|
localPackages.writeTextFile {
|
||||||
name = "manifest.dhall";
|
name = "manifest.dhall";
|
||||||
|
@ -99,12 +101,12 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
storeManifest =
|
storeManifest =
|
||||||
mergeManifests (map addManifest config.genode.init.inputs);
|
mergeManifests (map addManifest initInputs);
|
||||||
|
|
||||||
storeTarball = localPackages.runCommand "store" { } ''
|
storeTarball = localPackages.runCommand "store" { } ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
tar cf "$out/store.tar" --absolute-names ${
|
tar cf "$out/store.tar" --absolute-names ${
|
||||||
toString config.genode.init.inputs
|
toString initInputs
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
|
@ -1,36 +1,54 @@
|
||||||
# genodeInit.children is an attrset of nixos configurations, like containers
|
|
||||||
|
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
{
|
let
|
||||||
imports = [ ];
|
inputs = mkOption {
|
||||||
|
description = "List of packages to build a ROM store with.";
|
||||||
|
type = types.listOf types.package;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
|
||||||
options.genode.init = {
|
options.genode.init = {
|
||||||
|
inherit inputs;
|
||||||
|
|
||||||
config = mkOption {
|
config = mkOption {
|
||||||
description = "Dhall configuration of this init instance";
|
description = ''
|
||||||
type = types.nullOr types.str;
|
Dhall configuration of this init instance after children have been merged.
|
||||||
default = null;
|
'';
|
||||||
|
type = types.path;
|
||||||
};
|
};
|
||||||
|
|
||||||
inputs = mkOption {
|
baseConfig = mkOption {
|
||||||
description = "List of packages to build a ROM store with.";
|
description = ''
|
||||||
type = types.listOf types.package;
|
Dhall configuration of this init instance before merging children.
|
||||||
|
'';
|
||||||
|
type = types.str;
|
||||||
|
default = ''
|
||||||
|
let Genode = env:DHALL_GENODE
|
||||||
|
|
||||||
|
in Genode.Init::{ routes = [ Genode.Init.ServiceRoute.parent "Timer" ] }
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
children = mkOption {
|
children = mkOption {
|
||||||
type = let
|
type = with types;
|
||||||
childOptions = { name, ... }: {
|
attrsOf (submodule {
|
||||||
name = mkOption { type = types.str; };
|
options = {
|
||||||
dhallAttrs = mkOption { type = types.str; };
|
inherit inputs;
|
||||||
};
|
settings = mkOption {
|
||||||
in types.attrsOf (types.submodule childOptions);
|
type = types.path;
|
||||||
|
description = ''
|
||||||
|
Dhall configuration of child.
|
||||||
|
See https://git.sr.ht/~ehmry/dhall-genode/tree/master/Init/Child/Type
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
subinits = mkOption {
|
subinits = mkOption {
|
||||||
type = types.attrsOf (types.submodule ({ config, options, name, ... }: {
|
type = types.attrsOf (types.submodule ({ config, options, ... }: {
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
config = mkOption {
|
config = mkOption {
|
||||||
|
@ -86,6 +104,20 @@ with lib;
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
||||||
|
genode.init.inputs = with builtins;
|
||||||
|
[ pkgs.genodePackages.report_rom ] ++ concatLists
|
||||||
|
(catAttrs "inputs" (attrValues config.genode.init.children));
|
||||||
|
|
||||||
|
genode.init.config = builtins.toFile "init.dhall" ''
|
||||||
|
let baseConfig = ${config.genode.init.baseConfig}
|
||||||
|
|
||||||
|
in baseConfig with children = baseConfig.children # toMap {${
|
||||||
|
concatMapStrings
|
||||||
|
(name: ", `${name}` = ${config.genode.init.children.${name}.settings}")
|
||||||
|
(builtins.attrNames config.genode.init.children)
|
||||||
|
} }
|
||||||
|
'';
|
||||||
|
|
||||||
system.build.initXml = pkgs.buildPackages.runCommand "init.xml" {
|
system.build.initXml = pkgs.buildPackages.runCommand "init.xml" {
|
||||||
nativeBuildInputs = with pkgs.buildPackages; [ dhall xorg.lndir ];
|
nativeBuildInputs = with pkgs.buildPackages; [ dhall xorg.lndir ];
|
||||||
DHALL_GENODE = "${pkgs.genodePackages.dhallGenode}/binary.dhall";
|
DHALL_GENODE = "${pkgs.genodePackages.dhallGenode}/binary.dhall";
|
||||||
|
|
|
@ -1,50 +1,202 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
|
|
||||||
with lib; {
|
with lib;
|
||||||
options.genode = {
|
|
||||||
hardware = {
|
|
||||||
|
|
||||||
nic = mkOption {
|
{
|
||||||
default = { };
|
options.genode.hardware.nic = mkOption {
|
||||||
example = { eth0.driver = "virtio"; };
|
example = {
|
||||||
description = "The configuration for each Nic service.";
|
eth0 = {
|
||||||
type = let
|
driver = "virtio";
|
||||||
|
stack = "lwip";
|
||||||
nicOptions = { name, ... }: {
|
};
|
||||||
name = mkOption {
|
};
|
||||||
|
default = { };
|
||||||
example = "eth0";
|
description = "The configuration for each Nic service.";
|
||||||
type = types.str;
|
type = with types;
|
||||||
description = "Name of the Nic service.";
|
attrsOf (submodule {
|
||||||
};
|
options = {
|
||||||
|
|
||||||
driver = mkOption { type = types.enum [ "ipxe" "virtio" ]; };
|
|
||||||
|
|
||||||
ipStack = mkOption {
|
|
||||||
type = types.enum [ "lwip" "lxip" ];
|
|
||||||
default = "lwip";
|
|
||||||
};
|
|
||||||
|
|
||||||
|
driver = mkOption {
|
||||||
|
type = types.enum [ "ipxe" "virtio" ];
|
||||||
|
default = "ipxe";
|
||||||
};
|
};
|
||||||
|
|
||||||
in types.attrsOf (types.submodule nicOptions);
|
stack = mkOption {
|
||||||
};
|
type = types.enum [ "lwip" "lxip" ];
|
||||||
|
default = "lwip";
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
||||||
genode.init.children = let
|
genode.init.children = let
|
||||||
drivers = mapAttrsToList (name: interface: {
|
inherit (builtins) toFile;
|
||||||
name = name + "-nic";
|
|
||||||
value = { };
|
nics = mapAttrs' (name: interface:
|
||||||
}) config.networking.interfaces;
|
let name' = "nic." + name;
|
||||||
sockets = mapAttrsToList (name: interface: {
|
in {
|
||||||
name = name + "-sockets";
|
name = name';
|
||||||
value = { };
|
value = {
|
||||||
}) config.networking.interfaces;
|
inputs = with pkgs.genodePackages;
|
||||||
in builtins.listToAttrs (drivers ++ sockets);
|
{
|
||||||
|
ipxe = [ ipxe_nic_drv ];
|
||||||
|
virtio = [ virtio_nic_drv ];
|
||||||
|
}.${config.genode.hardware.nic.${name}.driver};
|
||||||
|
settings = toFile "${name'}.dhall" ''
|
||||||
|
let Genode = env:DHALL_GENODE
|
||||||
|
|
||||||
|
let Init = Genode.Init
|
||||||
|
|
||||||
|
in Init.Child.flat
|
||||||
|
Init.Child.Attributes::{
|
||||||
|
, binary = "virtio_pci_nic"
|
||||||
|
, provides = [ "Nic" ]
|
||||||
|
, resources = Init.Resources::{
|
||||||
|
, caps = 128
|
||||||
|
, ram = Genode.units.MiB 4
|
||||||
|
}
|
||||||
|
, routes = [ Init.ServiceRoute.parent "IO_MEM" ]
|
||||||
|
, config = Init.Config::{
|
||||||
|
, policies =
|
||||||
|
[ Init.Config.Policy::{
|
||||||
|
, service = "Nic"
|
||||||
|
, label =
|
||||||
|
Init.LabelSelector.prefix "sockets.${name}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}) config.networking.interfaces;
|
||||||
|
|
||||||
|
sockets = mapAttrs' (name: interface:
|
||||||
|
let name' = "sockets." + name;
|
||||||
|
in {
|
||||||
|
name = name';
|
||||||
|
value = {
|
||||||
|
inputs = with pkgs.genodePackages;
|
||||||
|
{
|
||||||
|
lwip = [ vfs_lwip ];
|
||||||
|
lxip = [ vfs_lixp ];
|
||||||
|
}.${config.genode.hardware.nic.${name}.stack};
|
||||||
|
settings = let ipv4 = builtins.head interface.ipv4.addresses;
|
||||||
|
in toFile "${name'}.dhall" ''
|
||||||
|
let Genode = env:DHALL_GENODE
|
||||||
|
|
||||||
|
let Init = Genode.Init
|
||||||
|
|
||||||
|
in Init.Child.flat
|
||||||
|
Init.Child.Attributes::{
|
||||||
|
, binary = "vfs"
|
||||||
|
, provides = [ "File_system" ]
|
||||||
|
, resources = Init.Resources::{ caps = 128, ram = Genode.units.MiB 16 }
|
||||||
|
, config = Init.Config::{
|
||||||
|
, defaultPolicy = Some Init.Config.DefaultPolicy::{
|
||||||
|
, attributes = toMap { root = "/", writeable = "yes" }
|
||||||
|
}
|
||||||
|
, content =
|
||||||
|
let XML = Genode.Prelude.XML
|
||||||
|
|
||||||
|
in [ XML.element
|
||||||
|
{ name = "vfs"
|
||||||
|
, attributes = XML.emptyAttributes
|
||||||
|
, content =
|
||||||
|
[ XML.leaf
|
||||||
|
{ name = "lwip"
|
||||||
|
, attributes = toMap
|
||||||
|
{ ip_addr = "${ipv4.address}", netmask = "${
|
||||||
|
if ipv4.prefixLength == 24 then
|
||||||
|
"255.255.255.0"
|
||||||
|
else
|
||||||
|
throw
|
||||||
|
"missing prefix to netmask conversion"
|
||||||
|
}" }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}) config.networking.interfaces;
|
||||||
|
|
||||||
|
in nics // sockets // {
|
||||||
|
|
||||||
|
platform_drv = {
|
||||||
|
inputs = [ pkgs.genodePackages.platform_drv ];
|
||||||
|
settings = let
|
||||||
|
policies = concatMapStrings (name: ''
|
||||||
|
Init.Config.Policy::{
|
||||||
|
, service = "Platform"
|
||||||
|
, label = Init.LabelSelector.prefix "nic.${name}"
|
||||||
|
, content =
|
||||||
|
[ Genode.Prelude.XML.leaf
|
||||||
|
{ name = "pci", attributes = toMap { class = "ETHERNET" } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
'') (builtins.attrNames config.networking.interfaces);
|
||||||
|
in toFile "platform_drv.dhall" ''
|
||||||
|
let Genode = env:DHALL_GENODE
|
||||||
|
|
||||||
|
let Init = Genode.Init
|
||||||
|
|
||||||
|
let label = \(_ : Text) -> { local = _, route = _ }
|
||||||
|
|
||||||
|
in Init.Child.flat
|
||||||
|
Init.Child.Attributes::{
|
||||||
|
, binary = "platform_drv"
|
||||||
|
, resources = Init.Resources::{
|
||||||
|
, caps = 800
|
||||||
|
, ram = Genode.units.MiB 4
|
||||||
|
, constrainPhys = True
|
||||||
|
}
|
||||||
|
, reportRoms = [ label "acpi" ]
|
||||||
|
, provides = [ "Platform" ]
|
||||||
|
, routes =
|
||||||
|
[ Init.ServiceRoute.parent "IRQ"
|
||||||
|
, Init.ServiceRoute.parent "IO_MEM"
|
||||||
|
, Init.ServiceRoute.parent "IO_PORT"
|
||||||
|
]
|
||||||
|
, config = Init.Config::{
|
||||||
|
, policies = [ ${policies} ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
acpi_drv = {
|
||||||
|
inputs = [ pkgs.genodePackages.acpi_drv ];
|
||||||
|
settings = toFile "acpi_drv.dhall" ''
|
||||||
|
let Genode = env:DHALL_GENODE
|
||||||
|
|
||||||
|
let Init = Genode.Init
|
||||||
|
|
||||||
|
let label = \(_ : Text) -> { local = _, route = _ }
|
||||||
|
|
||||||
|
in Init.Child.flat
|
||||||
|
Init.Child.Attributes::{
|
||||||
|
, binary = "acpi_drv"
|
||||||
|
, resources = Init.Resources::{
|
||||||
|
, caps = 400
|
||||||
|
, ram = Genode.units.MiB 4
|
||||||
|
, constrainPhys = True
|
||||||
|
}
|
||||||
|
, romReports = [ label "acpi" ]
|
||||||
|
, routes =
|
||||||
|
[ Init.ServiceRoute.parent "IRQ"
|
||||||
|
, Init.ServiceRoute.parent "IO_MEM"
|
||||||
|
, Init.ServiceRoute.parent "IO_PORT"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,17 @@
|
||||||
webserver = {
|
webserver = {
|
||||||
imports = [ ../nixos-modules/hardware.nix ];
|
imports = [ ../nixos-modules/hardware.nix ];
|
||||||
services.lighttpd.enable = true;
|
services.lighttpd.enable = true;
|
||||||
|
genode.hardware.nic.eth1.driver = "virtio";
|
||||||
|
genode.hardware.nic.eth1.stack = "lwip";
|
||||||
};
|
};
|
||||||
client = {
|
client = {
|
||||||
imports = [ ../nixos-modules/hardware.nix ];
|
imports = [ ../nixos-modules/hardware.nix ];
|
||||||
genode.hardware.nic.eth0.driver = "virtio";
|
genode.hardware.nic.eth1.driver = "virtio";
|
||||||
|
genode.hardware.nic.eth1.stack = "lwip";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
testScript = ''
|
||||||
|
start_all()
|
||||||
|
client.wait_until_serial_output("forever")
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user