2
0
Fork 0
genodepkgs/nixos-modules/genode-init.nix

124 lines
3.4 KiB
Nix

{ config, pkgs, lib, ... }:
with lib;
let
inputs = mkOption {
description = "List of packages to build a ROM store with.";
type = types.listOf types.package;
};
in {
options.genode.init = {
inherit inputs;
config = 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 "Timer" ] }
'';
};
children = mkOption {
type = with types;
attrsOf (submodule {
options = {
inherit inputs;
settings = mkOption {
type = types.path;
description = ''
Dhall configuration of child.
See https://git.sr.ht/~ehmry/dhall-genode/tree/master/Init/Child/Type
'';
};
};
});
};
subinits = mkOption {
type = types.attrsOf (types.submodule ({ config, options, ... }: {
options = {
config = mkOption {
description = ''
A specification of the desired configuration of this sub-init, as a NixOS module.
'';
type =
let confPkgs = if config.pkgs == null then pkgs else config.pkgs;
in lib.mkOptionType {
name = "Toplevel NixOS config";
merge = loc: defs:
(import (confPkgs.path + "/nixos/lib/eval-config.nix") {
inherit system;
pkgs = confPkgs;
baseModules =
import (confPkgs.path + "/nixos/modules/module-list.nix");
inherit (confPkgs) lib;
modules = let
extraConfig = {
_file = "module at ${__curPos.file}:${
toString __curPos.line
}";
config = { };
};
in [ extraConfig ] ++ (map (x: x.value) defs);
prefix = [ "containers" name ];
}).config;
};
};
pkgs = mkOption {
type = types.nullOr types.attrs;
default = null;
example = literalExample "pkgs";
description = ''
Customise which nixpkgs to use for this container.
'';
};
};
config = mkMerge [
(mkIf options.config.isDefined {
path = config.config.system.build.toplevel;
})
];
}));
default = { };
};
};
config = {
genode.init.inputs = with builtins;
[ pkgs.genodePackages.report_rom ] ++ concatLists
(catAttrs "inputs" (attrValues config.genode.init.children));
genode.init.config = builtins.toFile "init.dhall" ''
let baseConfig = ${config.genode.init.baseConfig}
in baseConfig with children = baseConfig.children # toMap {${
concatMapStrings
(name: ", `${name}` = ${config.genode.init.children.${name}.settings}")
(builtins.attrNames config.genode.init.children)
} }
'';
};
}