nixos: boot from AHCI
This commit is contained in:
vanhempi
085ce919d3
commit
26d4f6b62e
|
@ -1,12 +1,15 @@
|
|||
{ flake }:
|
||||
|
||||
let
|
||||
baseModules =
|
||||
[ ./genode-core.nix ./genode-init.nix ./gui ./hardware.nix ./systemd.nix ];
|
||||
in {
|
||||
{
|
||||
|
||||
x86_64 = {
|
||||
imports = [ baseModules ];
|
||||
imports = [
|
||||
./genode-core.nix
|
||||
./genode-init.nix
|
||||
./hardware.nix
|
||||
./qemu-vm.nix
|
||||
./systemd.nix
|
||||
];
|
||||
nixpkgs = rec {
|
||||
localSystem = "x86_64-linux";
|
||||
crossSystem = "x86_64-genode";
|
||||
|
|
|
@ -98,13 +98,22 @@ in {
|
|||
};
|
||||
|
||||
storeBackend = mkOption {
|
||||
type = types.enum [ "tarball" "usb" ]; # "parent"?
|
||||
type = types.enum [ "ahci" "tarball" "usb" ]; # "parent"?
|
||||
default = "tarball";
|
||||
description = ''
|
||||
Backend for the initial /nix/store file-system.
|
||||
|
||||
<variablelist>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>ahci</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
An EXT2 file-system backed by SATA storage.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>tarball</literal></term>
|
||||
<listitem>
|
||||
|
@ -188,12 +197,12 @@ in {
|
|||
}];
|
||||
|
||||
genode.core.basePackages =
|
||||
lib.optional (config.genode.boot.storeBackend == "usb")
|
||||
lib.optional (config.genode.boot.storeBackend != "tarball")
|
||||
pkgs.genodePackages.part_block;
|
||||
|
||||
genode.core.children =
|
||||
# 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" ''
|
||||
let Genode = env:DHALL_GENODE
|
||||
|
||||
|
@ -223,18 +232,25 @@ in {
|
|||
{ }) // {
|
||||
store_fs.configFile = let
|
||||
|
||||
storeVfsConfig = {
|
||||
storeVfsConfig = let
|
||||
rumpExt2 = ''
|
||||
VFS.vfs [ VFS.leafAttrs "rump" (toMap { fs = "ext2fs", ram="12M" }) ]
|
||||
'';
|
||||
in {
|
||||
ahci = rumpExt2;
|
||||
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" }) ]
|
||||
'';
|
||||
usb = rumpExt2;
|
||||
}.${config.genode.boot.storeBackend};
|
||||
|
||||
storeResources = {
|
||||
storeResources = let
|
||||
rumpExt2 =
|
||||
"Init.Resources::{ caps = 256, ram = Genode.units.MiB 16 }";
|
||||
in {
|
||||
ahci = rumpExt2;
|
||||
tarball = "Init.Resources.default";
|
||||
usb = "Init.Resources::{ caps = 256, ram = Genode.units.MiB 16 }";
|
||||
usb = rumpExt2;
|
||||
}.${config.genode.boot.storeBackend};
|
||||
|
||||
in builtins.toFile "store_fs.dhall" ''
|
||||
|
@ -272,6 +288,7 @@ in {
|
|||
"${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar";
|
||||
|
||||
storeBackendInputs = {
|
||||
ahci = [ pkgs.genodePackages.rump ];
|
||||
tarball = [ config.system.build.tarball ];
|
||||
usb = [ pkgs.genodePackages.rump ];
|
||||
}.${config.genode.boot.storeBackend};
|
||||
|
@ -370,7 +387,7 @@ in {
|
|||
xmllint --noout $out
|
||||
'';
|
||||
|
||||
system.build.bootDriveImage = let
|
||||
virtualisation.diskImage = let
|
||||
espImage = import ./lib/make-esp-fs.nix { inherit config pkgs; };
|
||||
storeFsImage =
|
||||
pkgs.callPackage ./lib/make-ext2-fs.nix { inherit config pkgs; };
|
||||
|
@ -382,12 +399,15 @@ in {
|
|||
# virtualisation.useEFIBoot = config.genode.boot.storeBackend == "usb";
|
||||
|
||||
virtualisation.qemu.options =
|
||||
lib.optionals (config.genode.boot.storeBackend == "usb") [
|
||||
"-bios ${pkgs.buildPackages.OVMF.fd}/FV/OVMF.fd"
|
||||
"-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly"
|
||||
"-usb"
|
||||
"-device usb-storage,drive=usbdisk"
|
||||
];
|
||||
let blockCommon = [ "-bios ${pkgs.buildPackages.OVMF.fd}/FV/OVMF.fd" ];
|
||||
in {
|
||||
tarball = [ ];
|
||||
ahci = blockCommon;
|
||||
usb = blockCommon ++ [
|
||||
"-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly"
|
||||
"-device usb-storage,drive=usbdisk"
|
||||
];
|
||||
}.${config.genode.boot.storeBackend};
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -36,6 +36,16 @@ with lib;
|
|||
|
||||
hardware.genode = {
|
||||
|
||||
ahci.enable = lib.mkEnableOption "AHCI (SATA) block driver";
|
||||
|
||||
framebuffer = {
|
||||
enable = lib.mkEnableOption "framebuffer driver";
|
||||
driver = mkOption {
|
||||
type = types.enum [ "boot" "vesa" ];
|
||||
default = "vesa";
|
||||
};
|
||||
};
|
||||
|
||||
usb = {
|
||||
|
||||
enable = lib.mkEnableOption "USB driver";
|
||||
|
@ -48,14 +58,6 @@ with lib;
|
|||
|
||||
};
|
||||
|
||||
framebuffer = {
|
||||
enable = lib.mkEnableOption "framebuffer driver";
|
||||
driver = mkOption {
|
||||
type = types.enum [ "boot" "vesa" ];
|
||||
default = "vesa";
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -92,6 +94,8 @@ with lib;
|
|||
policyCheck
|
||||
];
|
||||
|
||||
hardware.genode.ahci.enable = config.genode.boot.storeBackend == "ahci";
|
||||
|
||||
hardware.genode.usb.storage.enable = config.genode.boot.storeBackend
|
||||
== "usb";
|
||||
|
||||
|
@ -115,31 +119,43 @@ with lib;
|
|||
]
|
||||
}
|
||||
'') (builtins.attrNames config.networking.interfaces)
|
||||
++ lib.optional config.hardware.genode.framebuffer.enable
|
||||
(builtins.toFile ("framebuffer.platform-policy.dhall") ''
|
||||
let Genode = env:DHALL_GENODE
|
||||
++ (lib.optional config.hardware.genode.ahci.enable
|
||||
(builtins.toFile ("ahci.platform-policy.dhall") ''
|
||||
let Genode = env:DHALL_GENODE
|
||||
|
||||
in Genode.Init.Config.Policy::{
|
||||
, service = "Platform"
|
||||
, label = Genode.Init.LabelSelector.prefix "fb_drv"
|
||||
, content =
|
||||
[ Genode.Prelude.XML.leaf
|
||||
{ name = "pci", attributes = toMap { class = "VGA" } }
|
||||
]
|
||||
}
|
||||
'') ++ lib.optional config.hardware.genode.usb.enable
|
||||
(builtins.toFile ("usb.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" } }
|
||||
]
|
||||
}
|
||||
'')) ++ (lib.optional config.hardware.genode.framebuffer.enable
|
||||
(builtins.toFile ("framebuffer.platform-policy.dhall") ''
|
||||
let Genode = env:DHALL_GENODE
|
||||
|
||||
in Genode.Init.Config.Policy::{
|
||||
, service = "Platform"
|
||||
, label = Genode.Init.LabelSelector.prefix "usb_drv"
|
||||
, content =
|
||||
[ Genode.Prelude.XML.leaf
|
||||
{ name = "pci", attributes = toMap { class = "USB" } }
|
||||
]
|
||||
}
|
||||
'');
|
||||
in Genode.Init.Config.Policy::{
|
||||
, service = "Platform"
|
||||
, label = Genode.Init.LabelSelector.prefix "fb_drv"
|
||||
, content =
|
||||
[ Genode.Prelude.XML.leaf
|
||||
{ name = "pci", attributes = toMap { class = "VGA" } }
|
||||
]
|
||||
}
|
||||
'')) ++ (lib.optional config.hardware.genode.usb.enable
|
||||
(builtins.toFile ("usb.platform-policy.dhall") ''
|
||||
let Genode = env:DHALL_GENODE
|
||||
|
||||
in Genode.Init.Config.Policy::{
|
||||
, service = "Platform"
|
||||
, label = Genode.Init.LabelSelector.prefix "usb_drv"
|
||||
, content =
|
||||
[ Genode.Prelude.XML.leaf
|
||||
{ name = "pci", attributes = toMap { class = "USB" } }
|
||||
]
|
||||
}
|
||||
''));
|
||||
|
||||
genode.init.children = let
|
||||
|
||||
|
@ -280,6 +296,40 @@ with lib;
|
|||
|
||||
in lib.filterAttrs (n: v: v != null) (nics // sockets);
|
||||
|
||||
genode.core.children.ahci_drv = {
|
||||
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" }
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
||||
genode.core.children.acpi_drv = {
|
||||
inputs = [ pkgs.genodePackages.acpi_drv ];
|
||||
configFile = pkgs.writeText "acpi_drv.dhall" ''
|
||||
|
@ -452,6 +502,8 @@ with lib;
|
|||
'';
|
||||
};
|
||||
|
||||
virtualisation.useBootLoader = config.genode.boot.storeBackend != "tarball";
|
||||
|
||||
virtualisation.qemu.options = lib.optional config.hardware.genode.usb.enable
|
||||
(lib.optional (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) "-usb"
|
||||
++ lib.optional (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64)
|
||||
|
|
|
@ -64,6 +64,6 @@ pkgs.stdenv.mkDerivation {
|
|||
start=$espSectorOffset, type=$efiUuid
|
||||
EOF
|
||||
|
||||
qemu-img convert $img $out
|
||||
qemu-img convert -f raw -O qcow2 $img $out
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ in {
|
|||
};
|
||||
|
||||
genode.boot.storePaths =
|
||||
lib.optional (config.genode.boot.storeBackend == "usb") bootDir;
|
||||
lib.optional (config.genode.boot.storeBackend != "tarball") bootDir;
|
||||
|
||||
virtualisation.qemu.options =
|
||||
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'"
|
||||
];
|
||||
|
||||
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 = ''
|
||||
menuentry 'Genode on NOVA' {
|
||||
insmod multiboot2
|
||||
|
|
|
@ -11,77 +11,6 @@ let
|
|||
|
||||
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
|
||||
"${pkgs.buildPackages.OVMF.fd}/FV/OVMF"
|
||||
else if pkgs.stdenv.isAarch64 then
|
||||
|
@ -97,6 +26,11 @@ let
|
|||
|
||||
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
|
||||
${qemu}/bin/qemu-img create -f qcow2 "$NIX_DISK_IMAGE" \
|
||||
${toString config.virtualisation.diskSize}M || exit 1
|
||||
|
@ -107,131 +41,19 @@ let
|
|||
TMPDIR=$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir)
|
||||
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.
|
||||
set -v
|
||||
exec ${qemuBinary qemu} \
|
||||
-name ${config.system.name} \
|
||||
-m ${toString config.virtualisation.memorySize} \
|
||||
-smp ${toString config.virtualisation.cores} \
|
||||
-device virtio-rng-pci \
|
||||
${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} \
|
||||
$NIX_DISK_IMAGE \
|
||||
$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 {
|
||||
options = {
|
||||
|
||||
|
@ -258,14 +80,6 @@ in {
|
|||
'';
|
||||
};
|
||||
|
||||
virtualisation.bootDevice = mkOption {
|
||||
type = types.str;
|
||||
example = "/dev/vda";
|
||||
description = ''
|
||||
The disk to be used for the root filesystem.
|
||||
'';
|
||||
};
|
||||
|
||||
virtualisation.emptyDiskImages = mkOption {
|
||||
default = [ ];
|
||||
type = types.listOf types.int;
|
||||
|
@ -384,26 +198,28 @@ in {
|
|||
'';
|
||||
};
|
||||
|
||||
drives = mkOption {
|
||||
type = types.listOf (types.submodule driveOpts);
|
||||
description = "Drives passed to qemu.";
|
||||
apply = addDeviceNames;
|
||||
};
|
||||
|
||||
diskInterface = mkOption {
|
||||
default = "virtio";
|
||||
example = "scsi";
|
||||
type = types.enum [ "virtio" "scsi" "ide" ];
|
||||
default = "ahci";
|
||||
example = "usb";
|
||||
type = types.enum [ "ahci" "usb" "virtio" ];
|
||||
description = "The interface used for the virtual hard disks.";
|
||||
};
|
||||
|
||||
guestAgent.enable = mkOption {
|
||||
default = true;
|
||||
type = types.bool;
|
||||
description = ''
|
||||
Enable the Qemu guest agent.
|
||||
'';
|
||||
kernel = mkOption {
|
||||
type = types.path;
|
||||
description = "Guest kernel.";
|
||||
};
|
||||
|
||||
initrd = mkOption {
|
||||
type = types.path;
|
||||
description = "Guest initrd.";
|
||||
};
|
||||
|
||||
cmdline = mkOption {
|
||||
type = types.str;
|
||||
description = "Command line options to pass to guest.";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
virtualisation.useBootLoader = mkOption {
|
||||
|
@ -449,73 +265,8 @@ in {
|
|||
|
||||
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.
|
||||
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 [
|
||||
"-drive if=pflash,format=raw,unit=0,readonly,file=${efiFirmware}"
|
||||
"-drive if=pflash,format=raw,unit=1,file=$NIX_EFI_VARS"
|
||||
|
@ -524,29 +275,6 @@ in {
|
|||
(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; } ''
|
||||
mkdir -p $out/bin
|
||||
ln -s ${
|
||||
|
|
|
@ -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")
|
||||
'';
|
||||
}
|
|
@ -8,6 +8,7 @@ let
|
|||
testingPython = import ./lib/testing-python.nix;
|
||||
|
||||
testSpecs = map (p: import p) [
|
||||
./ahci.nix
|
||||
./bash.nix
|
||||
./hello.nix
|
||||
./log.nix
|
||||
|
|
Ladataan…
Viittaa uudesa ongelmassa