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;
|
|
|
|
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" ];
|
|
|
|
};
|
|
|
|
inputs = mkOption {
|
|
|
|
description = "List of packages to build a ROM store with.";
|
|
|
|
default = [ ];
|
|
|
|
type = types.listOf types.package;
|
|
|
|
};
|
2020-11-01 20:21:27 +01:00
|
|
|
in {
|
|
|
|
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-10 19:22:45 +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-10 19:22:45 +01:00
|
|
|
description = "Hardware supported by this core.";
|
2020-11-01 20:21:27 +01:00
|
|
|
};
|
|
|
|
|
2020-12-10 19:22:45 +01:00
|
|
|
basePackages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
description = ''
|
|
|
|
List of packages to make availabe before the Nix store is ready.
|
|
|
|
These are baked into <option>config.genode.core.image</option>.
|
|
|
|
'';
|
|
|
|
};
|
2020-11-01 20:21:27 +01:00
|
|
|
|
2020-12-03 12:48:07 +01:00
|
|
|
children = mkOption {
|
|
|
|
type = with types;
|
|
|
|
attrsOf (submodule {
|
|
|
|
options = {
|
|
|
|
inherit coreROMs inputs;
|
|
|
|
configFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
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-10 19:22:45 +01:00
|
|
|
default = { };
|
2020-11-01 20:21:27 +01:00
|
|
|
description = "Attr set of initial ROM modules";
|
|
|
|
};
|
|
|
|
|
2020-12-10 19:22:45 +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.";
|
|
|
|
};
|
|
|
|
|
2020-12-03 12:48:07 +01:00
|
|
|
storeBackend = mkOption {
|
|
|
|
type = types.enum [ "tarball" "usb" ]; # "parent"?
|
|
|
|
default = "tarball";
|
|
|
|
description = ''
|
|
|
|
Backend for the initial /nix/store file-system.
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>tarball</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
An in-memory tarball.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>usb</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
An EXT2 file-system backed by USB storage.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
</variablelist>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
storePaths = mkOption {
|
|
|
|
type = with types; listOf package;
|
|
|
|
description = ''
|
|
|
|
Derivations to be included in the Nix store in the generated boot image.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = let
|
|
|
|
|
|
|
|
addManifest = drv:
|
|
|
|
drv // {
|
|
|
|
manifest =
|
|
|
|
localPackages.runCommand "${drv.name}.dhall" { inherit drv; } ''
|
|
|
|
set -eu
|
|
|
|
echo -n '[' >> $out
|
|
|
|
find $drv/ -type f -printf ',{mapKey= "%f",mapValue="%p"}' >> $out
|
|
|
|
${if builtins.elem "lib" drv.outputs then
|
|
|
|
''
|
|
|
|
find ${drv.lib}/ -type f -printf ',{mapKey= "%f",mapValue="%p"}' >> $out''
|
|
|
|
else
|
|
|
|
""}
|
|
|
|
echo -n ']' >> $out
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
mergeManifests = inputs:
|
2020-12-10 19:22:45 +01:00
|
|
|
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";
|
|
|
|
in (foldl' f "[" inputs) + "]";
|
2020-11-01 20:21:27 +01:00
|
|
|
|
2020-11-10 15:49:12 +01:00
|
|
|
romDirectories = filterAttrs (_: value: value != null) (mapAttrs
|
|
|
|
(name: value:
|
|
|
|
if value.inputs == [ ] then
|
|
|
|
null
|
|
|
|
else
|
|
|
|
pkgs.symlinkJoin {
|
|
|
|
name = "${name}-rom";
|
|
|
|
paths = value.inputs;
|
|
|
|
}) config.genode.init.children);
|
2020-11-03 19:21:10 +01:00
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
in {
|
|
|
|
|
|
|
|
assertions = [{
|
|
|
|
assertion = builtins.any (s: s == config.nixpkgs.system)
|
|
|
|
config.genode.core.supportedSystems;
|
|
|
|
message = "invalid Genode core for this system";
|
|
|
|
}];
|
|
|
|
|
2020-12-10 19:22:45 +01:00
|
|
|
genode.core.basePackages =
|
|
|
|
lib.optional (config.genode.boot.storeBackend == "usb")
|
|
|
|
pkgs.genodePackages.part_block;
|
|
|
|
|
|
|
|
genode.core.children =
|
|
|
|
# Component to steer the store_fs to a specific partition
|
|
|
|
(if config.genode.boot.storeBackend == "usb" then {
|
|
|
|
part_block.configFile = builtins.toFile "part_block.dhall" ''
|
|
|
|
let Genode = env:DHALL_GENODE
|
|
|
|
|
|
|
|
let Init = Genode.Init
|
|
|
|
|
|
|
|
in Init.Child.flat
|
|
|
|
Init.Child.Attributes::{
|
|
|
|
, binary = "part_block"
|
|
|
|
, resources = Init.Resources::{ ram = Genode.units.MiB 8 }
|
|
|
|
, config = Init.Config::{
|
|
|
|
, attributes = toMap { ignore_mbr = "yes" }
|
|
|
|
, policies =
|
|
|
|
[ Init.Config.Policy::{
|
|
|
|
, service = "Block"
|
|
|
|
, label = Init.LabelSelector.prefix "store_fs"
|
|
|
|
, attributes = toMap
|
|
|
|
{ partition = "1"
|
|
|
|
, writeable = "yes"
|
|
|
|
, TODO = "select by partition UUID"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2020-12-03 12:48:07 +01:00
|
|
|
}
|
2020-12-10 19:22:45 +01:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
} else
|
|
|
|
{ }) // {
|
|
|
|
store_fs.configFile = let
|
|
|
|
|
|
|
|
storeVfsConfig = {
|
|
|
|
tarball = ''
|
|
|
|
VFS.vfs [ VFS.leafAttrs "tar" (toMap { name = "${config.system.build.tarball.fileName}.tar" }) ]
|
|
|
|
'';
|
|
|
|
usb = ''
|
|
|
|
VFS.vfs [ VFS.leafAttrs "rump" (toMap { fs = "ext2fs", ram="12M" }) ]
|
|
|
|
'';
|
|
|
|
}.${config.genode.boot.storeBackend};
|
|
|
|
|
|
|
|
storeResources = {
|
|
|
|
tarball = "Init.Resources.default";
|
|
|
|
usb = "Init.Resources::{ caps = 256, ram = Genode.units.MiB 16 }";
|
|
|
|
}.${config.genode.boot.storeBackend};
|
|
|
|
|
|
|
|
in builtins.toFile "store_fs.dhall" ''
|
|
|
|
let Genode = env:DHALL_GENODE
|
|
|
|
|
|
|
|
let Init = Genode.Init
|
|
|
|
|
|
|
|
let VFS = Genode.VFS
|
|
|
|
|
|
|
|
in Init.Child.flat
|
|
|
|
Init.Child.Attributes::{
|
|
|
|
, binary = "vfs"
|
|
|
|
, resources = ${storeResources}
|
|
|
|
, config = Init.Config::{
|
|
|
|
, content = [ ${storeVfsConfig} ]
|
|
|
|
, policies =
|
|
|
|
[ Init.Config.Policy::{
|
|
|
|
, service = "File_system"
|
|
|
|
, label = Init.LabelSelector.suffix "nix-store"
|
|
|
|
, attributes = toMap { root = "/nix/store" }
|
|
|
|
}
|
|
|
|
, Init.Config.Policy::{
|
|
|
|
, service = "File_system"
|
|
|
|
, label = Init.LabelSelector.prefix "store_rom"
|
|
|
|
, attributes = toMap { root = "/" }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2020-12-03 12:48:07 +01:00
|
|
|
}
|
2020-12-10 19:22:45 +01:00
|
|
|
'';
|
|
|
|
};
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
genode.boot.configFile = let
|
|
|
|
tarball =
|
|
|
|
"${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar";
|
2020-12-03 12:48:07 +01:00
|
|
|
|
|
|
|
storeBackendInputs = {
|
|
|
|
tarball = [ config.system.build.tarball ];
|
|
|
|
usb = [ pkgs.genodePackages.rump ];
|
|
|
|
}.${config.genode.boot.storeBackend};
|
|
|
|
|
2020-12-10 19:22:45 +01:00
|
|
|
coreInputs = with builtins;
|
|
|
|
concatMap (getAttr "inputs") (attrValues config.genode.core.children);
|
|
|
|
|
|
|
|
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;
|
|
|
|
config.genode.core.basePackages ++ storeBackendInputs
|
|
|
|
++ [ init cached_fs_rom jitter_sponge report_rom vfs ]
|
|
|
|
++ coreInputs)) + ''# [ { mapKey = "romModules", mapValue = [ ''
|
|
|
|
+ (toString
|
|
|
|
(mapAttrsToList (k: v: '', { mapKey = "${k}", mapValue = "${v}" }'')
|
|
|
|
config.genode.boot.romModules)) + " ] } ]");
|
2020-11-10 15:49:12 +01:00
|
|
|
|
|
|
|
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 =
|
|
|
|
Genode.Init.LabelSelector.Type.Partial
|
|
|
|
{ prefix = Some "nixos -> ${name}", suffix = Some "${suffix}" }
|
|
|
|
}
|
2020-12-10 19:22:45 +01:00
|
|
|
, route = Genode.Init.Route.parentLabel "${suffix}"
|
2020-11-10 15:49:12 +01:00
|
|
|
}
|
|
|
|
'') value.coreROMs) config.genode.init.children));
|
|
|
|
|
2020-12-03 12:48:07 +01:00
|
|
|
extraCoreChildren = "[ ${
|
|
|
|
toString (lib.mapAttrsToList (name: value:
|
|
|
|
'', { mapKey = "${name}", mapValue = ${value.configFile} }'')
|
|
|
|
config.genode.core.children)
|
|
|
|
} ]";
|
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
in localPackages.runCommand "boot.dhall" { } ''
|
|
|
|
cat > $out << EOF
|
2020-11-10 15:49:12 +01:00
|
|
|
let Genode = env:DHALL_GENODE in
|
2020-12-03 12:48:07 +01:00
|
|
|
let VFS = Genode.VFS
|
|
|
|
let XML = Genode.Prelude.XML
|
|
|
|
in
|
2020-11-01 20:21:27 +01:00
|
|
|
${./store-wrapper.dhall}
|
2020-12-03 12:48:07 +01:00
|
|
|
{ extraCoreChildren = ${extraCoreChildren}
|
|
|
|
, subinit = ${config.genode.init.configFile}
|
|
|
|
, storeSize = $(stat --format '%s' ${tarball})
|
|
|
|
, storeRomPolicies = [${
|
|
|
|
toString storeRomPolicies
|
|
|
|
} ] : Genode.Prelude.Map.Type Text Text
|
|
|
|
, routes = [${extraRoutes} ] : List Genode.Init.ServiceRoute.Type
|
|
|
|
, bootManifest = ${manifest}
|
|
|
|
}
|
2020-11-01 20:21:27 +01:00
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
|
2020-12-10 19:22:45 +01:00
|
|
|
genode.boot.storePaths = with builtins;
|
|
|
|
[ config.genode.init.configFile ] ++ (attrValues romDirectories);
|
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" {
|
|
|
|
contents = [ ];
|
2020-11-07 13:58:14 +01:00
|
|
|
storeContents = let
|
|
|
|
romDirs = mapAttrsToList (name: object: {
|
|
|
|
symlink = "rom/${name}";
|
|
|
|
inherit object;
|
|
|
|
}) romDirectories;
|
|
|
|
configFiles = mapAttrsToList (name: child: {
|
|
|
|
symlink = "config/${name}.dhall";
|
|
|
|
object = child.configFile;
|
|
|
|
}) config.genode.init.children;
|
|
|
|
in romDirs ++ configFiles;
|
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 ];
|
2020-11-01 20:21:27 +01:00
|
|
|
DHALL_GENODE = "${pkgs.genodePackages.dhallGenode}/binary.dhall";
|
|
|
|
} ''
|
|
|
|
export XDG_CACHE_HOME=$NIX_BUILD_TOP
|
|
|
|
lndir -silent \
|
|
|
|
${pkgs.genodePackages.dhallGenode}/.cache \
|
|
|
|
$XDG_CACHE_HOME
|
2020-11-03 19:21:10 +01:00
|
|
|
dhall text <<< "(env:DHALL_GENODE).Init.render (${config.genode.boot.configFile}).config" > $out
|
2020-11-07 18:46:35 +01:00
|
|
|
xmllint --noout $out
|
2020-11-01 20:21:27 +01:00
|
|
|
'';
|
|
|
|
|
2020-12-03 12:48:07 +01:00
|
|
|
system.build.bootDriveImage = let
|
2020-12-10 19:22:45 +01:00
|
|
|
espImage = import ./lib/make-esp-fs.nix { inherit config pkgs; };
|
|
|
|
storeFsImage =
|
|
|
|
pkgs.callPackage ./lib/make-ext2-fs.nix { inherit config pkgs; };
|
|
|
|
bootDriveImage = import ./lib/make-bootable-image.nix {
|
|
|
|
inherit config pkgs espImage storeFsImage;
|
2020-12-03 12:48:07 +01:00
|
|
|
};
|
2020-12-10 19:22:45 +01:00
|
|
|
in bootDriveImage;
|
|
|
|
|
|
|
|
# virtualisation.useEFIBoot = config.genode.boot.storeBackend == "usb";
|
2020-12-03 12:48:07 +01:00
|
|
|
|
|
|
|
virtualisation.qemu.options =
|
|
|
|
lib.optionals (config.genode.boot.storeBackend == "usb") [
|
2020-12-10 19:22:45 +01:00
|
|
|
"-bios ${pkgs.buildPackages.OVMF.fd}/FV/OVMF.fd"
|
2020-12-03 12:48:07 +01:00
|
|
|
"-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly"
|
2020-12-10 19:22:45 +01:00
|
|
|
"-usb"
|
2020-12-03 12:48:07 +01:00
|
|
|
"-device usb-storage,drive=usbdisk"
|
|
|
|
];
|
|
|
|
|
2020-11-01 20:21:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|