2020-11-01 20:21:27 +01:00
|
|
|
{ config, pkgs, lib, modulesPath, ... }:
|
|
|
|
|
|
|
|
with lib;
|
2020-12-03 12:48:07 +01:00
|
|
|
let
|
|
|
|
localPackages = pkgs.buildPackages;
|
2021-03-02 22:55:59 +01:00
|
|
|
|
2021-03-12 18:50:40 +01:00
|
|
|
children' = config.lib.children.freeze
|
|
|
|
(config.genode.core.children // config.genode.core.supportChildren);
|
2021-02-16 12:10:50 +01:00
|
|
|
|
|
|
|
coreErisCaps = with builtins;
|
2021-03-04 15:02:39 +01:00
|
|
|
let pkgNames = [ "rtc_drv" ];
|
2021-02-16 12:10:50 +01:00
|
|
|
in listToAttrs (map (name:
|
|
|
|
let pkg = pkgs.genodePackages.${name};
|
|
|
|
in {
|
|
|
|
inherit name;
|
|
|
|
value = lib.getEris "bin" pkg;
|
|
|
|
}) pkgNames);
|
|
|
|
|
|
|
|
tarball =
|
|
|
|
"${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar";
|
|
|
|
|
|
|
|
bootConfigFile = let
|
|
|
|
|
|
|
|
storeBackendInputs = {
|
2021-03-04 15:02:39 +01:00
|
|
|
fs = [ ];
|
2021-02-16 12:10:50 +01:00
|
|
|
memory = [ config.system.build.tarball ];
|
2021-03-04 15:02:39 +01:00
|
|
|
net = [ ];
|
2021-02-16 12:10:50 +01:00
|
|
|
}.${config.genode.boot.storeBackend};
|
|
|
|
|
2021-03-12 18:50:40 +01:00
|
|
|
coreInputs =
|
|
|
|
# TODO: get rid of this?
|
|
|
|
with builtins;
|
2021-02-16 12:10:50 +01:00
|
|
|
concatMap (getAttr "extraInputs")
|
2021-03-12 18:50:40 +01:00
|
|
|
((attrValues config.genode.core.children)
|
|
|
|
++ (attrValues config.genode.core.supportChildren));
|
2021-02-16 12:10:50 +01:00
|
|
|
|
|
|
|
mergeManifests = inputs:
|
|
|
|
with builtins;
|
|
|
|
let
|
|
|
|
f = head: input:
|
|
|
|
if hasAttr "manifest" input then
|
|
|
|
''
|
|
|
|
${head}, { mapKey = "${
|
|
|
|
lib.getName input
|
|
|
|
}", mapValue = ${input.manifest} }''
|
|
|
|
else
|
|
|
|
abort "${input.pname} does not have a manifest";
|
2021-03-04 15:02:39 +01:00
|
|
|
in (foldl' f "([" inputs)
|
|
|
|
+ "] : List { mapKey : Text, mapValue : List { mapKey : Text, mapValue : Text } }) ";
|
2021-02-16 12:10:50 +01:00
|
|
|
|
|
|
|
addManifest = drv:
|
|
|
|
drv // {
|
|
|
|
manifest =
|
|
|
|
localPackages.runCommand "${drv.name}.dhall" { inherit drv; } ''
|
|
|
|
set -eu
|
|
|
|
echo -n '[' >> $out
|
|
|
|
find $drv/ -type f -printf ',{mapKey= "%p",mapValue="%p"}' >> $out
|
|
|
|
${if builtins.elem "lib" drv.outputs then
|
|
|
|
''
|
|
|
|
find ${drv.lib}/ -type f -printf ',{mapKey= "%p",mapValue="%p"}' >> $out''
|
|
|
|
else
|
|
|
|
""}
|
|
|
|
echo -n ']' >> $out
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
manifest =
|
|
|
|
# Manifests are Dhall metadata to be attached to every
|
|
|
|
# package to be used for dynamically buildings enviroments
|
|
|
|
# using Dhall expressions. Probably not worth pursuing.
|
|
|
|
pkgs.writeText "manifest.dhall" (mergeManifests (map addManifest
|
|
|
|
(with pkgs.genodePackages; storeBackendInputs ++ coreInputs))
|
|
|
|
+ lib.optionalString (config.genode.boot.romModules != { }) ''
|
|
|
|
# [ { mapKey = "romModules", mapValue = [ ${
|
|
|
|
lib.concatStringsSep ", " (lib.lists.flatten ((mapAttrsToList
|
|
|
|
(k: v: ''{ mapKey = "${k}", mapValue = "${v}" }'')
|
|
|
|
config.genode.boot.romModules)))
|
|
|
|
}] } ]'');
|
|
|
|
|
|
|
|
/* storeRomPolicies = mapAttrsToList
|
|
|
|
(name: value: '', { mapKey = "${name}", mapValue = "${value}" }'')
|
|
|
|
romDirectories;
|
|
|
|
*/
|
|
|
|
|
|
|
|
extraRoutes = lib.concatStringsSep ", " (lib.lists.flatten
|
|
|
|
(lib.mapAttrsToList (name: value:
|
|
|
|
map (suffix: ''
|
|
|
|
{ service =
|
|
|
|
{ name = "ROM"
|
|
|
|
, label =
|
2021-03-28 15:07:21 +02:00
|
|
|
Sigil.Init.LabelSelector.Type.Partial
|
2021-02-16 12:10:50 +01:00
|
|
|
{ prefix = Some "nixos -> ${name}", suffix = Some "${suffix}" }
|
|
|
|
}
|
2021-03-28 15:07:21 +02:00
|
|
|
, route = Sigil.Init.Route.parent (Some "${suffix}")
|
2021-02-16 12:10:50 +01:00
|
|
|
}
|
|
|
|
'') value.coreROMs) config.genode.init.children));
|
|
|
|
|
|
|
|
extraCoreChildren = "[ ${
|
|
|
|
lib.concatStringsSep ", " (lib.mapAttrsToList
|
|
|
|
(name: value: ''{ mapKey = "${name}", mapValue = ${value.config} }'')
|
|
|
|
children')
|
|
|
|
} ]";
|
|
|
|
|
|
|
|
in with coreErisCaps;
|
|
|
|
localPackages.runCommand "boot.dhall" { } ''
|
|
|
|
cat > $out << EOF
|
2021-03-28 15:07:21 +02:00
|
|
|
let Sigil = env:DHALL_SIGIL in
|
|
|
|
let VFS = Sigil.VFS
|
|
|
|
let XML = Sigil.Prelude.XML
|
2021-02-16 12:10:50 +01:00
|
|
|
in
|
|
|
|
${./store-wrapper.dhall}
|
2021-03-04 15:02:39 +01:00
|
|
|
{ binaries = { rtc_drv = "${rtc_drv.cap}" }
|
2021-02-16 12:10:50 +01:00
|
|
|
, extraCoreChildren = ${extraCoreChildren}
|
|
|
|
, subinit = ${config.genode.init.configFile}
|
|
|
|
, storeSize = $(stat --format '%s' ${tarball})
|
2021-03-28 15:07:21 +02:00
|
|
|
, routes = [${extraRoutes} ] : List Sigil.Init.ServiceRoute.Type
|
2021-02-16 12:10:50 +01:00
|
|
|
, bootManifest = ${manifest}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
|
|
|
|
erisContents = lib.attrsets.mapAttrsToList (urn: source: {
|
|
|
|
target = "eris/" + urn;
|
|
|
|
inherit source;
|
|
|
|
}) config.genode.init.romModules;
|
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
in {
|
2021-03-02 22:55:59 +01:00
|
|
|
|
|
|
|
imports = [ ./lib/children.nix ];
|
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
options.genode = {
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
core = {
|
|
|
|
|
|
|
|
prefix = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "hw-pc-";
|
2020-12-03 12:48:07 +01:00
|
|
|
description = "String prefix signifying the Genode core in use.";
|
2020-11-01 20:21:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
supportedSystems = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
example = [ "i686-genode" "x86_64-genode" ];
|
2020-12-03 12:48:07 +01:00
|
|
|
description = "Hardware supported by this core.";
|
|
|
|
};
|
|
|
|
|
2021-03-02 22:55:59 +01:00
|
|
|
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.
|
|
|
|
Configuration format is a Dhall configuration of type
|
2021-03-28 15:07:21 +02:00
|
|
|
<literal>Sigil.Init.Child.Type</literal>.
|
2021-03-02 22:55:59 +01:00
|
|
|
See https://git.sr.ht/~ehmry/dhall-genode/tree/master/Init/Child/Type
|
|
|
|
'';
|
2020-12-03 12:48:07 +01:00
|
|
|
};
|
2020-11-01 20:21:27 +01:00
|
|
|
|
2021-03-12 18:50:40 +01:00
|
|
|
supportChildren = config.lib.types.children { extraOptions = { }; } // {
|
|
|
|
internal = true;
|
|
|
|
description = ''
|
|
|
|
Children added to support other children, such as drivers.
|
|
|
|
Do not manually add children here.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
boot = {
|
|
|
|
|
|
|
|
configFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description = ''
|
|
|
|
Dhall boot configuration. See
|
|
|
|
https://git.sr.ht/~ehmry/dhall-genode/tree/master/Boot/package.dhall
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
image = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
description =
|
|
|
|
"Boot image containing the base component binaries and configuration.";
|
|
|
|
};
|
|
|
|
|
|
|
|
romModules = mkOption {
|
|
|
|
type = types.attrsOf types.path;
|
2020-12-03 12:48:07 +01:00
|
|
|
default = { };
|
2020-11-01 20:21:27 +01:00
|
|
|
description = "Attr set of initial ROM modules";
|
|
|
|
};
|
|
|
|
|
2020-12-03 12:48:07 +01:00
|
|
|
storeFsUuid = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = import ./store-fs-uuid;
|
|
|
|
description = "Custom partition type of the nix-store file-system.";
|
|
|
|
};
|
|
|
|
|
|
|
|
storePartUuid = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = import ./partition-type;
|
|
|
|
description = "Custom partition type of the nix-store file-system.";
|
|
|
|
};
|
|
|
|
|
|
|
|
storeBackend = mkOption {
|
2021-02-01 13:32:05 +01:00
|
|
|
type = types.enum [ "fs" "memory" ]; # "parent"?
|
|
|
|
default = "memory";
|
2020-12-03 12:48:07 +01:00
|
|
|
description = ''
|
2021-03-04 15:02:39 +01:00
|
|
|
Backend for the initial ROM store.
|
2020-12-03 12:48:07 +01:00
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2021-02-01 13:32:05 +01:00
|
|
|
<term>
|
|
|
|
<literal>fs</literal>
|
|
|
|
</term>
|
2020-12-03 12:48:07 +01:00
|
|
|
<listitem>
|
2021-02-01 13:32:05 +01:00
|
|
|
<para>Store backed by a File_system session.</para>
|
2020-12-03 12:48:07 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2021-02-01 13:32:05 +01:00
|
|
|
<term>
|
|
|
|
<literal>tarball</literal>
|
|
|
|
</term>
|
2020-12-03 12:48:07 +01:00
|
|
|
<listitem>
|
2021-02-01 13:32:05 +01:00
|
|
|
<para>An in-memory tarball.</para>
|
2020-12-03 12:48:07 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
storePaths = mkOption {
|
2021-03-02 17:45:54 +01:00
|
|
|
type = with types; listOf path;
|
2020-12-03 12:48:07 +01:00
|
|
|
description = ''
|
|
|
|
Derivations to be included in the Nix store in the generated boot image.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-02-16 12:10:50 +01:00
|
|
|
config = {
|
2020-11-01 20:21:27 +01:00
|
|
|
|
|
|
|
assertions = [{
|
2021-01-05 15:11:42 +01:00
|
|
|
assertion = builtins.any (s:
|
|
|
|
s == config.nixpkgs.system || s == config.nixpkgs.crossSystem.system)
|
2020-11-01 20:21:27 +01:00
|
|
|
config.genode.core.supportedSystems;
|
|
|
|
message = "invalid Genode core for this system";
|
|
|
|
}];
|
|
|
|
|
2021-02-16 12:10:50 +01:00
|
|
|
genode.boot.romModules = with builtins;
|
|
|
|
let getBin = name: "${getAttr name pkgs.genodePackages}/bin/${name}";
|
|
|
|
in listToAttrs (lib.lists.flatten
|
|
|
|
((map (getAttr "roms") (attrValues children')) ++ (map
|
|
|
|
({ cap, path, ... }: {
|
|
|
|
name = cap;
|
|
|
|
value = path;
|
|
|
|
}) (attrValues coreErisCaps)))) // {
|
|
|
|
"init" = "${pkgs.genodePackages.init}/bin/init";
|
|
|
|
"report_rom" = "${pkgs.genodePackages.report_rom}/bin/report_rom";
|
|
|
|
};
|
2021-02-03 20:39:25 +01:00
|
|
|
|
2021-03-04 15:02:39 +01:00
|
|
|
genode.core.children.jitter_sponge = {
|
|
|
|
package = pkgs.genodePackages.jitter_sponge;
|
|
|
|
configFile = pkgs.writeText "jitter_sponge.dhall" ''
|
2021-03-28 15:07:21 +02:00
|
|
|
let Sigil = env:DHALL_SIGIL
|
2021-03-04 15:02:39 +01:00
|
|
|
|
2021-03-28 15:07:21 +02:00
|
|
|
let Init = Sigil.Init
|
2021-03-04 15:02:39 +01:00
|
|
|
|
|
|
|
in λ(binary : Text) →
|
|
|
|
Init.Child.flat
|
|
|
|
Init.Child.Attributes::{
|
|
|
|
, binary
|
|
|
|
, config = Init.Config::{
|
|
|
|
, policies =
|
|
|
|
[ Init.Config.Policy::{
|
|
|
|
, service = "Terminal"
|
|
|
|
, label = Init.LabelSelector.suffix "entropy"
|
2021-02-16 15:25:30 +01:00
|
|
|
}
|
2021-03-04 15:02:39 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2020-11-10 15:49:12 +01:00
|
|
|
|
2021-03-04 15:02:39 +01:00
|
|
|
system.build.configFile = bootConfigFile;
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
# Create the tarball of the store to live in core ROM
|
|
|
|
system.build.tarball =
|
|
|
|
pkgs.callPackage "${modulesPath}/../lib/make-system-tarball.nix" {
|
2021-02-16 12:10:50 +01:00
|
|
|
extraInputs = lib.attrsets.mapAttrsToList (name: child: child.package)
|
|
|
|
config.genode.init.children;
|
|
|
|
contents = erisContents;
|
2020-11-01 20:21:27 +01:00
|
|
|
compressCommand = "cat";
|
|
|
|
compressionExtension = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
system.build.initXml = pkgs.buildPackages.runCommand "init.xml" {
|
2020-11-07 18:46:35 +01:00
|
|
|
nativeBuildInputs = with pkgs.buildPackages; [ dhall xorg.lndir libxml2 ];
|
2021-03-28 15:07:21 +02:00
|
|
|
DHALL_SIGIL = "${pkgs.genodePackages.dhallSigil}/binary.dhall";
|
2020-11-01 20:21:27 +01:00
|
|
|
} ''
|
|
|
|
export XDG_CACHE_HOME=$NIX_BUILD_TOP
|
|
|
|
lndir -silent \
|
2021-03-28 15:07:21 +02:00
|
|
|
${pkgs.genodePackages.dhallSigil}/.cache \
|
2020-11-01 20:21:27 +01:00
|
|
|
$XDG_CACHE_HOME
|
2021-03-28 15:07:21 +02:00
|
|
|
dhall text <<< "(env:DHALL_SIGIL).Init.render (${bootConfigFile}).config" > $out
|
2020-11-07 18:46:35 +01:00
|
|
|
xmllint --noout $out
|
2020-11-01 20:21:27 +01:00
|
|
|
'';
|
|
|
|
|
2020-12-30 21:07:30 +01:00
|
|
|
virtualisation.diskImage = let
|
2020-12-03 12:48:07 +01:00
|
|
|
espImage = import ./lib/make-esp-fs.nix { inherit config pkgs; };
|
2021-02-16 12:10:50 +01:00
|
|
|
storeFsImage = pkgs.callPackage ./lib/make-ext2-fs.nix {
|
|
|
|
inherit config lib pkgs;
|
|
|
|
contents = erisContents;
|
|
|
|
};
|
2020-12-03 12:48:07 +01:00
|
|
|
bootDriveImage = import ./lib/make-bootable-image.nix {
|
|
|
|
inherit config pkgs espImage storeFsImage;
|
|
|
|
};
|
2021-03-04 15:02:39 +01:00
|
|
|
in lib.mkIf (config.genode.boot.storeBackend == "fs") bootDriveImage;
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2021-03-04 15:02:39 +01:00
|
|
|
virtualisation.useBootLoader = config.genode.boot.storeBackend == "fs";
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2021-02-16 12:10:50 +01:00
|
|
|
virtualisation.qemu.options = let
|
|
|
|
blockCommon =
|
|
|
|
[ "-bios ${pkgs.buildPackages.buildPackages.OVMF.fd}/FV/OVMF.fd" ];
|
|
|
|
in {
|
|
|
|
fs = blockCommon;
|
2021-03-04 15:02:39 +01:00
|
|
|
net = [ ];
|
2021-02-16 12:10:50 +01:00
|
|
|
memory = [ ];
|
|
|
|
}.${config.genode.boot.storeBackend};
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|