Skip to content

Commit 0752b1b

Browse files
authored
buildInLinuxVM: switch from 9p to virtiofs (#362081)
2 parents 7cf0929 + a8032f7 commit 0752b1b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pkgs/build-support/vm/default.nix

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
, img ? pkgs.stdenv.hostPlatform.linux-kernel.target
66
, storeDir ? builtins.storeDir
77
, rootModules ?
8-
[ "virtio_pci" "virtio_mmio" "virtio_blk" "virtio_balloon" "virtio_rng" "ext4" "unix" "9p" "9pnet_virtio" "crc32c_generic" ]
8+
[ "virtio_pci" "virtio_mmio" "virtio_blk" "virtio_balloon" "virtio_rng" "ext4" "unix" "virtiofs" "crc32c_generic" ]
99
}:
1010

1111
let
@@ -123,7 +123,7 @@ rec {
123123
124124
echo "mounting Nix store..."
125125
mkdir -p /fs${storeDir}
126-
mount -t 9p store /fs${storeDir} -o trans=virtio,version=9p2000.L,cache=loose,msize=131072
126+
mount -t virtiofs store /fs${storeDir}
127127
128128
mkdir -p /fs/tmp /fs/run /fs/var
129129
mount -t tmpfs -o "mode=1777" none /fs/tmp
@@ -132,7 +132,7 @@ rec {
132132
133133
echo "mounting host's temporary directory..."
134134
mkdir -p /fs/tmp/xchg
135-
mount -t 9p xchg /fs/tmp/xchg -o trans=virtio,version=9p2000.L,msize=131072
135+
mount -t virtiofs xchg /fs/tmp/xchg
136136
137137
mkdir -p /fs/proc
138138
mount -t proc none /fs/proc
@@ -222,8 +222,10 @@ rec {
222222
${if (customQemu != null) then customQemu else (qemu-common.qemuBinary qemu)} \
223223
-nographic -no-reboot \
224224
-device virtio-rng-pci \
225-
-virtfs local,path=${storeDir},security_model=none,mount_tag=store \
226-
-virtfs local,path=xchg,security_model=none,mount_tag=xchg \
225+
-chardev socket,id=store,path=virtio-store.sock \
226+
-device vhost-user-fs-pci,chardev=store,tag=store \
227+
-chardev socket,id=xchg,path=virtio-xchg.sock \
228+
-device vhost-user-fs-pci,chardev=xchg,tag=xchg \
227229
''${diskImage:+-drive file=$diskImage,if=virtio,cache=unsafe,werror=report} \
228230
-kernel ${kernel}/${img} \
229231
-initrd ${initrd}/initrd \
@@ -259,6 +261,8 @@ rec {
259261
cat > ./run-vm <<EOF
260262
#! ${bash}/bin/sh
261263
''${diskImage:+diskImage=$diskImage}
264+
${pkgs.virtiofsd}/bin/virtiofsd --xattr --socket-path virtio-store.sock --sandbox none --shared-dir "${storeDir}" &
265+
${pkgs.virtiofsd}/bin/virtiofsd --xattr --socket-path virtio-xchg.sock --sandbox none --shared-dir xchg &
262266
${qemuCommand}
263267
EOF
264268
@@ -339,7 +343,7 @@ rec {
339343
args = ["-e" (vmRunCommand qemuCommandLinux)];
340344
origArgs = args;
341345
origBuilder = builder;
342-
QEMU_OPTS = "${QEMU_OPTS} -m ${toString memSize}";
346+
QEMU_OPTS = "${QEMU_OPTS} -m ${toString memSize} -object memory-backend-memfd,id=mem,size=${toString memSize}M,share=on -machine memory-backend=mem";
343347
passAsFile = []; # HACK fix - see https://github.com/NixOS/nixpkgs/issues/16742
344348
});
345349

0 commit comments

Comments
 (0)