2024-01-19 12:32:06 +01:00
|
|
|
{ config, lib, pkgs, modulesPath, ... }:
|
|
|
|
|
|
|
|
# Contains the configuration to make a VM bootable with qemu.
|
|
|
|
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
"${modulesPath}/virtualisation/qemu-vm.nix"
|
|
|
|
];
|
|
|
|
|
2024-03-07 16:50:35 +01:00
|
|
|
# Enable ssh on boot
|
|
|
|
services.openssh.enable = true;
|
|
|
|
|
2024-01-19 12:32:06 +01:00
|
|
|
boot = {
|
2024-03-07 12:03:02 +01:00
|
|
|
kernelParams = [
|
|
|
|
"console=tty1"
|
|
|
|
"console=ttyS0,115200"
|
|
|
|
"boot.shell_on_fail"
|
|
|
|
];
|
2024-01-19 12:32:06 +01:00
|
|
|
consoleLogLevel = lib.mkDefault 7;
|
|
|
|
initrd.kernelModules = [
|
|
|
|
"virtio_pci"
|
|
|
|
"virtio_blk"
|
|
|
|
"virtio_input"
|
|
|
|
"9pnet"
|
|
|
|
"9pnet_virtio"
|
|
|
|
];
|
|
|
|
|
2024-03-04 14:44:49 +01:00
|
|
|
kernelPatches = [ {
|
|
|
|
name = "qemu";
|
|
|
|
patch = null;
|
|
|
|
extraConfig = ''
|
|
|
|
# For qemu
|
|
|
|
BLOCK y
|
|
|
|
BLK_DEV y
|
|
|
|
DEVTMPFS y
|
|
|
|
VIRTIO_MENU y
|
|
|
|
VIRTIO_BLK y
|
|
|
|
VIRTIO_NET y
|
|
|
|
EXT4_FS y
|
|
|
|
|
|
|
|
# For 9P: https://wiki.qemu.org/Documentation/9psetup
|
|
|
|
NET_9P y
|
|
|
|
NET_9P_VIRTIO y
|
|
|
|
NET_9P_DEBUG y
|
|
|
|
NET_DEVICES y
|
|
|
|
NET_CORE y
|
|
|
|
INET y
|
|
|
|
NETWORK_FILESYSTEMS y
|
|
|
|
OVERLAY_FS y
|
|
|
|
"9P_FS" y
|
|
|
|
"9P_FS_POSIX_ACL" y
|
|
|
|
PCI y
|
|
|
|
VIRTIO_PCI y
|
|
|
|
PCI_HOST_GENERIC y
|
|
|
|
'';
|
|
|
|
} ];
|
|
|
|
|
2024-01-19 12:32:06 +01:00
|
|
|
loader = {
|
|
|
|
grub.enable = false;
|
|
|
|
generic-extlinux-compatible.enable = true;
|
|
|
|
};
|
|
|
|
};
|
2024-03-07 12:03:02 +01:00
|
|
|
|
|
|
|
nixpkgs.overlays = [
|
|
|
|
(final: prev: {
|
|
|
|
qemu = prev.qemu.override { rutabagaSupport = false; };
|
|
|
|
|
|
|
|
uboot-custom = prev.ubootQemuRiscv64Smode.override {
|
|
|
|
# Override preboot to set 'bootcmd' directly to the kernel address in RAM
|
|
|
|
extraConfig = ''
|
|
|
|
CONFIG_PREBOOT="setenv fdt_addr ''${fdtcontroladdr}; fdt addr ''${fdtcontroladdr}; setenv bootcmd booti ''${kernel_addr_r} - ''${fdtcontroladdr};"
|
|
|
|
CONFIG_RISCV_ISA_C=n
|
|
|
|
'';
|
|
|
|
# Also include debug u-boot
|
|
|
|
filesToInstall = ["u-boot.bin" "u-boot"];
|
|
|
|
};
|
|
|
|
|
|
|
|
opensbi-uboot = prev.opensbi.overrideAttrs (old: {
|
|
|
|
makeFlags = old.makeFlags ++ [
|
|
|
|
# Build OpenSBI without compressed instructions
|
|
|
|
"PLATFORM_RISCV_ISA=rv64g"
|
|
|
|
# Check with: riscv64-unknown-elf-objdump -d -M no-aliases rotate
|
|
|
|
"FW_PAYLOAD_PATH=${final.uboot-custom}/u-boot.bin"
|
|
|
|
];
|
|
|
|
});
|
|
|
|
})
|
|
|
|
];
|
2024-01-19 12:32:06 +01:00
|
|
|
}
|