nixos: boot from AHCI

This commit is contained in:
Ehmry - 2020-12-30 21:07:30 +01:00
parent 28859b57fd
commit 07645a3930
9 changed files with 179 additions and 321 deletions

View File

@ -98,13 +98,22 @@ in {
}; };
storeBackend = mkOption { storeBackend = mkOption {
type = types.enum [ "tarball" "usb" ]; # "parent"? type = types.enum [ "ahci" "tarball" "usb" ]; # "parent"?
default = "tarball"; default = "tarball";
description = '' description = ''
Backend for the initial /nix/store file-system. Backend for the initial /nix/store file-system.
<variablelist> <variablelist>
<varlistentry>
<term><literal>ahci</literal></term>
<listitem>
<para>
An EXT2 file-system backed by SATA storage.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><literal>tarball</literal></term> <term><literal>tarball</literal></term>
<listitem> <listitem>
@ -188,12 +197,12 @@ in {
}]; }];
genode.core.basePackages = genode.core.basePackages =
lib.optional (config.genode.boot.storeBackend == "usb") lib.optional (config.genode.boot.storeBackend != "tarball")
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 == "usb" then { (if config.genode.boot.storeBackend != "tarball" 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
@ -223,18 +232,25 @@ in {
{ }) // { { }) // {
store_fs.configFile = let store_fs.configFile = let
storeVfsConfig = { storeVfsConfig = let
rumpExt2 = ''
VFS.vfs [ VFS.leafAttrs "rump" (toMap { fs = "ext2fs", ram="12M" }) ]
'';
in {
ahci = rumpExt2;
tarball = '' tarball = ''
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" }) ]
''; '';
usb = '' usb = rumpExt2;
VFS.vfs [ VFS.leafAttrs "rump" (toMap { fs = "ext2fs", ram="12M" }) ]
'';
}.${config.genode.boot.storeBackend}; }.${config.genode.boot.storeBackend};
storeResources = { storeResources = let
rumpExt2 =
"Init.Resources::{ caps = 256, ram = Genode.units.MiB 16 }";
in {
ahci = rumpExt2;
tarball = "Init.Resources.default"; tarball = "Init.Resources.default";
usb = "Init.Resources::{ caps = 256, ram = Genode.units.MiB 16 }"; usb = rumpExt2;
}.${config.genode.boot.storeBackend}; }.${config.genode.boot.storeBackend};
in builtins.toFile "store_fs.dhall" '' in builtins.toFile "store_fs.dhall" ''
@ -273,6 +289,7 @@ 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 ];
tarball = [ config.system.build.tarball ]; tarball = [ config.system.build.tarball ];
usb = [ pkgs.genodePackages.rump ]; usb = [ pkgs.genodePackages.rump ];
}.${config.genode.boot.storeBackend}; }.${config.genode.boot.storeBackend};
@ -371,24 +388,27 @@ in {
xmllint --noout $out xmllint --noout $out
''; '';
system.build.bootDriveImage = let virtualisation.diskImage = let
espImage = import ./lib/make-esp-fs.nix { inherit config pkgs; }; espImage = import ./lib/make-esp-fs.nix { inherit config pkgs; };
storeFsImage = storeFsImage =
pkgs.callPackage ./lib/make-ext2-fs.nix { inherit config pkgs; }; pkgs.callPackage ./lib/make-ext2-fs.nix { inherit config pkgs; };
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 bootDriveImage; in lib.mkIf (config.genode.boot.storeBackend != "tarball") bootDriveImage;
# virtualisation.useEFIBoot = config.genode.boot.storeBackend == "usb"; virtualisation.useBootLoader = config.genode.boot.storeBackend != "tarball";
virtualisation.qemu.options = virtualisation.qemu.options =
lib.optionals (config.genode.boot.storeBackend == "usb") [ let blockCommon = [ "-bios ${pkgs.buildPackages.OVMF.fd}/FV/OVMF.fd" ];
"-bios ${pkgs.buildPackages.OVMF.fd}/FV/OVMF.fd" in {
"-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly" tarball = [ ];
"-usb" ahci = blockCommon;
"-device usb-storage,drive=usbdisk" usb = blockCommon ++ [
]; "-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly"
"-device usb-storage,drive=usbdisk"
];
}.${config.genode.boot.storeBackend};
}; };

View File

@ -0,0 +1,65 @@
{ config, pkgs, lib, ... }:
with lib;
{
options.hardware.genode.ahci = {
enable = lib.mkEnableOption "AHCI (SATA) block driver";
};
config = let cfg = config.hardware.genode.ahci;
in {
hardware.genode.ahci.enable = config.genode.boot.storeBackend == "ahci";
hardware.genode.platform.policies = lib.optional cfg.enable
(builtins.toFile ("ahci.platform-policy.dhall") ''
let Genode = env:DHALL_GENODE
in Genode.Init.Config.Policy::{
, service = "Platform"
, label = Genode.Init.LabelSelector.prefix "ahci_drv"
, content =
[ Genode.Prelude.XML.leaf
{ name = "pci", attributes = toMap { class = "AHCI" } }
]
}
'');
genode.core.children.ahci_drv = lib.mkIf cfg.enable {
inputs = [ pkgs.genodePackages.ahci_drv ];
configFile = pkgs.writeText "ahci_drv.dhall" ''
let Genode = env:DHALL_GENODE
let Init = Genode.Init
in Init.Child.flat
Init.Child.Attributes::{
, binary = "ahci_drv"
, resources = Init.Resources::{
, caps = 400
, ram = Genode.units.MiB 10
, constrainPhys = True
}
, romReports = [ { local = "ports", route = "ahci_ports" } ]
, routes =
[ Init.ServiceRoute.parent "IRQ"
, Init.ServiceRoute.parent "IO_MEM"
, Init.ServiceRoute.parent "IO_PORT"
]
, config = Init.Config::{
, policies =
[ Init.Config.Policy::{
, service = "Block"
, label = Init.LabelSelector.prefix "part_block"
, attributes = toMap { device = "0", writeable = "yes" }
}
]
}
}
'';
};
};
}

View File

@ -3,7 +3,7 @@
with lib; with lib;
{ {
imports = [ ./framebuffer.nix ./nic.nix ./usb.nix ]; imports = [ ./ahci.nix ./framebuffer.nix ./nic.nix ./usb.nix ];
options.hardware.genode.platform.policies = lib.mkOption { options.hardware.genode.platform.policies = lib.mkOption {
type = with types; listOf path; type = with types; listOf path;
@ -21,7 +21,7 @@ with lib;
platform_drv platform_drv
]; ];
genode.init.children.acpi_drv = { genode.core.children.acpi_drv = {
coreROMs = [ "acpi_drv" ]; coreROMs = [ "acpi_drv" ];
configFile = pkgs.writeText "acpi_drv.dhall" '' configFile = pkgs.writeText "acpi_drv.dhall" ''
let Genode = env:DHALL_GENODE let Genode = env:DHALL_GENODE
@ -48,7 +48,7 @@ with lib;
''; '';
}; };
genode.init.children.platform_drv = { genode.core.children.platform_drv = {
coreROMs = [ "platform_drv" ]; coreROMs = [ "platform_drv" ];
configFile = let configFile = let
policies = policies =

View File

@ -64,6 +64,6 @@ pkgs.stdenv.mkDerivation {
start=$espSectorOffset, type=$efiUuid start=$espSectorOffset, type=$efiUuid
EOF EOF
qemu-img convert $img $out qemu-img convert -f raw -O qcow2 $img $out
''; '';
} }

View File

@ -31,7 +31,7 @@ in {
}; };
genode.boot.storePaths = genode.boot.storePaths =
lib.optional (config.genode.boot.storeBackend == "usb") bootDir; lib.optional (config.genode.boot.storeBackend != "tarball") bootDir;
virtualisation.qemu.options = virtualisation.qemu.options =
lib.optionals (!config.virtualisation.useBootLoader) [ lib.optionals (!config.virtualisation.useBootLoader) [
@ -39,6 +39,12 @@ in {
"-initrd '${pkgs.genodePackages.NOVA}/hypervisor-x86_64 arg=iommu logmem novpid serial,${config.genode.boot.image}/image.elf'" "-initrd '${pkgs.genodePackages.NOVA}/hypervisor-x86_64 arg=iommu logmem novpid serial,${config.genode.boot.image}/image.elf'"
]; ];
virtualisation.qemu.kernel = "${pkgs.genodePackages.bender}/share/bender/bender";
virtualisation.qemu.initrd = "${pkgs.genodePackages.NOVA}/hypervisor-x86_64";
virtualisation.qemu.cmdline = "arg=iommu logmem novpid serial,${config.genode.boot.image}/image.elf";
boot.loader.grub.extraEntries = '' boot.loader.grub.extraEntries = ''
menuentry 'Genode on NOVA' { menuentry 'Genode on NOVA' {
insmod multiboot2 insmod multiboot2

View File

@ -11,77 +11,6 @@ let
consoles = lib.concatMapStringsSep " " (c: "console=${c}") cfg.qemu.consoles; consoles = lib.concatMapStringsSep " " (c: "console=${c}") cfg.qemu.consoles;
driveOpts = { ... }: {
options = {
file = mkOption {
type = types.str;
description = "The file image used for this drive.";
};
driveExtraOpts = mkOption {
type = types.attrsOf types.str;
default = { };
description = "Extra options passed to drive flag.";
};
deviceExtraOpts = mkOption {
type = types.attrsOf types.str;
default = { };
description = "Extra options passed to device flag.";
};
name = mkOption {
type = types.nullOr types.str;
default = null;
description =
"A name for the drive. Must be unique in the drives list. Not passed to qemu.";
};
};
};
driveCmdline = idx:
{ file, driveExtraOpts, deviceExtraOpts, ... }:
let
drvId = "drive${toString idx}";
mkKeyValue = generators.mkKeyValueDefault { } "=";
mkOpts = opts: concatStringsSep "," (mapAttrsToList mkKeyValue opts);
driveOpts = mkOpts (driveExtraOpts // {
index = idx;
id = drvId;
"if" = "none";
inherit file;
});
deviceOpts = mkOpts (deviceExtraOpts // { drive = drvId; });
device = if cfg.qemu.diskInterface == "scsi" then
"-device lsi53c895a -device scsi-hd,${deviceOpts}"
else
"-device virtio-blk-pci,${deviceOpts}";
in "-drive ${driveOpts} ${device}";
drivesCmdLine = drives: concatStringsSep " " (imap1 driveCmdline drives);
# Creates a device name from a 1-based a numerical index, e.g.
# * `driveDeviceName 1` -> `/dev/vda`
# * `driveDeviceName 2` -> `/dev/vdb`
driveDeviceName = idx:
let letter = elemAt lowerChars (idx - 1);
in if cfg.qemu.diskInterface == "scsi" then
"/dev/sd${letter}"
else
"/dev/vd${letter}";
lookupDriveDeviceName = driveName: driveList:
(findSingle (drive: drive.name == driveName)
(throw "Drive ${driveName} not found")
(throw "Multiple drives named ${driveName}") driveList).device;
addDeviceNames =
imap1 (idx: drive: drive // { device = driveDeviceName idx; });
efiPrefix = if (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) then efiPrefix = if (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) then
"${pkgs.buildPackages.OVMF.fd}/FV/OVMF" "${pkgs.buildPackages.OVMF.fd}/FV/OVMF"
else if pkgs.stdenv.isAarch64 then else if pkgs.stdenv.isAarch64 then
@ -94,144 +23,38 @@ let
# Shell script to start the VM. # Shell script to start the VM.
startVM = '' startVM = ''
#! ${pkgs.buildPackages.runtimeShell} #! ${pkgs.buildPackages.runtimeShell}
'' + lib.optionalString (config.virtualisation.diskImage != null) ''
NIX_DISK_IMAGE=$(readlink -f ''${NIX_DISK_IMAGE:-${config.virtualisation.diskImage}}) NIX_DISK_IMAGE=$(readlink -f ''${NIX_DISK_IMAGE:-${config.virtualisation.diskImage}})
if ! test -w "$NIX_DISK_IMAGE"; then
${qemu}/bin/qemu-img create -f qcow2 -b $NIX_DISK_IMAGE $TMPDIR/disk.img || exit 1
NIX_DISK_IMAGE=$TMPDIR/disk.img
fi
if ! test -e "$NIX_DISK_IMAGE"; then if ! test -e "$NIX_DISK_IMAGE"; then
${qemu}/bin/qemu-img create -f qcow2 "$NIX_DISK_IMAGE" \ ${qemu}/bin/qemu-img create -f qcow2 "$NIX_DISK_IMAGE" \
${toString config.virtualisation.diskSize}M || exit 1 ${toString config.virtualisation.diskSize}M || exit 1
fi fi
'' + ''
# Create a directory for storing temporary data of the running VM. # Create a directory for storing temporary data of the running VM.
if [ -z "$TMPDIR" -o -z "$USE_TMPDIR" ]; then if [ -z "$TMPDIR" -o -z "$USE_TMPDIR" ]; then
TMPDIR=$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir) TMPDIR=$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir)
fi fi
# Create a directory for exchanging data with the VM.
mkdir -p $TMPDIR/xchg
${if cfg.useBootLoader then ''
# Create a writable copy/snapshot of the boot disk.
# A writable boot disk can be booted from automatically.
${qemu}/bin/qemu-img create -f qcow2 -b ${bootDisk}/disk.img $TMPDIR/disk.img || exit 1
NIX_EFI_VARS=$(readlink -f ''${NIX_EFI_VARS:-${cfg.efiVars}})
${if cfg.useEFIBoot then ''
# VM needs writable EFI vars
if ! test -e "$NIX_EFI_VARS"; then
cp ${bootDisk}/efi-vars.fd "$NIX_EFI_VARS" || exit 1
chmod 0644 "$NIX_EFI_VARS" || exit 1
fi
'' else
""}
'' else
""}
cd $TMPDIR
idx=0
${flip concatMapStrings cfg.emptyDiskImages (size: ''
if ! test -e "empty$idx.qcow2"; then
${qemu}/bin/qemu-img create -f qcow2 "empty$idx.qcow2" "${
toString size
}M"
fi
idx=$((idx + 1))
'')}
# Start QEMU. # Start QEMU.
set -v
exec ${qemuBinary qemu} \ exec ${qemuBinary qemu} \
-name ${config.system.name} \ -name ${config.system.name} \
-m ${toString config.virtualisation.memorySize} \ -m ${toString config.virtualisation.memorySize} \
-smp ${toString config.virtualisation.cores} \ -smp ${toString config.virtualisation.cores} \
-device virtio-rng-pci \
${concatStringsSep " " config.virtualisation.qemu.networkingOptions} \ ${concatStringsSep " " config.virtualisation.qemu.networkingOptions} \
-virtfs local,path=/nix/store,security_model=none,mount_tag=store \
-virtfs local,path=$TMPDIR/xchg,security_model=none,mount_tag=xchg \
-virtfs local,path=''${SHARED_DIR:-$TMPDIR/xchg},security_model=none,mount_tag=shared \
${drivesCmdLine config.virtualisation.qemu.drives} \
${toString config.virtualisation.qemu.options} \ ${toString config.virtualisation.qemu.options} \
$NIX_DISK_IMAGE \
$QEMU_OPTS \ $QEMU_OPTS \
"$@" "$@"
''; '';
regInfo =
pkgs.closureInfo { rootPaths = config.virtualisation.pathsInNixDB; };
# Generate a hard disk image containing a /boot partition and GRUB
# in the MBR. Used when the `useBootLoader' option is set.
# Uses `runInLinuxVM` to create the image in a throwaway VM.
# See note [Disk layout with `useBootLoader`].
# FIXME: use nixos/lib/make-disk-image.nix.
bootDisk = pkgs.vmTools.runInLinuxVM (pkgs.runCommand "nixos-boot-disk" {
preVM = ''
mkdir $out
diskImage=$out/disk.img
${qemu}/bin/qemu-img create -f qcow2 $diskImage "60M"
${if cfg.useEFIBoot then ''
efiVars=$out/efi-vars.fd
cp ${efiVarsDefault} $efiVars
chmod 0644 $efiVars
'' else
""}
'';
buildInputs = [ pkgs.utillinux ];
QEMU_OPTS = "-nographic -serial stdio -monitor none"
+ lib.optionalString cfg.useEFIBoot
(" -drive if=pflash,format=raw,unit=0,readonly=on,file=${efiFirmware}"
+ " -drive if=pflash,format=raw,unit=1,file=$efiVars");
} ''
# Create a /boot EFI partition with 60M and arbitrary but fixed GUIDs for reproducibility
${pkgs.gptfdisk}/bin/sgdisk \
--set-alignment=1 --new=1:34:2047 --change-name=1:BIOSBootPartition --typecode=1:ef02 \
--set-alignment=512 --largest-new=2 --change-name=2:EFISystem --typecode=2:ef00 \
--attributes=1:set:1 \
--attributes=2:set:2 \
--disk-guid=97FD5997-D90B-4AA3-8D16-C1723AEA73C1 \
--partition-guid=1:1C06F03B-704E-4657-B9CD-681A087A2FDC \
--partition-guid=2:970C694F-AFD0-4B99-B750-CDB7A329AB6F \
--hybrid 2 \
--recompute-chs /dev/vda
${optionalString (config.boot.loader.grub.device != "/dev/vda")
# In this throwaway VM, we only have the /dev/vda disk, but the
# actual VM described by `config` (used by `switch-to-configuration`
# below) may set `boot.loader.grub.device` to a different device
# that's nonexistent in the throwaway VM.
# Create a symlink for that device, so that the `grub-install`
# by `switch-to-configuration` will hit /dev/vda anyway.
''
ln -s /dev/vda ${config.boot.loader.grub.device}
''}
${pkgs.dosfstools}/bin/mkfs.fat -F16 /dev/vda2
export MTOOLS_SKIP_CHECK=1
${pkgs.mtools}/bin/mlabel -i /dev/vda2 ::boot
mkdir /boot
mount /dev/vda2 /boot
${optionalString config.boot.loader.efi.canTouchEfiVariables ''
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
''}
# This is needed for GRUB 0.97, which doesn't know about virtio devices.
mkdir /boot/grub
echo '(hd0) /dev/vda' > /boot/grub/device.map
# This is needed for systemd-boot to find ESP, and udev is not available here to create this
mkdir -p /dev/block
ln -s /dev/vda2 /dev/block/254:2
# Install bootloader
touch /etc/NIXOS
export NIXOS_INSTALL_BOOTLOADER=1
${config.system.build.toplevel}/bin/switch-to-configuration boot
umount /boot
'' # */
);
in { in {
options = { options = {
@ -250,7 +73,8 @@ in {
}; };
virtualisation.diskImage = mkOption { virtualisation.diskImage = mkOption {
default = "./${config.system.name}.qcow2"; type = with types; nullOr path;
default = null;
description = '' description = ''
Path to the disk image containing the root filesystem. Path to the disk image containing the root filesystem.
The image will be created on startup if it does not The image will be created on startup if it does not
@ -258,14 +82,6 @@ in {
''; '';
}; };
virtualisation.bootDevice = mkOption {
type = types.str;
example = "/dev/vda";
description = ''
The disk to be used for the root filesystem.
'';
};
virtualisation.emptyDiskImages = mkOption { virtualisation.emptyDiskImages = mkOption {
default = [ ]; default = [ ];
type = types.listOf types.int; type = types.listOf types.int;
@ -384,26 +200,28 @@ in {
''; '';
}; };
drives = mkOption {
type = types.listOf (types.submodule driveOpts);
description = "Drives passed to qemu.";
apply = addDeviceNames;
};
diskInterface = mkOption { diskInterface = mkOption {
default = "virtio"; default = "ahci";
example = "scsi"; example = "usb";
type = types.enum [ "virtio" "scsi" "ide" ]; type = types.enum [ "ahci" "usb" "virtio" ];
description = "The interface used for the virtual hard disks."; description = "The interface used for the virtual hard disks.";
}; };
guestAgent.enable = mkOption { kernel = mkOption {
default = true; type = types.path;
type = types.bool; description = "Guest kernel.";
description = ''
Enable the Qemu guest agent.
'';
}; };
initrd = mkOption {
type = types.path;
description = "Guest initrd.";
};
cmdline = mkOption {
type = types.str;
description = "Command line options to pass to guest.";
};
}; };
virtualisation.useBootLoader = mkOption { virtualisation.useBootLoader = mkOption {
@ -449,73 +267,8 @@ in {
config = { config = {
# Note [Disk layout with `useBootLoader`]
#
# If `useBootLoader = true`, we configure 2 drives:
# `/dev/?da` for the root disk, and `/dev/?db` for the boot disk
# which has the `/boot` partition and the boot loader.
# Concretely:
#
# * The second drive's image `disk.img` is created in `bootDisk = ...`
# using a throwaway VM. Note that there the disk is always `/dev/vda`,
# even though in the final VM it will be at `/dev/*b`.
# * The disks are attached in `virtualisation.qemu.drives`.
# Their order makes them appear as devices `a`, `b`, etc.
# * `fileSystems."/boot"` is adjusted to be on device `b`.
# If `useBootLoader`, GRUB goes to the second disk, see
# note [Disk layout with `useBootLoader`].
boot.loader.grub.device = mkVMOverride (if cfg.useBootLoader then
driveDeviceName 2 # second disk
else
cfg.bootDevice);
boot.initrd.extraUtilsCommands = ''
# We need mke2fs in the initrd.
copy_bin_and_libs ${pkgs.e2fsprogs}/bin/mke2fs
'';
boot.initrd.postDeviceCommands = ''
# If the disk image appears to be empty, run mke2fs to
# initialise.
FSTYPE=$(blkid -o value -s TYPE ${cfg.bootDevice} || true)
if test -z "$FSTYPE"; then
mke2fs -t ext4 ${cfg.bootDevice}
fi
'';
boot.initrd.postMountCommands = ''
# Mark this as a NixOS machine.
mkdir -p $targetRoot/etc
echo -n > $targetRoot/etc/NIXOS
# Fix the permissions on /tmp.
chmod 1777 $targetRoot/tmp
mkdir -p $targetRoot/boot
${optionalString cfg.writableStore ''
echo "mounting overlay filesystem on /nix/store..."
mkdir -p 0755 $targetRoot/nix/.rw-store/store $targetRoot/nix/.rw-store/work $targetRoot/nix/store
mount -t overlay overlay $targetRoot/nix/store \
-o lowerdir=$targetRoot/nix/.ro-store,upperdir=$targetRoot/nix/.rw-store/store,workdir=$targetRoot/nix/.rw-store/work || fail
''}
'';
virtualisation.bootDevice = mkDefault (driveDeviceName 1);
# FIXME: Consolidate this one day. # FIXME: Consolidate this one day.
virtualisation.qemu.options = mkMerge [ virtualisation.qemu.options = mkMerge [
(mkIf (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) [
"-usb"
"-device usb-tablet,bus=usb-bus.0"
])
(mkIf (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64) [
"-device virtio-gpu-pci"
"-device usb-ehci,id=usb0"
"-device usb-kbd"
"-device usb-tablet"
])
(mkIf cfg.useEFIBoot [ (mkIf cfg.useEFIBoot [
"-drive if=pflash,format=raw,unit=0,readonly,file=${efiFirmware}" "-drive if=pflash,format=raw,unit=0,readonly,file=${efiFirmware}"
"-drive if=pflash,format=raw,unit=1,file=$NIX_EFI_VARS" "-drive if=pflash,format=raw,unit=1,file=$NIX_EFI_VARS"
@ -524,29 +277,6 @@ in {
(mkIf (!cfg.graphics) [ "-nographic" ]) (mkIf (!cfg.graphics) [ "-nographic" ])
]; ];
virtualisation.qemu.drives = mkMerge [
[{
name = "root";
file = "$NIX_DISK_IMAGE";
driveExtraOpts.cache = "writeback";
driveExtraOpts.werror = "report";
}]
(mkIf cfg.useBootLoader [
# The order of this list determines the device names, see
# note [Disk layout with `useBootLoader`].
{
name = "boot";
file = "$TMPDIR/disk.img";
driveExtraOpts.media = "disk";
deviceExtraOpts.bootindex = "1";
}
])
(imap0 (idx: _: {
file = "$(pwd)/empty${toString idx}.qcow2";
driveExtraOpts.werror = "report";
}) cfg.emptyDiskImages)
];
system.build.vm = pkgs.runCommand "nixos-vm" { preferLocalBuild = true; } '' system.build.vm = pkgs.runCommand "nixos-vm" { preferLocalBuild = true; } ''
mkdir -p $out/bin mkdir -p $out/bin
ln -s ${ ln -s ${

35
tests/ahci.nix Normal file
View File

@ -0,0 +1,35 @@
{
name = "ahci";
machine = { pkgs, ... }: {
genode.boot.storeBackend = "ahci";
genode.init.children.hello = {
inputs = [ pkgs.hello pkgs.genodePackages.vfs.lib ];
configFile = pkgs.writeText "ahci-hello.child.dhall" ''
let Genode = env:DHALL_GENODE
let Init = Genode.Init
let Child = Init.Child
let Libc = Genode.Libc
in Child.flat
Child.Attributes::{
, binary = "hello"
, exitPropagate = True
, resources = Genode.Init.Resources::{
, caps = 500
, ram = Genode.units.MiB 10
}
, config =
Libc.toConfig
Libc::{ args = [ "hello", "-g", "Hello from AHCI test" ] }
}
'';
};
};
testScript = ''
start_all()
machine.wait_until_serial_output("Hello from AHCI test")
'';
}

View File

@ -8,6 +8,7 @@ let
testingPython = import ./lib/testing-python.nix; testingPython = import ./lib/testing-python.nix;
testSpecs = map (p: import p) [ testSpecs = map (p: import p) [
./ahci.nix
./bash.nix ./bash.nix
./hello.nix ./hello.nix
./log.nix ./log.nix

View File

@ -29,6 +29,7 @@ rec {
baseModules = (import "${modulesPath}/module-list.nix") ++ [ baseModules = (import "${modulesPath}/module-list.nix") ++ [
../../nixos-modules/genode-core.nix ../../nixos-modules/genode-core.nix
../../nixos-modules/genode-init.nix ../../nixos-modules/genode-init.nix
../../nixos-modules/gui
../../nixos-modules/hardware ../../nixos-modules/hardware
../../nixos-modules/qemu-vm.nix ../../nixos-modules/qemu-vm.nix
{ {