Skip to content

nixos/qemu-vm: 9p -> virtiofs - #552774

Merged
lassulus merged 4 commits into
NixOS:staging-nixosfrom
nikstur:virtiofs
Sep 8, 2026
Merged

lassulus merged 4 commits into
NixOS:staging-nixosfrom
nikstur:virtiofs

Conversation

@nikstur

@nikstur nikstur commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Using virtiofs instead of 9P can give us massive performance boosts (especially for more complex tests). In the best case that I have benchmarked the test is almost 50% faster. Please see the benchmark section for more details.

I successfully ran all systemd.nixosTests, all qemu-vm-* tests and nixos/release-small tests (~120 tests).

Benchmarks

All benchmarks

nixosTests.simple-vm

Branch Mean [s] Min [s] Max [s] Relative
master 18.172 ± 0.908 16.971 20.023 1.00 ± 0.07
virtiofs 18.106 ± 0.894 16.184 19.271 1.00

nixosTests.systemd

Branch Mean [s] Min [s] Max [s] Relative
master 81.203 ± 1.495 79.448 84.075 1.10 ± 0.04
virtiofs 73.871 ± 2.443 69.596 77.700 1.00

nixosTests.switchTest

Branch Mean [s] Min [s] Max [s] Relative
master 272.757 ± 2.953 268.665 279.877 1.44 ± 0.02
virtiofs 189.598 ± 0.804 188.175 191.007 1.00

nixosTests.systemd-network

Command Mean [s] Min [s] Max [s] Relative
master 27.423 ± 2.516 25.605 34.382 1.08 ± 0.10
virtiofs 25.407 ± 0.605 24.185 26.238 1.00

nixosTests.postgresql.postgresql.postgresql_18.postgresql-backup-all

Command Mean [s] Min [s] Max [s] Relative
master 46.737 ± 1.545 45.031 50.475 1.14 ± 0.05
virtiofs 41.164 ± 0.960 40.013 43.197 1.00

nixosTests.garage_2.with-3node-replication

Command Mean [s] Min [s] Max [s] Relative
master 32.814 ± 2.803 30.891 40.080 1.11 ± 0.10
virtiofs 29.595 ± 0.556 28.777 30.448 1.00

nixosTests.nginx

Command Mean [s] Min [s] Max [s] Relative
master 26.674 ± 0.804 25.402 27.740 1.15 ± 0.06
virtiofs 23.255 ± 1.016 21.767 24.928 1.00

Things done

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Aug 14, 2026
@blitz

blitz commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

That's so amazing! 🎉🎉🎉

@nikstur
nikstur marked this pull request as draft August 17, 2026 10:02
@nikstur
nikstur marked this pull request as ready for review August 17, 2026 10:06

@picnoir picnoir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

The diff look good.

Rebuilding all the tests ATM to see if we break more stuff.

Will do a second review pass once I get the results.

@ofborg ofborg Bot added ofborg-internal-error Ofborg encountered an error and removed ofborg-internal-error Ofborg encountered an error labels Aug 17, 2026
Comment thread nixos/tests/hibernate.nix Resolved
@Ma27

Ma27 commented Aug 21, 2026

Copy link
Copy Markdown
Member

Very nice!

@nikstur
nikstur requested a review from arianvp August 23, 2026 19:32
Comment thread nixos/tests/qemu-vm-store.nix Resolved
@Erethon

Erethon commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

I think that with this we can also get rid of an old custom 9pfs patch in qemu and stop applying it [1]

[1]: I only started looking at this patch today because I run into a weird case with microvm.nix and realized it's because of it. I would open a PR to fix it, but I think merging this and getting rid of it completely is the better option.

@nikstur

nikstur commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

I think that with this we can also get rid of an old custom 9pfs patch in qemu and stop applying it [1]

Ah very interesting that's why we don't have to do this UID mapping for 9p because we just patched it into QEMU.

I would open a PR to fix it, but I think merging this and getting rid of it completely is the better option.

Not sure that this is the right thing to do. If we remove this patch we bascially cannot use 9p to share the Nix Store from a sandbox anymore. But let's not have this discussion here. Feel free to open an issue for it.

@Ma27 Ma27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do this.

There's one major issue though: virtiofsd doesn't support Darwin. IMO Darwin is an inferior platform these days and I wouldn't want to sacrifice major speedups for support of that platform. These speedups are not only an improvement to dev experience, but also valuable to NixOS infra (cc @nixos/infra) in terms of speeding up builds.

At the same time, we do explicitly support Darwin currently and I can't just make that call on my own in good faith.

So the question goes to the rest of @NixOS/test-driver: what do you think?

Proposals I see moving forward:

@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Sep 8, 2026
@vcunat

vcunat commented Sep 10, 2026

Copy link
Copy Markdown
Member

So this thing https://hydra.nixos.org/job/nixpkgs/staging-next/darwin.linux-builder.aarch64-darwin
has been a blocking build for the nixpkgs-unstable channel, and this PR made it fail to eval.

My understanding of the discussion is that we should simply remove it from the blockers?

@vcunat

vcunat commented Sep 10, 2026

Copy link
Copy Markdown
Member

Note: this hasn't reached nixpkgs master yet, but it's e.g. in staging-next.

vcunat added a commit to vcunat/nixpkgs that referenced this pull request Sep 10, 2026
It wouldn't eval anymore.  See the discussion on:
NixOS#552774
@vcunat vcunat mentioned this pull request Sep 10, 2026
2 tasks done
@booxter

booxter commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

I'm as excited by virtiofsd gains. But I am (partially) restoring dropped 9p support for Darwin here because unconditional removal broke a lot of workflows: #562444

It would be helpful if you tag @NixOS/darwin-core or @NixOS/darwin-maintainers in similar situations, so that we could chime in on important changes that affect the platform before merge.

holidayworking added a commit to holidayworking/core that referenced this pull request Sep 13, 2026
nixpkgs 02f5696b breaks nix.linux-builder on aarch64-darwin: NixOS/nixpkgs#552774
switched qemu-vm from 9p to virtiofs, but virtiofsd doesn't support darwin.
Fix (NixOS/nixpkgs#562444) isn't merged yet, so pin nixpkgs to aff8a0b (2026-09-10)
until it lands.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fricklerhandwerk

This comment was marked as resolved.

@Erethon

Erethon commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

According to https://www.qemu.org/docs/master/system/devices/virtio/vhost-user.html#shared-memory-object

In order for the daemon to access the VirtIO queues to process the requests it needs access to the guest’s address space. This is achieved via the memory-backend-file, memory-backend-memfd, or memory-backend-shm objects. A reference to a file-descriptor which can access this object will be passed via the socket as part of the protocol negotiation.
Currently the shared memory object needs to match the size of the main system memory as defined by the -m argument.

So, since we're using vhost-fs-user now, we should also enable enableSharedMemory by default? This works for @fricklerhandwerk's reproducer.

@jfly

jfly commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

@Erethon, I actually am working on a PR right now =)

#563324

jfly added a commit to jfly/nixpkgs that referenced this pull request Sep 14, 2026
We recently switched to virtiofs for qemu-vms run on Linux
(NixOS#552774). I suspect we
only tested it with nixos tests, which just [happen to enable shared memory](https://github.com/NixOS/nixpkgs/blob/673028b7b1845fb74dab830518892c917634b95a/nixos/lib/testing/driver.nix#L259)
for the ssh backdoor. However, for folks using qemu-vm.nix outside of nixos
tests, they'll experience virtiofsd crashing with [some very obtuse
messages](https://gitlab.com/virtio-fs/virtiofsd/-/work_items/127).

Reported by @fricklerhandwerk in
<NixOS#552774 (comment)>.
jfly added a commit to jfly/nixpkgs that referenced this pull request Sep 14, 2026
We recently switched to virtiofs for qemu-vms run on Linux
(NixOS#552774). I suspect we
only tested it with nixos tests, which just [happen to enable shared memory](https://github.com/NixOS/nixpkgs/blob/673028b7b1845fb74dab830518892c917634b95a/nixos/lib/testing/driver.nix#L259)
for the ssh backdoor. However, for folks using qemu-vm.nix outside of nixos
tests, they'll experience virtiofsd crashing with [some very obtuse
messages](https://gitlab.com/virtio-fs/virtiofsd/-/work_items/127).

Reported by @fricklerhandwerk in
<NixOS#552774 (comment)>.
jfly added a commit to jfly/nixpkgs that referenced this pull request Sep 14, 2026
We recently switched to virtiofs for qemu-vms run on Linux
(NixOS#552774). I suspect we
only tested it with nixos tests, which just [happen to enable shared memory](https://github.com/NixOS/nixpkgs/blob/673028b7b1845fb74dab830518892c917634b95a/nixos/lib/testing/driver.nix#L259)
for the ssh backdoor. However, for folks using qemu-vm.nix outside of nixos
tests, they'll experience virtiofsd crashing with [some very obtuse
messages](https://gitlab.com/virtio-fs/virtiofsd/-/work_items/127).

Reported by @fricklerhandwerk in
<NixOS#552774 (comment)>.
henrirosten added a commit to henrirosten/dotflake that referenced this pull request Sep 15, 2026
nixpkgs replaced 9p with virtiofs for virtualisation.sharedDirectories
(NixOS/nixpkgs#552774), which removed the securityModel option and
broke evaluation of the generic-vm app.

virtiofsd only maps the unmapped host uid (65534, i.e. root-owned store
files seen from the build sandbox) to root in the guest. With the
single-user Nix install in the flake update smoke job, store files are
owned by the runner user, so auditd refuses its non-root-owned config
and the x1 VM never reaches the running state. Use the default
multi-user install for that job.

Signed-off-by: Henri Rosten <[email protected]>
henrirosten added a commit to henrirosten/dotflake that referenced this pull request Sep 15, 2026
nixpkgs replaced 9p with virtiofs for virtualisation.sharedDirectories
(NixOS/nixpkgs#552774), which removed the securityModel option and
broke evaluation of the generic-vm app.

virtiofsd only maps the unmapped host uid (65534, i.e. root-owned store
files seen from the build sandbox) to root in the guest. With the
single-user Nix install in the flake update smoke job, store files are
owned by the runner user, so auditd refuses its non-root-owned config
and the x1 VM never reaches the running state. Use the default
multi-user install for that job.

Signed-off-by: Henri Rosten <[email protected]>
myme added a commit to myme/dotfiles that referenced this pull request Sep 21, 2026
nixpkgs switched qemu-vm's sharedDirectories from 9p to virtiofs
(NixOS/nixpkgs#552774), calling `hostPkgs.virtiofsd` unconditionally.
virtiofsd is linux-only, so `nix.linux-builder.enable` stopped
evaluating on aarch64-darwin:

  error: Refusing to evaluate package 'virtiofsd-1.14.0' ... because it
  is not available on the requested hostPlatform

NixOS/nixpkgs#562444 keeps virtiofs for linux and falls back to 9p
otherwise, restoring darwin.linux-builder. It landed in nixos-unstable
after the rev this lock pinned.
Ma27 added a commit to Ma27/nixpkgs that referenced this pull request Oct 24, 2026
The issue we were chasing was an number of QEMU VMs being started up in
large tests[1], introduced by the migration from 9pfs to virtiofs[2]. What
happened here was

* When having a large number of VMs (and at least 3x the amount of
  virtiofsd procs), some processes aren't ready for operation leading
  QEMU to fail because the sockets it exposes aren't ready yet.

* The tests hang indefinitely now since the process is dead, but the
  stdout fd is still open as it's used by the virtiofsd processes.

* As a result, the startup logic for a VM in the test-driver assumes the
  VM to be dead and tries to fully read its stdout which hangs since it's
  still used by the virtiofsd procs.

I tried to fix this in pure Bash, but decided to give up since Bash's
job control logic is a hot mess. Also, a naive implementation would
notably slow down the startup of tests since we need a loop for
virtiofsd having set up all sockets before starting QEMU and with
asyncio we can wait on all of them rather than doing all of this
sequentially.

The virtiofsd configuration is passed to the Python script via CLI args
on purpose to still evaluate Bash variables that are sadly part of the
interface.

I think it'd make sense to move more of the start script into this
Python package, but my main goal is to have something ready where we can
be confident that the original bug got fixed. This refactoring can be
done iteratively in follow-ups.

[1] e.g. https://hydra.nixos.org/build/350180953/step/3/log/tail
[2] NixOS#552774
Ma27 added a commit to Ma27/nixpkgs that referenced this pull request Oct 29, 2026
The issue we were chasing was an number of QEMU VMs being started up in
large tests[1], introduced by the migration from 9pfs to virtiofs[2]. What
happened here was

* When having a large number of VMs (and at least 3x the amount of
  virtiofsd procs), some processes aren't ready for operation leading
  QEMU to fail because the sockets it exposes aren't ready yet.

* The tests hang indefinitely now since the process is dead, but the
  stdout fd is still open as it's used by the virtiofsd processes.

* As a result, the startup logic for a VM in the test-driver assumes the
  VM to be dead and tries to fully read its stdout which hangs since it's
  still used by the virtiofsd procs.

I tried to fix this in pure Bash, but decided to give up since Bash's
job control logic is a hot mess. Also, a naive implementation would
notably slow down the startup of tests since we need a loop for
virtiofsd having set up all sockets before starting QEMU and with
asyncio we can wait on all of them rather than doing all of this
sequentially.

The virtiofsd configuration is passed to the Python script via CLI args
on purpose to still evaluate Bash variables that are sadly part of the
interface.

I think it'd make sense to move more of the start script into this
Python package, but my main goal is to have something ready where we can
be confident that the original bug got fixed. This refactoring can be
done iteratively in follow-ups.

[1] e.g. https://hydra.nixos.org/build/350180953/step/3/log/tail
[2] NixOS#552774
@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tweag-nix-dev-update-60/81357/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.