From 317457f582d0b6099a0e7216d723ab9e9672117b Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 9 Dec 2023 16:42:45 +0000 Subject: [PATCH] extract common config for qemu devices into module --- devices/families/qemu.nix | 54 ++++++++++++++++++++++++++++++++ devices/qemu-aarch64/default.nix | 48 +++------------------------- devices/qemu-armv7l/default.nix | 52 +++++------------------------- devices/qemu/default.nix | 51 +++--------------------------- 4 files changed, 70 insertions(+), 135 deletions(-) create mode 100644 devices/families/qemu.nix diff --git a/devices/families/qemu.nix b/devices/families/qemu.nix new file mode 100644 index 0000000..2ebb986 --- /dev/null +++ b/devices/families/qemu.nix @@ -0,0 +1,54 @@ +{ config, pkgs, ... }: +{ + config = { + kernel = { + src = pkgs.pkgsBuildBuild.fetchurl { + name = "linux.tar.gz"; + url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.71.tar.gz"; + hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8="; + }; + config = { + MTD = "y"; + MTD_BLOCK = "y"; + MTD_CMDLINE_PARTS = "y"; + MTD_PHRAM = "y"; + + VIRTIO_MENU = "y"; + PCI = "y"; + VIRTIO_PCI = "y"; + BLOCK = "y"; + VIRTIO_BLK = "y"; + VIRTIO_NET = "y"; + }; + }; + hardware = + let + mac80211 = pkgs.mac80211.override { + drivers = ["mac80211_hwsim"]; + klibBuild = config.system.outputs.kernel.modulesupport; + }; + in { + defaultOutput = "vmroot"; + rootDevice = "/dev/mtdblock0"; + dts.src = null; + flash.eraseBlockSize = 65536; + networkInterfaces = + let inherit (config.system.service.network) link; + in { + wan = link.build { + devpath = "/devices/pci0000:00/0000:00:13.0/virtio0"; + ifname = "wan"; + }; + lan = link.build { + devpath = "/devices/pci0000:00/0000:00:14.0/virtio1"; + ifname = "lan"; + }; + + wlan_24 = link.build { + ifname = "wlan0"; + dependencies = [ mac80211 ]; + }; + }; + }; + }; +} diff --git a/devices/qemu-aarch64/default.nix b/devices/qemu-aarch64/default.nix index 2c4a22d..275ce36 100644 --- a/devices/qemu-aarch64/default.nix +++ b/devices/qemu-aarch64/default.nix @@ -27,29 +27,15 @@ installer = "vmroot"; module = {pkgs, config, lim, ... }: { - imports = [ ../../modules/arch/aarch64.nix ]; + imports = [ + ../../modules/arch/aarch64.nix + ../families/qemu.nix + ]; kernel = { - src = pkgs.pkgsBuildBuild.fetchurl { - name = "linux.tar.gz"; - url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.71.tar.gz"; - hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8="; - }; config = { VIRTUALIZATION = "y"; PCI_HOST_GENERIC="y"; - MTD = "y"; - MTD_BLOCK = "y"; - MTD_CMDLINE_PARTS = "y"; - MTD_PHRAM = "y"; - - VIRTIO_MENU = "y"; - PCI = "y"; - VIRTIO_PCI = "y"; - BLOCK = "y"; - VIRTIO_BLK = "y"; - VIRTIO_NET = "y"; - SERIAL_AMBA_PL011 = "y"; SERIAL_AMBA_PL011_CONSOLE = "y"; }; @@ -57,31 +43,5 @@ boot.commandLine = [ "console=ttyAMA0,38400" ]; - hardware = - let - mac80211 = pkgs.mac80211.override { - drivers = ["mac80211_hwsim"]; - klibBuild = config.system.outputs.kernel.modulesupport; - }; - in { - defaultOutput = "vmroot"; - loadAddress = lim.parseInt "0x0"; - entryPoint = lim.parseInt "0x0"; - rootDevice = "/dev/mtdblock0"; - - flash.eraseBlockSize = 65536; # c.f. pkgs/mips-vm/mips-vm.sh - networkInterfaces = - let inherit (config.system.service.network) link; - in { - wan = link.build { ifname = "eth0"; }; - lan = link.build { ifname = "eth1"; }; - - wlan_24 = link.build { - ifname = "wlan0"; - dependencies = [ mac80211 ]; - }; - }; - }; - }; } diff --git a/devices/qemu-armv7l/default.nix b/devices/qemu-armv7l/default.nix index ff9c0a2..03fddb9 100644 --- a/devices/qemu-armv7l/default.nix +++ b/devices/qemu-armv7l/default.nix @@ -25,33 +25,19 @@ installer = "vmroot"; module = {pkgs, config, lim, ... }: { - imports = [ ../../modules/arch/arm.nix ]; + imports = [ + ../../modules/arch/arm.nix + ../families/qemu.nix + ]; kernel = { - src = pkgs.pkgsBuildBuild.fetchurl { - name = "linux.tar.gz"; - url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.71.tar.gz"; - hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8="; - }; config = { PCI_HOST_GENERIC = "y"; - PCI = "y"; ARCH_VIRT = "y"; VFP = "y"; NEON = "y"; AEABI = "y"; - MTD = "y"; - MTD_BLOCK = "y"; - MTD_CMDLINE_PARTS = "y"; - MTD_PHRAM = "y"; - - VIRTIO_MENU = "y"; - VIRTIO_PCI = "y"; - BLOCK = "y"; - VIRTIO_BLK = "y"; - VIRTIO_NET = "y"; - SERIAL_AMBA_PL011 = "y"; SERIAL_AMBA_PL011_CONSOLE = "y"; }; @@ -59,31 +45,9 @@ boot.commandLine = [ "console=ttyAMA0" ]; - hardware = - let - mac80211 = pkgs.mac80211.override { - drivers = ["mac80211_hwsim"]; - klibBuild = config.system.outputs.kernel.modulesupport; - }; - in { - defaultOutput = "vmroot"; - loadAddress = lim.parseInt "0x00010000"; - entryPoint = lim.parseInt "0x00010000"; - rootDevice = "/dev/mtdblock0"; - - flash.eraseBlockSize = 65536; # c.f. pkgs/mips-vm/mips-vm.sh - networkInterfaces = - let inherit (config.system.service.network) link; - in { - wan = link.build { ifname = "eth0"; }; - lan = link.build { ifname = "eth1"; }; - - wlan_24 = link.build { - ifname = "wlan0"; - dependencies = [ mac80211 ]; - }; - }; - }; - + hardware = { + loadAddress = lim.parseInt "0x00010000"; + entryPoint = lim.parseInt "0x00010000"; + }; }; } diff --git a/devices/qemu/default.nix b/devices/qemu/default.nix index 8473d38..3c4ce2d 100644 --- a/devices/qemu/default.nix +++ b/devices/qemu/default.nix @@ -37,61 +37,18 @@ ''; module = {pkgs, config, lim, ... }: { - imports = [ ../../modules/arch/mipseb.nix ]; + imports = [ + ../../modules/arch/mipseb.nix + ../families/qemu.nix + ]; kernel = { - src = pkgs.pkgsBuildBuild.fetchurl { - name = "linux.tar.gz"; - url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.71.tar.gz"; - hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8="; - }; config = { MIPS_MALTA= "y"; CPU_MIPS32_R2= "y"; - MTD = "y"; - MTD_BLOCK = "y"; - MTD_CMDLINE_PARTS = "y"; - MTD_PHRAM = "y"; - - VIRTIO_MENU = "y"; - PCI = "y"; - VIRTIO_PCI = "y"; - BLOCK = "y"; - VIRTIO_BLK = "y"; - VIRTIO_NET = "y"; - SERIAL_8250= "y"; SERIAL_8250_CONSOLE= "y"; }; }; - hardware = - let - mac80211 = pkgs.mac80211.override { - drivers = ["mac80211_hwsim"]; - klibBuild = config.system.outputs.kernel.modulesupport; - }; - in { - defaultOutput = "vmroot"; - rootDevice = "/dev/mtdblock0"; - flash.eraseBlockSize = 65536; - networkInterfaces = - let inherit (config.system.service.network) link; - in { - wan = link.build { - devpath = "/devices/pci0000:00/0000:00:13.0/virtio0"; - ifname = "wan"; - }; - lan = link.build { - devpath = "/devices/pci0000:00/0000:00:14.0/virtio1"; - ifname = "lan"; - }; - - wlan_24 = link.build { - ifname = "wlan0"; - dependencies = [ mac80211 ]; - }; - }; - }; - }; }