2020-11-01 20:21:27 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2020-11-03 19:21:10 +01:00
|
|
|
cfg = config.genode.init;
|
2021-02-16 15:25:30 +01:00
|
|
|
|
|
|
|
binary = mkOption {
|
|
|
|
description = "Program binary for this child.";
|
|
|
|
type = types.path;
|
|
|
|
};
|
2020-11-10 15:49:12 +01:00
|
|
|
coreROMs = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
List of label suffixes that when matched against
|
|
|
|
ROM requests shall be forwared to the core.
|
|
|
|
'';
|
|
|
|
example = [ "platform_info" ];
|
|
|
|
};
|
2021-02-16 15:25:30 +01:00
|
|
|
extraInputs = mkOption {
|
2020-11-01 20:21:27 +01:00
|
|
|
description = "List of packages to build a ROM store with.";
|
2020-11-03 19:21:10 +01:00
|
|
|
default = [ ];
|
2020-11-01 20:21:27 +01:00
|
|
|
type = types.listOf types.package;
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
|
|
|
|
options.genode.init = {
|
|
|
|
|
2020-11-10 15:46:24 +01:00
|
|
|
verbose = mkEnableOption "verbose logging";
|
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
configFile = mkOption {
|
|
|
|
description = ''
|
|
|
|
Dhall configuration of this init instance after children have been merged.
|
|
|
|
'';
|
|
|
|
type = types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
baseConfig = mkOption {
|
|
|
|
description =
|
|
|
|
"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 "File_system"
|
|
|
|
, Genode.Init.ServiceRoute.parent "IO_MEM"
|
|
|
|
, Genode.Init.ServiceRoute.parent "IO_PORT"
|
2020-12-02 19:25:07 +01:00
|
|
|
, Genode.Init.ServiceRoute.parent "IRQ"
|
|
|
|
, Genode.Init.ServiceRoute.parent "Rtc"
|
|
|
|
, Genode.Init.ServiceRoute.parent "Terminal"
|
|
|
|
, Genode.Init.ServiceRoute.parent "Timer"
|
2020-11-01 20:21:27 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
children = mkOption {
|
|
|
|
default = { };
|
|
|
|
type = with types;
|
|
|
|
attrsOf (submodule {
|
|
|
|
options = {
|
2021-02-16 15:25:30 +01:00
|
|
|
inherit binary coreROMs extraInputs;
|
2020-12-20 14:56:47 +01:00
|
|
|
|
|
|
|
routeToNics = lib.mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "eth0" ];
|
|
|
|
description = ''
|
|
|
|
Grant access to these Nic interfaces.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-12-31 09:36:19 +01:00
|
|
|
fsPersistence = lib.mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether this child will have access to mutable and persistent storage.
|
|
|
|
This space is shared among all components for which this option is available
|
|
|
|
and UNIX permission bits are not honored.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
configFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = ''
|
|
|
|
Dhall configuration of child.
|
|
|
|
See https://git.sr.ht/~ehmry/dhall-genode/tree/master/Init/Child/Type
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-11-03 19:21:10 +01:00
|
|
|
subinits =
|
|
|
|
# Subinits are just a different kind of children.
|
|
|
|
# Eventually this will be nested "genode.init" instances.
|
|
|
|
mkOption {
|
|
|
|
default = { };
|
|
|
|
type = with types;
|
|
|
|
attrsOf (submodule {
|
|
|
|
options = {
|
2021-02-16 15:25:30 +01:00
|
|
|
inherit binary coreROMs extraInputs;
|
2020-11-03 19:21:10 +01:00
|
|
|
configFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = ''
|
|
|
|
Dhall configuration of child init.
|
|
|
|
See https://git.sr.ht/~ehmry/dhall-genode/tree/master/Init/Type
|
|
|
|
'';
|
|
|
|
};
|
2020-11-01 20:21:27 +01:00
|
|
|
};
|
2020-11-03 19:21:10 +01:00
|
|
|
});
|
|
|
|
};
|
2020-11-01 20:21:27 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-11-03 19:21:10 +01:00
|
|
|
config.genode.init = {
|
2020-11-01 20:21:27 +01:00
|
|
|
|
|
|
|
# TODO: convert the subinits to children
|
|
|
|
|
2020-11-03 19:21:10 +01:00
|
|
|
children = mapAttrs (name: value: {
|
2021-02-16 15:25:30 +01:00
|
|
|
inherit (value) extraInputs;
|
2020-11-03 19:21:10 +01:00
|
|
|
configFile = pkgs.writeText "${name}.child.dhall" ''
|
|
|
|
let Genode = env:DHALL_GENODE
|
|
|
|
|
|
|
|
in Genode.Init.toChild ${value.configFile} Genode.Init.Attributes.default
|
|
|
|
'';
|
|
|
|
}) cfg.subinits;
|
|
|
|
|
2020-11-10 15:46:24 +01:00
|
|
|
configFile = let
|
|
|
|
|
2021-02-16 15:25:30 +01:00
|
|
|
children = lib.mapAttrsToList
|
|
|
|
(name: value: '', `${name}` = ${value.configFile} "${value.binary}"'')
|
2020-11-10 15:46:24 +01:00
|
|
|
cfg.children;
|
|
|
|
|
2021-01-12 12:39:35 +01:00
|
|
|
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;
|
|
|
|
|
2020-11-10 15:46:24 +01:00
|
|
|
in pkgs.writeText "init.dhall" ''
|
2020-11-01 20:21:27 +01:00
|
|
|
let Genode = env:DHALL_GENODE
|
2021-01-12 12:39:35 +01:00
|
|
|
|
2020-11-03 19:21:10 +01:00
|
|
|
let baseConfig = ${cfg.baseConfig}
|
2020-11-01 20:21:27 +01:00
|
|
|
|
2020-11-10 15:46:24 +01:00
|
|
|
in baseConfig // {
|
|
|
|
, verbose = ${if config.genode.init.verbose then "True" else "False"}
|
|
|
|
, children = baseConfig.children # toMap {${toString children} }
|
2021-01-12 12:39:35 +01:00
|
|
|
, routes = baseConfig.routes # [${
|
|
|
|
toString nicRoutes
|
|
|
|
}] : List Genode.Init.ServiceRoute.Type
|
|
|
|
} : Genode.Init.Type
|
2020-11-01 20:21:27 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|