Repository navigation
nixos/qemu-vm: 9p -> virtiofs - #552774
Conversation
|
That's so amazing! 🎉🎉🎉 |
picnoir
left a comment
There was a problem hiding this comment.
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.
|
Very nice! |
|
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. |
Ah very interesting that's why we don't have to do this UID mapping for 9p because we just patched it into QEMU.
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
left a comment
There was a problem hiding this comment.
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:
- Keep 9pfs for darwin (and accept the risk of regular breakage because the codepath isn't tested by default)
- Drop Darwin entirely and ask people to work with VM builders instead. I've heard there are decent solutions these days, e.g. https://github.com/applicative-systems/vzvm which explicitly mentions that it has nested virtualisation!
|
So this thing https://hydra.nixos.org/job/nixpkgs/staging-next/darwin.linux-builder.aarch64-darwin My understanding of the discussion is that we should simply remove it from the blockers? |
|
Note: this hasn't reached nixpkgs |
It wouldn't eval anymore. See the discussion on: NixOS#552774
|
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. |
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]>
This comment was marked as resolved.
This comment was marked as resolved.
So, since we're using |
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)>.
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)>.
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)>.
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]>
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]>
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.
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
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
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
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, allqemu-vm-*tests andnixos/release-smalltests (~120 tests).Benchmarks
All benchmarks
nixosTests.simple-vmmastervirtiofsnixosTests.systemdmastervirtiofsnixosTests.switchTestmastervirtiofsnixosTests.systemd-networkmastervirtiofsnixosTests.postgresql.postgresql.postgresql_18.postgresql-backup-allmastervirtiofsnixosTests.garage_2.with-3node-replicationmastervirtiofsnixosTests.nginxmastervirtiofsThings done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.