{ config, lib, pkgs, modulesPath, ... }: # Contains the configuration to make a VM bootable with qemu. { imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ]; # Enable ssh on boot services.openssh.enable = true; boot = { kernelParams = [ "console=tty1" "console=ttyS0,115200" "boot.shell_on_fail" ]; consoleLogLevel = lib.mkDefault 7; initrd.kernelModules = [ "virtio_pci" "virtio_blk" "virtio_input" "9pnet" "9pnet_virtio" ]; 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 ''; } ]; loader = { grub.enable = false; generic-extlinux-compatible.enable = true; }; }; nixpkgs.overlays = [ (final: prev: { qemu = prev.qemu.override { pulseSupport = false; pipewireSupport = false; sdlSupport = false; jackSupport = false; gtkSupport = false; vncSupport = false; smartcardSupport = 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" ]; }); }) ]; }