From 1fdac5afd2d1edeb11c2530cf95f4f30529f7cdc Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Tue, 5 May 2026 11:17:23 +0300 Subject: [PATCH] doc/stdenv/cross-compilation: expand a bit emulation example --- doc/stdenv/cross-compilation.chapter.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/stdenv/cross-compilation.chapter.md b/doc/stdenv/cross-compilation.chapter.md index 08e1a9bc22c7..18f3b2344607 100644 --- a/doc/stdenv/cross-compilation.chapter.md +++ b/doc/stdenv/cross-compilation.chapter.md @@ -161,10 +161,20 @@ stdenv.mkDerivation { To run a cross-compiled binary outside the Nix sandbox, build it and invoke the emulator from a shell. This is also a quick way to verify the dispatch table above: ```ShellSession -$ nix-build '' -A pkgsCross.aarch64-multiplatform.hello +$ nix-build '' -A pkgsCross.aarch64-multiplatform.hello # Should be available in cache.nixos.org +``` + +To get a path for an emulator, given a `crossSystem.config` (e.g with `aarch64-linux`): + +```ShellSession $ nix-instantiate --eval --strict -E \ '(import { crossSystem.config = "aarch64-unknown-linux-gnu"; }).stdenv.hostPlatform.emulator (import {})' "/nix/store/.../bin/qemu-aarch64" +``` + +And specifically for `aarch64-linux`, and many other platforms, you have all of them available in `qemu` package, meaning you can simply run: + +```ShellSession $ nix-shell -p qemu --run 'qemu-aarch64 ./result/bin/hello' Hello, world! ```