extract common config for qemu devices into module

This commit is contained in:
Daniel Barlow 2023-12-09 16:42:45 +00:00
parent 07e66c462b
commit 317457f582
4 changed files with 70 additions and 135 deletions

54
devices/families/qemu.nix Normal file
View file

@ -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 ];
};
};
};
};
}

View file

@ -27,29 +27,15 @@
installer = "vmroot"; installer = "vmroot";
module = {pkgs, config, lim, ... }: { module = {pkgs, config, lim, ... }: {
imports = [ ../../modules/arch/aarch64.nix ]; imports = [
../../modules/arch/aarch64.nix
../families/qemu.nix
];
kernel = { 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 = { config = {
VIRTUALIZATION = "y"; VIRTUALIZATION = "y";
PCI_HOST_GENERIC="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 = "y";
SERIAL_AMBA_PL011_CONSOLE = "y"; SERIAL_AMBA_PL011_CONSOLE = "y";
}; };
@ -57,31 +43,5 @@
boot.commandLine = [ boot.commandLine = [
"console=ttyAMA0,38400" "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 ];
};
};
};
}; };
} }

View file

@ -25,33 +25,19 @@
installer = "vmroot"; installer = "vmroot";
module = {pkgs, config, lim, ... }: { module = {pkgs, config, lim, ... }: {
imports = [ ../../modules/arch/arm.nix ]; imports = [
../../modules/arch/arm.nix
../families/qemu.nix
];
kernel = { 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 = { config = {
PCI_HOST_GENERIC = "y"; PCI_HOST_GENERIC = "y";
PCI = "y";
ARCH_VIRT = "y"; ARCH_VIRT = "y";
VFP = "y"; VFP = "y";
NEON = "y"; NEON = "y";
AEABI = "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 = "y";
SERIAL_AMBA_PL011_CONSOLE = "y"; SERIAL_AMBA_PL011_CONSOLE = "y";
}; };
@ -59,31 +45,9 @@
boot.commandLine = [ boot.commandLine = [
"console=ttyAMA0" "console=ttyAMA0"
]; ];
hardware = hardware = {
let loadAddress = lim.parseInt "0x00010000";
mac80211 = pkgs.mac80211.override { entryPoint = lim.parseInt "0x00010000";
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 ];
};
};
};
}; };
} }

View file

@ -37,61 +37,18 @@
''; '';
module = {pkgs, config, lim, ... }: { module = {pkgs, config, lim, ... }: {
imports = [ ../../modules/arch/mipseb.nix ]; imports = [
../../modules/arch/mipseb.nix
../families/qemu.nix
];
kernel = { 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 = { config = {
MIPS_MALTA= "y"; MIPS_MALTA= "y";
CPU_MIPS32_R2= "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= "y";
SERIAL_8250_CONSOLE= "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 ];
};
};
};
}; };
} }