nixos: config.genode.boot.storeBackend is "fs" or "memory"

Make the config.genode.boot.storeBackend option a choice between
a traditional file-system or memory-backed file-system image. Fix
GRUB booting when using a file-system store.

The nova-ahci test shows that this is working.
This commit is contained in:
Ehmry - 2021-02-01 13:32:05 +01:00
parent 6f9f1b7069
commit 8c0c7d55c4
6 changed files with 40 additions and 48 deletions

View File

@ -7,7 +7,7 @@ with lib; {
device = lib.mkOption { type = types.int; }; device = lib.mkOption { type = types.int; };
driver = lib.mkOption { type = types.enum [ "ahci" ]; }; driver = lib.mkOption { type = types.enum [ "ahci" "usb" ]; };
partition = lib.mkOption { type = types.ints.positive; }; partition = lib.mkOption { type = types.ints.positive; };
@ -24,6 +24,9 @@ with lib; {
hardware.genode.ahci.enable = hardware.genode.ahci.enable =
any (fs: fs.block.driver == "ahci") (attrValues config.fileSystems); any (fs: fs.block.driver == "ahci") (attrValues config.fileSystems);
hardware.genode.usb.storage.enable =
any (fs: fs.block.driver == "usb") (attrValues config.fileSystems);
}; };
} }

View File

@ -98,40 +98,28 @@ in {
}; };
storeBackend = mkOption { storeBackend = mkOption {
type = types.enum [ "ahci" "tarball" "usb" ]; # "parent"? type = types.enum [ "fs" "memory" ]; # "parent"?
default = "tarball"; default = "memory";
description = '' description = ''
Backend for the initial /nix/store file-system. Backend for the initial /nix/store file-system.
<variablelist> <variablelist>
<varlistentry> <varlistentry>
<term><literal>ahci</literal></term> <term>
<literal>fs</literal>
</term>
<listitem> <listitem>
<para> <para>Store backed by a File_system session.</para>
An EXT2 file-system backed by SATA storage.
</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><literal>tarball</literal></term> <term>
<literal>tarball</literal>
</term>
<listitem> <listitem>
<para> <para>An in-memory tarball.</para>
An in-memory tarball.
</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><literal>usb</literal></term>
<listitem>
<para>
An EXT2 file-system backed by USB storage.
</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
''; '';
}; };
@ -198,12 +186,12 @@ in {
}]; }];
genode.core.basePackages = genode.core.basePackages =
lib.optional (config.genode.boot.storeBackend != "tarball") lib.optional (config.genode.boot.storeBackend != "memory")
pkgs.genodePackages.part_block; pkgs.genodePackages.part_block;
genode.core.children = genode.core.children =
# Component to steer the store_fs to a specific partition # Component to steer the store_fs to a specific partition
(if config.genode.boot.storeBackend != "tarball" then { (if config.genode.boot.storeBackend != "memory" then {
part_block.configFile = builtins.toFile "part_block.dhall" '' part_block.configFile = builtins.toFile "part_block.dhall" ''
let Genode = env:DHALL_GENODE let Genode = env:DHALL_GENODE
@ -236,7 +224,7 @@ in {
store_fs.configFile = let store_fs.configFile = let
storeVfsConfig = storeVfsConfig =
if config.genode.boot.storeBackend == "tarball" then '' if config.genode.boot.storeBackend == "memory" then ''
VFS.vfs [ VFS.leafAttrs "tar" (toMap { name = "${config.system.build.tarball.fileName}.tar" }) ] VFS.vfs [ VFS.leafAttrs "tar" (toMap { name = "${config.system.build.tarball.fileName}.tar" }) ]
'' else '' else
let let
@ -252,9 +240,8 @@ in {
rumpExt2 = rumpExt2 =
"Init.Resources::{ caps = 256, ram = Genode.units.MiB 16 }"; "Init.Resources::{ caps = 256, ram = Genode.units.MiB 16 }";
in { in {
ahci = rumpExt2; fs = rumpExt2;
tarball = "Init.Resources.default"; memory = "Init.Resources.default";
usb = rumpExt2;
}.${config.genode.boot.storeBackend}; }.${config.genode.boot.storeBackend};
persistencePolicies = lib.mapAttrsToList (name: _: '' persistencePolicies = lib.mapAttrsToList (name: _: ''
@ -316,9 +303,8 @@ in {
"${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar"; "${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar";
storeBackendInputs = { storeBackendInputs = {
ahci = [ pkgs.genodePackages.rump ]; fs = [ pkgs.genodePackages.rump ];
tarball = [ config.system.build.tarball ]; memory = [ config.system.build.tarball ];
usb = [ pkgs.genodePackages.rump ];
}.${config.genode.boot.storeBackend}; }.${config.genode.boot.storeBackend};
coreInputs = with builtins; coreInputs = with builtins;
@ -422,19 +408,15 @@ in {
bootDriveImage = import ./lib/make-bootable-image.nix { bootDriveImage = import ./lib/make-bootable-image.nix {
inherit config pkgs espImage storeFsImage; inherit config pkgs espImage storeFsImage;
}; };
in lib.mkIf (config.genode.boot.storeBackend != "tarball") bootDriveImage; in lib.mkIf (config.genode.boot.storeBackend != "memory") bootDriveImage;
virtualisation.useBootLoader = config.genode.boot.storeBackend != "tarball"; virtualisation.useBootLoader = config.genode.boot.storeBackend != "memory";
virtualisation.qemu.options = virtualisation.qemu.options =
let blockCommon = [ "-bios ${pkgs.buildPackages.OVMF.fd}/FV/OVMF.fd" ]; let blockCommon = [ "-bios ${pkgs.buildPackages.OVMF.fd}/FV/OVMF.fd" ];
in { in {
tarball = [ ]; fs = blockCommon;
ahci = blockCommon; memory = [ ];
usb = blockCommon ++ [
"-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly"
"-device usb-storage,drive=usbdisk"
];
}.${config.genode.boot.storeBackend}; }.${config.genode.boot.storeBackend};
}; };

View File

@ -18,9 +18,6 @@ with lib;
config = let cfg = config.hardware.genode.usb; config = let cfg = config.hardware.genode.usb;
in { in {
hardware.genode.usb.storage.enable = config.genode.boot.storeBackend
== "usb";
hardware.genode.usb.enable = cfg.storage.enable; hardware.genode.usb.enable = cfg.storage.enable;
hardware.genode.platform.policies = lib.optional cfg.enable hardware.genode.platform.policies = lib.optional cfg.enable
@ -118,7 +115,10 @@ with lib;
virtualisation.qemu.options = lib.optional cfg.enable virtualisation.qemu.options = lib.optional cfg.enable
(lib.optional (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) "-usb" (lib.optional (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) "-usb"
++ lib.optional (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64) ++ lib.optional (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64)
"-device usb-ehci,id=usb0"); "-device usb-ehci,id=usb0") ++ lib.optional cfg.storage.enable [
"-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly"
"-device usb-storage,drive=usbdisk"
];
}; };

View File

@ -23,6 +23,12 @@ in pkgs.stdenv.mkDerivation {
# Create nix/store before copying path # Create nix/store before copying path
mkdir -p ./rootImage/boot/grub ./rootImage/nix/store mkdir -p ./rootImage/boot/grub ./rootImage/nix/store
cat > extraPrepareConfig.sh <<< '${config.boot.loader.grub.extraPrepareConfig}'
substituteInPlace extraPrepareConfig.sh \
--replace '${pkgs.coreutils}' '${pkgs.buildPackages.coreutils}' \
--replace '@bootPath@' './rootImage/boot'
source extraPrepareConfig.sh
cat <<EOF > ./rootImage/boot/grub/grub.cfg cat <<EOF > ./rootImage/boot/grub/grub.cfg
set timeout=3 set timeout=3
set default=0 set default=0

View File

@ -31,7 +31,7 @@ in {
}; };
genode.boot.storePaths = genode.boot.storePaths =
lib.optional (config.genode.boot.storeBackend != "tarball") bootDir; lib.optional (config.genode.boot.storeBackend != "memory") bootDir;
virtualisation.qemu.options = virtualisation.qemu.options =
lib.optionals (!config.virtualisation.useBootLoader) [ lib.optionals (!config.virtualisation.useBootLoader) [
@ -52,9 +52,9 @@ in {
menuentry 'Genode on NOVA' { menuentry 'Genode on NOVA' {
insmod multiboot2 insmod multiboot2
insmod gzio insmod gzio
multiboot2 /bender.gz serial_fallback multiboot2 /boot/bender.gz serial_fallback
module2 /hypervisor.gz hypervisor iommu logmem novga novpid serial module2 /boot/hypervisor.gz hypervisor iommu logmem novga novpid serial
module2 /image.elf.gz image.elf module2 /boot/image.elf.gz image.elf
} }
''; '';
extraFiles = { extraFiles = {

View File

@ -6,6 +6,7 @@
device = 0; device = 0;
partition = 1; partition = 1;
}; };
genode.boot.storeBackend = "fs";
genode.init.children.hello = { genode.init.children.hello = {
inputs = [ pkgs.hello pkgs.genodePackages.vfs.lib ]; inputs = [ pkgs.hello pkgs.genodePackages.vfs.lib ];
configFile = pkgs.writeText "ahci-hello.child.dhall" '' configFile = pkgs.writeText "ahci-hello.child.dhall" ''