sigil/nixos-modules/genode-init.nix

130 lines
3.5 KiB
Nix
Raw Normal View History

{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.genode.init;
children' = config.lib.children.freeze
(config.genode.init.children // config.genode.init.auxiliaryChildren);
2021-02-16 12:10:50 +01:00
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 = ''
2021-03-28 15:07:21 +02:00
let Sigil = env:DHALL_SIGIL
2021-03-28 15:07:21 +02:00
in Sigil.Init::{
, routes =
2021-03-28 15:07:21 +02:00
[ Sigil.Init.ServiceRoute.parent "File_system"
2021-04-21 09:26:33 +02:00
, Sigil.Init.ServiceRoute.parent "Gui"
2021-03-28 15:07:21 +02:00
, Sigil.Init.ServiceRoute.parent "IO_MEM"
, Sigil.Init.ServiceRoute.parent "IO_PORT"
, Sigil.Init.ServiceRoute.parent "IRQ"
2021-04-12 20:57:02 +02:00
, Sigil.Init.ServiceRoute.parent "Platform"
2021-03-28 15:07:21 +02:00
, Sigil.Init.ServiceRoute.parent "Rtc"
, Sigil.Init.ServiceRoute.parent "Terminal"
, Sigil.Init.ServiceRoute.parent "Timer"
]
}
'';
};
children = config.lib.types.children {
extraOptions = {
routeToNics = lib.mkOption {
type = with types; listOf str;
default = [ ];
example = [ "eth0" ];
description = ''
Grant access to these Nic interfaces.
'';
};
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.
'';
};
};
};
auxiliaryChildren = config.lib.types.children { extraOptions = { }; } // {
internal = true;
description = ''
Children added to support other children, such as drivers.
Do not manually add children here.
'';
};
2021-02-16 12:10:50 +01:00
romModules = mkOption {
type = types.attrsOf types.path;
default = { };
description = "Attr set of initial ROM modules";
};
};
config.genode.init = {
configFile = let
children = lib.mapAttrsToList
(name: value: '', { mapKey = "${name}", mapValue = ${value.config} }'')
2021-02-16 12:10:50 +01:00
children';
nicRoutes = lib.mapAttrsToList (child: value:
(map (label: ''
, { service =
{ name = "Nic"
, label = Sigil.Init.LabelSelector.prefix "${child} -> ${label}"
}
2021-03-28 15:07:21 +02:00
, route = Sigil.Init.Route.parent (None Text)
}
'') value.routeToNics)) config.genode.init.children;
in pkgs.writeText "init.dhall" ''
2021-03-28 15:07:21 +02:00
let Sigil = env:DHALL_SIGIL
let Init = Sigil.Init
let baseConfig = ${cfg.baseConfig}
in baseConfig // {
, verbose = ${if config.genode.init.verbose then "True" else "False"}
, children = baseConfig.children # ([ ${
toString children
2021-03-28 15:07:21 +02:00
} ] : Init.Children.Type)
2021-02-16 12:10:50 +01:00
, routes = baseConfig.routes # ([${
toString nicRoutes
2021-03-28 15:07:21 +02:00
}] : List Init.ServiceRoute.Type)
} : 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'))));
};
}