nixos-riscv/vm.nix

97 lines
2.3 KiB
Nix
Raw Permalink Normal View History

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
2024-05-28 18:12:14 +02:00
#"9P_FS" y
#"9P_FS_POSIX_ACL" y
2024-03-04 14:44:49 +01:00
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: {
2024-05-28 18:12:14 +02:00
qemu = prev.qemu.override {
pulseSupport = false;
pipewireSupport = false;
sdlSupport = false;
jackSupport = false;
gtkSupport = false;
vncSupport = false;
smartcardSupport = false;
};
2024-03-07 12:03:02 +01:00
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
}