2020-11-01 20:21:27 +01:00
|
|
|
{ config, pkgs, lib, modulesPath, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let localPackages = pkgs.buildPackages;
|
|
|
|
in {
|
|
|
|
options.genode = {
|
|
|
|
core = {
|
|
|
|
|
|
|
|
prefix = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "hw-pc-";
|
|
|
|
};
|
|
|
|
|
|
|
|
supportedSystems = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
example = [ "i686-genode" "x86_64-genode" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
basePackages = mkOption { type = types.listOf types.package; };
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
boot = {
|
|
|
|
|
|
|
|
kernel = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "${pkgs.genodePackages.bender}/bender";
|
|
|
|
};
|
|
|
|
|
|
|
|
initrd = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "${pkgs.genodePackages.bender}/bender";
|
|
|
|
description = "Path to an image or a command-line arguments";
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
description = "Attr set of initial ROM modules";
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
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:
|
|
|
|
localPackages.writeTextFile {
|
|
|
|
name = "manifest.dhall";
|
|
|
|
text = 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-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";
|
|
|
|
}];
|
|
|
|
|
|
|
|
genode.boot.configFile = let
|
|
|
|
tarball =
|
|
|
|
"${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar";
|
|
|
|
manifest = mergeManifests (map addManifest
|
|
|
|
(config.genode.core.basePackages ++ [ config.system.build.tarball ]
|
2020-11-03 19:21:10 +01:00
|
|
|
++ (with pkgs.genodePackages; [
|
|
|
|
init
|
|
|
|
cached_fs_rom
|
2020-12-02 19:25:07 +01:00
|
|
|
jitter_sponge
|
2020-11-03 19:21:10 +01:00
|
|
|
report_rom
|
|
|
|
vfs
|
|
|
|
])));
|
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}" }
|
|
|
|
}
|
|
|
|
, route = Genode.Init.Route.parent (Some "${suffix}")
|
|
|
|
}
|
|
|
|
'') value.coreROMs) config.genode.init.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-11-01 20:21:27 +01:00
|
|
|
${./store-wrapper.dhall}
|
|
|
|
(${config.genode.init.configFile})
|
|
|
|
"${config.system.build.tarball.fileName}.tar"
|
|
|
|
$(stat --format '%s' ${tarball})
|
2020-11-10 15:49:12 +01:00
|
|
|
([${toString storeRomPolicies} ] : Genode.Prelude.Map.Type Text Text)
|
|
|
|
([${extraRoutes} ] : List Genode.Init.ServiceRoute.Type)
|
2020-11-03 19:21:10 +01:00
|
|
|
${manifest}
|
2020-11-01 20:21:27 +01:00
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
|
|
|
|
# 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
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|