52 lines
1.7 KiB
Nix
52 lines
1.7 KiB
Nix
|
# based on https://github.com/NickCao/nixos-riscv/blob/master/qemu.nix
|
||
|
{ config, pkgs, lib, ...}:
|
||
|
|
||
|
{
|
||
|
boot.loader.generic-extlinux-compatible.enable = false;
|
||
|
|
||
|
#boot.kernelPackages = pkgs.linuxPackages_latest;
|
||
|
boot.kernelParams = [ "console=ttyS0" "earlycon" ];
|
||
|
boot.initrd.availableKernelModules = [ "pci_host_generic" "virtio_pci" "9p" "9pnet_virtio" ];
|
||
|
|
||
|
fileSystems."/" = {
|
||
|
device = "none";
|
||
|
fsType = "tmpfs";
|
||
|
options = [ "defaults" "mode=755" ];
|
||
|
};
|
||
|
fileSystems."/nix/store" = {
|
||
|
device = "nix-store";
|
||
|
fsType = "9p";
|
||
|
options = [ "ro" "trans=virtio" "version=9p2000.L" "msize=1M" ];
|
||
|
};
|
||
|
|
||
|
systemd.services."autotty@hvc0".enable = false;
|
||
|
systemd.services.mount-pstore.enable = false;
|
||
|
services.getty.autologinUser = "root";
|
||
|
networking.firewall.enable = false;
|
||
|
#virtualisation.docker.enable = true;
|
||
|
|
||
|
system.build.vm =
|
||
|
let
|
||
|
qemu-path = "${pkgs.pkgsBuildBuild.qemu}/bin/qemu-system-${pkgs.targetPlatform.qemuArch}";
|
||
|
closure = config.system.build.toplevel;
|
||
|
qemu-args = [
|
||
|
"-M" "virt"
|
||
|
"-smp" "2" # cpus
|
||
|
"-m" "2G" # mem
|
||
|
"-kernel" "${closure}/kernel"
|
||
|
"-initrd" "${closure}/initrd"
|
||
|
"-append" "$(cat ${closure}/kernel-params) init=${closure}/init"
|
||
|
"-device" "virtio-rng-pci"
|
||
|
"-netdev" "user,id=end0"
|
||
|
"-device" "virtio-net-pci,netdev=end0"
|
||
|
"-netdev" "user,id=end1"
|
||
|
"-device" "virtio-net-pci,netdev=end1"
|
||
|
"-fsdev" "local,security_model=passthrough,id=nix-store,path=/nix/store,readonly=on"
|
||
|
"-device" "virtio-9p-pci,id=nix-store,fsdev=nix-store,mount_tag=nix-store"
|
||
|
"-nographic"
|
||
|
];
|
||
|
in pkgs.writeShellScriptBin "run-vm" ''
|
||
|
exec ${qemu-path} ${lib.escapeShellArgs qemu-args}
|
||
|
'';
|
||
|
}
|