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;
|
with lib;
|
||||||
let
|
let
|
||||||
localPackages = pkgs.buildPackages;
|
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;
|
children' = config.lib.children.freeze config.genode.init.children;
|
||||||
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;
|
|
||||||
|
|
||||||
coreErisCaps = with builtins;
|
coreErisCaps = with builtins;
|
||||||
let pkgNames = [ "cached_fs_rom" "jitter_sponge" "rtc_drv" ];
|
let pkgNames = [ "cached_fs_rom" "jitter_sponge" "rtc_drv" ];
|
||||||
|
@ -177,6 +133,9 @@ let
|
||||||
}) config.genode.init.romModules;
|
}) config.genode.init.romModules;
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
|
||||||
|
imports = [ ./lib/children.nix ];
|
||||||
|
|
||||||
options.genode = {
|
options.genode = {
|
||||||
|
|
||||||
core = {
|
core = {
|
||||||
|
@ -193,23 +152,14 @@ in {
|
||||||
description = "Hardware supported by this core.";
|
description = "Hardware supported by this core.";
|
||||||
};
|
};
|
||||||
|
|
||||||
children = mkOption {
|
children = config.lib.types.children { extraOptions = { }; } // {
|
||||||
type = with types;
|
description = ''
|
||||||
attrsOf (submodule {
|
Set of children at the lowest init level, these children must not
|
||||||
options = {
|
have any dependency on a Nix store.
|
||||||
inherit binary coreROMs extraInputs package;
|
Configuration format is a Dhall configuration of type
|
||||||
configFile = mkOption {
|
<literal>Genode.Init.Child.Type</literal>.
|
||||||
type = types.path;
|
See https://git.sr.ht/~ehmry/dhall-genode/tree/master/Init/Child/Type
|
||||||
description = ''
|
'';
|
||||||
Set of children at the lowest init level, these children must not
|
|
||||||
have any dependency on a Nix store.
|
|
||||||
Configuration format is a Dhall configuration of type
|
|
||||||
<literal>Genode.Init.Child.Type</literal>.
|
|
||||||
See https://git.sr.ht/~ehmry/dhall-genode/tree/master/Init/Child/Type
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,62 +5,7 @@ with lib;
|
||||||
let
|
let
|
||||||
cfg = config.genode.init;
|
cfg = config.genode.init;
|
||||||
|
|
||||||
binary = mkOption {
|
children' = config.lib.children.freeze config.genode.init.children;
|
||||||
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;
|
|
||||||
|
|
||||||
in {
|
in {
|
||||||
|
|
||||||
|
@ -96,41 +41,28 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
children = mkOption {
|
children = config.lib.types.children {
|
||||||
default = { };
|
extraOptions = {
|
||||||
type = with types;
|
|
||||||
attrsOf (submodule {
|
|
||||||
options = {
|
|
||||||
inherit binary coreROMs extraErisInputs extraInputs package;
|
|
||||||
|
|
||||||
routeToNics = lib.mkOption {
|
routeToNics = lib.mkOption {
|
||||||
type = with types; listOf str;
|
type = with types; listOf str;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
example = [ "eth0" ];
|
example = [ "eth0" ];
|
||||||
description = ''
|
description = ''
|
||||||
Grant access to these Nic interfaces.
|
Grant access to these Nic interfaces.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
fsPersistence = lib.mkOption {
|
fsPersistence = lib.mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Whether this child will have access to mutable and persistent storage.
|
Whether this child will have access to mutable and persistent storage.
|
||||||
This space is shared among all components for which this option is available
|
This space is shared among all components for which this option is available
|
||||||
and UNIX permission bits are not honored.
|
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 {
|
romModules = mkOption {
|
||||||
|
|
|
@ -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