Skip to content

Commit c0a5382

Browse files
authored
Use host-architecture packages for build-time derivations (#504)
When building a MicroVM for a different architecture (e.g. aarch64-linux guest on x86_64 host) with QEMU system emulation, NixOS module evaluation binds `pkgs` to the guest's package set. Build-time derivations like `runCommandLocal` and runtime host-side binaries must use host-architecture packages, otherwise Nix requires binfmt emulation just to build disk images that will run inside the VM anyway.
1 parent 4f5e499 commit c0a5382

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

lib/runners/qemu.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ let
1414
configureFlags = oa.configureFlags ++ [
1515
"--enable-libusb"
1616
];
17-
buildInputs = oa.buildInputs ++ (with pkgs; [
18-
libusb1
19-
]);
17+
buildInputs = oa.buildInputs ++ [
18+
vmHostPackages.libusb1
19+
];
2020
});
2121

2222
minimizeQemuClosureSize = pkg: pkg.override (oa: {
@@ -133,7 +133,7 @@ let
133133
host = "hostfwd=${proto}:${host.address}:${toString host.port}-" +
134134
"${guest.address}:${toString guest.port},";
135135
guest = "guestfwd=${proto}:${guest.address}:${toString guest.port}-" +
136-
"cmd:${pkgs.netcat}/bin/nc ${host.address} ${toString host.port},";
136+
"cmd:${vmHostPackages.netcat}/bin/nc ${host.address} ${toString host.port},";
137137
}.${from}) forwardPorts;
138138

139139
writeQmp = data: ''

nixos-modules/microvm/boot-disk.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ in {
2121
};
2222

2323
config = lib.mkIf config.microvm.guest.enable {
24-
microvm.bootDisk = pkgs.runCommandLocal "microvm-bootdisk.img" {
25-
nativeBuildInputs = with pkgs; [
24+
microvm.bootDisk = pkgs.buildPackages.runCommandLocal "microvm-bootdisk.img" {
25+
nativeBuildInputs = with pkgs.buildPackages; [
2626
parted
2727
libguestfs
2828
];
29-
LIBGUESTFS_PATH = pkgs.libguestfs-appliance;
29+
LIBGUESTFS_PATH = pkgs.buildPackages.libguestfs-appliance;
3030
} ''
3131
# kernel + initrd + slack, in sectors
3232
EFI_SIZE=$(( ( ( $(stat -c %s ${kernelPath}) + $(stat -c %s ${initrdPath}) + 16 * 4096 ) / ( 2048 * 512 ) + 1 ) * 2048 ))

nixos-modules/microvm/store-disk.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ in
6464
config.microvm.storeDiskType
6565
];
6666

67-
microvm.storeDisk = pkgs.runCommandLocal "microvm-store-disk.${config.microvm.storeDiskType}" {
67+
microvm.storeDisk = pkgs.buildPackages.runCommandLocal "microvm-store-disk.${config.microvm.storeDiskType}" {
6868
nativeBuildInputs = [
6969
pkgs.buildPackages.time
7070
pkgs.buildPackages.bubblewrap

0 commit comments

Comments
 (0)