Files
qemu-xteink/flake.nix
T
evan 1174ef0e5d feat(xteink): manage the emulator SD card from the web UI
Browse, edit, upload, and delete files on the FAT32 image with mtools,
mirroring the wasm emulator's Files tab. Mutations stop the emulator
first because QEMU caches the card, so host writes to a live image would
be lost.
2026-07-26 11:36:37 -04:00

137 lines
4.0 KiB
Nix

{
description = "Espressif QEMU fork with the xteink X3/X4 (ESP32-C3) machine and a wasm32 TCG backend";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{ self
, nixpkgs
, flake-utils
,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
keycodemapdb = pkgs.fetchFromGitLab {
owner = "qemu-project";
repo = "keycodemapdb";
rev = "f5772a62ec52591ff6870b7e8ef32482371f22c6";
hash = "sha256-GbZ5mrUYLXMi0IX4IZzles0Oyc095ij2xAsiLNJwfKQ=";
};
qemu-native-xteink = pkgs.stdenv.mkDerivation {
pname = "qemu-native-xteink";
version = pkgs.lib.strings.trim (builtins.readFile ./VERSION);
src = pkgs.lib.cleanSource ./.;
nativeBuildInputs = with pkgs; [
bison
flex
meson
ninja
perl
pkg-config
python3
];
buildInputs = with pkgs; [
dtc
glib
gtk3
libgcrypt
libpng
libslirp
pixman
zlib
];
dontUseMesonConfigure = true;
postPatch = ''
cp -r ${keycodemapdb} subprojects/keycodemapdb
chmod -R u+w subprojects/keycodemapdb
sed -i "/subdir('fp')/d" tests/meson.build
substituteInPlace meson.build --replace-fail "static: true" "static: false"
'';
configurePhase = ''
runHook preConfigure
export PKG_CONFIG_PATH=${pkgs.libslirp}/lib/pkgconfig''${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
./configure \
--prefix=$out \
--target-list=riscv32-softmmu \
--with-devices-riscv32=xteink \
--with-coroutine=ucontext \
--without-default-features \
--enable-system \
--enable-gcrypt \
--enable-gtk \
--enable-pixman \
--enable-png \
--enable-slirp \
--disable-werror \
--disable-docs \
--disable-tools
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
ninja -C build qemu-system-riscv32
runHook postBuild
'';
installPhase = ''
runHook preInstall
ninja -C build install
runHook postInstall
'';
};
xteink-emu = pkgs.writeShellApplication {
name = "xteink-emu";
runtimeInputs = [ pkgs.uv pkgs.mtools pkgs.dosfstools ];
text = ''
export XTEINK_QEMU=${qemu-native-xteink}/bin/qemu-system-riscv32
export XTEINK_BIOS=${qemu-native-xteink}/share/qemu
export XTEINK_BOOTLOADER=${./scripts/assets/esp32c3-bootloader.bin}
export XTEINK_PARTITIONS=${./scripts/assets/xteink-partitions.bin}
exec uv run --script ${./scripts}/xteink-emu.py "$@"
'';
};
in
{
packages.qemu-native-xteink = qemu-native-xteink;
packages.xteink-emu = xteink-emu;
apps.xteink-emu = {
type = "app";
program = "${xteink-emu}/bin/xteink-emu";
};
# Native build/test shell. The wasm target is built by the parent
# xteink-web-emulator repo via its emsdk Docker toolchain, not here.
#
# nix develop
# ./configure --target-list=riscv32-softmmu --with-devices-riscv32=xteink \
# --enable-gcrypt && ninja -C build qemu-system-riscv32
devShells.default = pkgs.mkShell {
inputsFrom = [ pkgs.qemu ];
packages = with pkgs; [
dosfstools
git
gnumake
libgcrypt
libslirp
meson
mtools
ninja
pixman
pkg-config
uv
];
};
}
);
}