nixos-modules: consolidate common init functions
The "config.genode.init.children" option is a superset of the "config.genode.core.children" option, so refactor both into helper functions.
This commit is contained in:
parent
98175a0f9b
commit
165cf60551
|
@ -3,52 +3,8 @@
|
|||
with lib;
|
||||
let
|
||||
localPackages = pkgs.buildPackages;
|
||||
binary = mkOption {
|
||||
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" ];
|
||||
};
|
||||
extraInputs = mkOption {
|
||||
description = "List of packages to build a ROM store with.";
|
||||
default = [ ];
|
||||
type = types.listOf types.package;
|
||||
};
|
||||
|
||||
children' = with builtins;
|
||||
lib.attrsets.mapAttrs (childName: child:
|
||||
if child.binary != null then {
|
||||
inherit (child) binary configFile;
|
||||
roms = { };
|
||||
} else
|
||||
let bin = lib.getEris "bin" child.package;
|
||||
in {
|
||||
config = ''${child.configFile} "${bin.cap}"'';
|
||||
binary = bin.cap;
|
||||
roms = [{
|
||||
name = bin.cap;
|
||||
value = bin.path;
|
||||
}] ++ lib.mapAttrsToList (path: cap: {
|
||||
name = cap;
|
||||
value = path;
|
||||
}) bin.closure;
|
||||
}) config.genode.core.children;
|
||||
children' = config.lib.children.freeze config.genode.init.children;
|
||||
|
||||
coreErisCaps = with builtins;
|
||||
let pkgNames = [ "cached_fs_rom" "jitter_sponge" "rtc_drv" ];
|
||||
|
@ -177,6 +133,9 @@ let
|
|||
}) config.genode.init.romModules;
|
||||
|
||||
in {
|
||||
|
||||
imports = [ ./lib/children.nix ];
|
||||
|
||||
options.genode = {
|
||||
|
||||
core = {
|
||||
|
@ -193,13 +152,7 @@ in {
|
|||
description = "Hardware supported by this core.";
|
||||
};
|
||||
|
||||
children = mkOption {
|
||||
type = with types;
|
||||
attrsOf (submodule {
|
||||
options = {
|
||||
inherit binary coreROMs extraInputs package;
|
||||
configFile = mkOption {
|
||||
type = types.path;
|
||||
children = config.lib.types.children { extraOptions = { }; } // {
|
||||
description = ''
|
||||
Set of children at the lowest init level, these children must not
|
||||
have any dependency on a Nix store.
|
||||
|
@ -208,9 +161,6 @@ in {
|
|||
See https://git.sr.ht/~ehmry/dhall-genode/tree/master/Init/Child/Type
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -5,62 +5,7 @@ with lib;
|
|||
let
|
||||
cfg = config.genode.init;
|
||||
|
||||
binary = mkOption {
|
||||
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" ];
|
||||
};
|
||||
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 = [ ];
|
||||
type = types.listOf types.attrs;
|
||||
};
|
||||
|
||||
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;
|
||||
children' = config.lib.children.freeze config.genode.init.children;
|
||||
|
||||
in {
|
||||
|
||||
|
@ -96,12 +41,8 @@ in {
|
|||
'';
|
||||
};
|
||||
|
||||
children = mkOption {
|
||||
default = { };
|
||||
type = with types;
|
||||
attrsOf (submodule {
|
||||
options = {
|
||||
inherit binary coreROMs extraErisInputs extraInputs package;
|
||||
children = config.lib.types.children {
|
||||
extraOptions = {
|
||||
|
||||
routeToNics = lib.mkOption {
|
||||
type = with types; listOf str;
|
||||
|
@ -121,17 +62,8 @@ in {
|
|||
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
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
romModules = mkOption {
|
||||
type = types.attrsOf types.path;
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
lib = {
|
||||
|
||||
# Type of a declaration of init children.
|
||||
types.children = { extraOptions }:
|
||||
with lib;
|
||||
mkOption {
|
||||
default = { };
|
||||
type = with types;
|
||||
attrsOf (submodule {
|
||||
options = {
|
||||
|
||||
binary = mkOption {
|
||||
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";
|
||||
};
|
||||
|
||||
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" ];
|
||||
};
|
||||
|
||||
configFile = mkOption {
|
||||
type = types.path;
|
||||
description = ''
|
||||
Dhall configuration of child.
|
||||
See https://git.sr.ht/~ehmry/dhall-genode/tree/master/Init/Child/Type
|
||||
'';
|
||||
};
|
||||
|
||||
extraErisInputs = mkOption {
|
||||
description = "List of ERIS inputs to add to the init closure.";
|
||||
default = [ ];
|
||||
type = types.listOf types.attrs;
|
||||
};
|
||||
|
||||
extraInputs =
|
||||
# TODO: deprecated?
|
||||
mkOption {
|
||||
description = "List of packages to build a ROM store with.";
|
||||
default = [ ];
|
||||
type = types.listOf types.package;
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
description = "Package to source the binary for this child.";
|
||||
type = lib.types.package;
|
||||
example = literalExample "pkg.genodePackages.init";
|
||||
};
|
||||
|
||||
} // extraOptions;
|
||||
});
|
||||
};
|
||||
|
||||
/* Map a set of children to the config and
|
||||
ROM closure of each child.
|
||||
*/
|
||||
children.freeze = children:
|
||||
with builtins;
|
||||
lib.attrsets.mapAttrs (_:
|
||||
{ binary, configFile, extraErisInputs, package, ... }:
|
||||
let
|
||||
toRoms = { cap, closure, path }:
|
||||
[{
|
||||
name = cap;
|
||||
value = path;
|
||||
}] ++ (lib.mapAttrsToList (value: name: { inherit name value; })
|
||||
closure);
|
||||
extraRoms = map toRoms extraErisInputs;
|
||||
in if binary != null then {
|
||||
config = ''${configFile} "${binary}"'';
|
||||
roms = extraRoms;
|
||||
} else
|
||||
let bin = lib.getEris "bin" package;
|
||||
in {
|
||||
config = ''${configFile} "${bin.cap}"'';
|
||||
roms = toRoms bin ++ extraRoms;
|
||||
}) children;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue