2
0
Fork 0

Boot from USB

This commit is contained in:
Ehmry - 2020-12-10 19:22:45 +01:00
parent 16f62030f4
commit 517080b3dd
1 changed files with 134 additions and 79 deletions

View File

@ -25,14 +25,22 @@ in {
prefix = mkOption { prefix = mkOption {
type = types.str; type = types.str;
example = "hw-pc-"; example = "hw-pc-";
description = "String prefix signifying the Genode core in use.";
}; };
supportedSystems = mkOption { supportedSystems = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
example = [ "i686-genode" "x86_64-genode" ]; example = [ "i686-genode" "x86_64-genode" ];
description = "Hardware supported by this core.";
}; };
basePackages = mkOption { type = types.listOf types.package; }; 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>.
'';
};
children = mkOption { children = mkOption {
type = with types; type = with types;
@ -57,17 +65,6 @@ in {
boot = { 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 { configFile = mkOption {
type = types.path; type = types.path;
description = '' description = ''
@ -87,6 +84,18 @@ in {
description = "Attr set of initial ROM modules"; description = "Attr set of initial ROM modules";
}; };
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 { storeBackend = mkOption {
type = types.enum [ "tarball" "usb" ]; # "parent"? type = types.enum [ "tarball" "usb" ]; # "parent"?
default = "tarball"; default = "tarball";
@ -119,7 +128,6 @@ in {
storePaths = mkOption { storePaths = mkOption {
type = with types; listOf package; type = with types; listOf package;
example = literalExample "[ pkgs.genodePackages.vfs_lwp ]";
description = '' description = ''
Derivations to be included in the Nix store in the generated boot image. Derivations to be included in the Nix store in the generated boot image.
''; '';
@ -148,20 +156,17 @@ in {
}; };
mergeManifests = inputs: mergeManifests = inputs:
localPackages.writeTextFile { with builtins;
name = "manifest.dhall"; let
text = with builtins; f = head: input:
let if hasAttr "manifest" input then
f = head: input: ''
if hasAttr "manifest" input then ${head}, { mapKey = "${
'' lib.getName input
${head}, { mapKey = "${ }", mapValue = ${input.manifest} }''
lib.getName input else
}", mapValue = ${input.manifest} }'' abort "${input.pname} does not have a manifest";
else in (foldl' f "[" inputs) + "]";
abort "${input.pname} does not have a manifest";
in (foldl' f "[" inputs) + "]";
};
romDirectories = filterAttrs (_: value: value != null) (mapAttrs romDirectories = filterAttrs (_: value: value != null) (mapAttrs
(name: value: (name: value:
@ -181,51 +186,85 @@ in {
message = "invalid Genode core for this system"; message = "invalid Genode core for this system";
}]; }];
genode.core.children.store_fs.configFile = let genode.core.basePackages =
lib.optional (config.genode.boot.storeBackend == "usb")
pkgs.genodePackages.part_block;
storeVfsConfig = { genode.core.children =
tarball = '' # Component to steer the store_fs to a specific partition
VFS.vfs [ VFS.leafAttrs "tar" (toMap { name = "${config.system.build.tarball.fileName}.tar" }) ] (if config.genode.boot.storeBackend == "usb" then {
''; part_block.configFile = builtins.toFile "part_block.dhall" ''
usb = '' let Genode = env:DHALL_GENODE
VFS.vfs [ VFS.leafAttrs "rump" (toMap { fs = "ext2fs", ram="12M" }) ]
'';
}.${config.genode.boot.storeBackend};
storeResources = { let Init = Genode.Init
tarball = "Init.Resources.default";
usb = "Init.Resources::{ caps = 256, ram = Genode.units.MiB 16 }";
}.${config.genode.boot.storeBackend};
in builtins.toFile "store_fs.dhall" '' in Init.Child.flat
let Genode = env:DHALL_GENODE Init.Child.Attributes::{
, binary = "part_block"
let Init = Genode.Init , resources = Init.Resources::{ ram = Genode.units.MiB 8 }
, config = Init.Config::{
let VFS = Genode.VFS , attributes = toMap { ignore_mbr = "yes" }
, policies =
in Init.Child.flat [ Init.Config.Policy::{
Init.Child.Attributes::{ , service = "Block"
, binary = "vfs" , label = Init.LabelSelector.prefix "store_fs"
, resources = ${storeResources} , attributes = toMap
, config = Init.Config::{ { partition = "1"
, content = [ ${storeVfsConfig} ] , writeable = "yes"
, policies = , TODO = "select by partition UUID"
[ 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" } else
, attributes = toMap { root = "/" } { }) // {
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 = "/" }
}
]
}
} }
] '';
} };
, provides = [ "File_system" ]
}
'';
genode.boot.configFile = let genode.boot.configFile = let
tarball = tarball =
@ -236,9 +275,21 @@ in {
usb = [ pkgs.genodePackages.rump ]; usb = [ pkgs.genodePackages.rump ];
}.${config.genode.boot.storeBackend}; }.${config.genode.boot.storeBackend};
manifest = mergeManifests (map addManifest (with pkgs.genodePackages; coreInputs = with builtins;
config.genode.core.basePackages ++ storeBackendInputs concatMap (getAttr "inputs") (attrValues config.genode.core.children);
++ [ init cached_fs_rom jitter_sponge report_rom vfs ]));
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)) + " ] } ]");
storeRomPolicies = mapAttrsToList storeRomPolicies = mapAttrsToList
(name: value: '', { mapKey = "${name}", mapValue = "${value}" }'') (name: value: '', { mapKey = "${name}", mapValue = "${value}" }'')
@ -253,7 +304,7 @@ in {
Genode.Init.LabelSelector.Type.Partial Genode.Init.LabelSelector.Type.Partial
{ prefix = Some "nixos -> ${name}", suffix = Some "${suffix}" } { prefix = Some "nixos -> ${name}", suffix = Some "${suffix}" }
} }
, route = Genode.Init.Route.parent (Some "${suffix}") , route = Genode.Init.Route.parentLabel "${suffix}"
} }
'') value.coreROMs) config.genode.init.children)); '') value.coreROMs) config.genode.init.children));
@ -282,8 +333,8 @@ in {
EOF EOF
''; '';
genode.boot.storePaths = [ config.genode.init.configFile ] genode.boot.storePaths = with builtins;
++ (builtins.attrValues romDirectories); [ config.genode.init.configFile ] ++ (attrValues romDirectories);
# Create the tarball of the store to live in core ROM # Create the tarball of the store to live in core ROM
system.build.tarball = system.build.tarball =
@ -316,17 +367,21 @@ in {
''; '';
system.build.bootDriveImage = let system.build.bootDriveImage = let
storeFsImage = pkgs.callPackage ./lib/make-ext2-fs.nix { espImage = import ./lib/make-esp-fs.nix { inherit config pkgs; };
inherit (config.genode.boot) storePaths; storeFsImage =
inherit (config.system.build) qemu; pkgs.callPackage ./lib/make-ext2-fs.nix { inherit config pkgs; };
volumeLabel = "NIXOS_GENODE"; bootDriveImage = import ./lib/make-bootable-image.nix {
inherit config pkgs espImage storeFsImage;
}; };
in storeFsImage; in bootDriveImage;
# virtualisation.useEFIBoot = config.genode.boot.storeBackend == "usb";
virtualisation.qemu.options = virtualisation.qemu.options =
lib.optionals (config.genode.boot.storeBackend == "usb") [ lib.optionals (config.genode.boot.storeBackend == "usb") [
"-usb" "-bios ${pkgs.buildPackages.OVMF.fd}/FV/OVMF.fd"
"-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly" "-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly"
"-usb"
"-device usb-storage,drive=usbdisk" "-device usb-storage,drive=usbdisk"
]; ];