sigil/nixos-modules/genode-init.nix

214 lines
6.2 KiB
Nix
Raw Normal View History

{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.genode.init;
binary = mkOption {
2021-02-16 12:10:50 +01:00
description = "Program binary for this child. Must be an ERIS URN.";
default = null;
type = types.nullOr
(types.str // { check = lib.strings.hasPrefix "urn:erisx2:"; });
example =
"urn:erisx2:AEAU4KT7AGJLA5BHPWFZ7HX2OVVNVFGDM2SIS726OPZBGXDED64QIDPHN2M5P5HIMOG3YDSWBGDPNUMZKCG4CRVU4DI5BOS5IJRFCSLQQY";
};
package = mkOption {
description = "Package to source the binary for this child.";
type = lib.types.package;
example = literalExample "pkg.genodePackages.init";
};
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 12:10:50 +01:00
extraInputs =
# TODO: deprecated?
mkOption {
description = "List of packages to build a ROM store with.";
default = [ ];
type = types.listOf types.package;
};
extraErisInputs = mkOption {
description = "List of ERIS inputs to add to the init closure.";
default = [ ];
2021-02-16 12:10:50 +01:00
type = types.listOf types.attrs;
};
2021-02-16 12:10:50 +01:00
children' = with builtins;
lib.attrsets.mapAttrs (childName: child:
let
toRoms = { cap, closure, path }:
[{
name = cap;
value = path;
}] ++ (lib.mapAttrsToList (value: name: { inherit name value; })
closure);
extraRoms = lib.lists.flatten (map toRoms child.extraErisInputs);
in if child.binary != null then {
inherit (child) binary configFile;
roms = { }; # extraRoms;
} else
let bin = lib.getEris "bin" child.package;
in {
config = ''${child.configFile} "${bin.cap}"'';
binary = bin.cap;
roms = toRoms bin ++ extraRoms;
}) config.genode.init.children;
in {
options.genode.init = {
verbose = mkEnableOption "verbose logging";
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"
, Genode.Init.ServiceRoute.parent "IRQ"
, Genode.Init.ServiceRoute.parent "Rtc"
, Genode.Init.ServiceRoute.parent "Terminal"
, Genode.Init.ServiceRoute.parent "Timer"
]
}
'';
};
children = mkOption {
default = { };
type = with types;
attrsOf (submodule {
options = {
2021-02-16 12:10:50 +01:00
inherit binary coreROMs extraErisInputs extraInputs package;
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.
'';
};
configFile = mkOption {
type = types.path;
description = ''
Dhall configuration of child.
See https://git.sr.ht/~ehmry/dhall-genode/tree/master/Init/Child/Type
'';
};
};
});
};
2021-02-16 12:10:50 +01:00
romModules = mkOption {
type = types.attrsOf types.path;
default = { };
description = "Attr set of initial ROM modules";
};
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 12:10:50 +01:00
inherit binary coreROMs extraErisInputs extraInputs;
configFile = mkOption {
type = types.path;
description = ''
Dhall configuration of child init.
See https://git.sr.ht/~ehmry/dhall-genode/tree/master/Init/Type
'';
};
};
});
};
};
config.genode.init = {
# TODO: convert the subinits to children
children = mapAttrs (name: value: {
2021-02-16 12:10:50 +01:00
inherit (value) extraErisInputs extraInputs;
configFile = pkgs.writeText "${name}.child.dhall" ''
let Genode = env:DHALL_GENODE
in Genode.Init.toChild ${value.configFile} Genode.Init.Attributes.default
'';
}) cfg.subinits;
configFile = let
2021-02-16 12:10:50 +01:00
children =
lib.mapAttrsToList (name: value: ", `${name}` = ${value.config} ")
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} }
2021-02-16 12:10:50 +01:00
, routes = baseConfig.routes # ([${
toString nicRoutes
2021-02-16 12:10:50 +01:00
}] : List Genode.Init.ServiceRoute.Type)
} : Genode.Init.Type
'';
2021-02-16 12:10:50 +01:00
romModules = with builtins;
listToAttrs (lib.lists.flatten
(map ({ roms, ... }: roms) (lib.lists.flatten (attrValues children'))));
};
}