Case Study
Testing CUDA applications close to production
An embedded AI company wanted to bring their CUDA tests closer to production. Together we enabled GPU testing in the NixOS test driver, both on developer laptops and CI. The community got faster, cheaper tests.
- Industry
- Embedded AI
- Service
- NixOS Integration Testing
- Scope
- Container support for the NixOS test driver, from idea to upstream
- Stack
- NixOS integration tests · systemd-nspawn · CUDA · Python · nixpkgs
Related talks
The goal
Our client builds embedded products that run local AI on NVIDIA hardware using CUDA. Embedded products are typically much more than a single binary: They are full Linux systems that deploy their applications as services. In NixOS, modules wire applications and configuration together into a full systemd process tree.
The client wanted tests that come as close as possible to how the product ships, so the payoff was production-near testing. Those tests should run in the Nix sandbox and behave the same in CI and on a developer’s laptop.
Cost of separate tests
The NixOS test driver is the usually accepted tool for this kind of test. It describes a whole system in a few lines of Nix and runs it in the sandbox. At that time, however, it could only run QEMU virtual machines.
QEMU VMs can use GPUs via PCI passthrough, but passthrough is exclusive. The client wanted to share GPUs between multiple tests on CI builders.
As a result, GPU testing happened outside the test driver, so it stayed further from production than the client wanted. Engineers spent work hours writing custom test scripts that run their CUDA apps in the sandbox. This way, the applications were tested to correctly run with NVIDIA hardware, but these “mini deployments” were something different than their setup as proper services in a real system image, wired up by NixOS modules. Starting from there, the actual deployment became an extra test with no real automation. The closer a test came to the GPU, the further it moved away from the product, and the core benefit was lost.
Consultation
The client approached us, asking how else to do GPU testing in the sandbox. While discussing their use cases and constraints, we realized the right answer was broader than they had asked for: Container tests in the NixOS test driver.
Containers can bind-mount host device nodes (/dev/nvidia0, /dev/nvidiactl, etc.), so several of them can share one GPU.
Even tests without GPU profit from containers:
Startup times would be much faster and their RAM requirements lower.
On top of that, they would run inside normal VMs without KVM or nesting!
We were sure a feature like that would benefit the whole community, and thus would have a strong chance of being accepted into nixpkgs. From our perspective, we could provide the client what they need and benefit the whole community at the same time. A feature accepted and used by the community would also benefit from upstream maintenance. If maintained internally, someone would need to be paid to keep it from bit-rotting over time.
We also identified potential for code reuse, as the Clan project had already written an initial proof of concept for container tests.
The client agreed and contracted us to build and upstream it.
From customer need to community feature
We implemented the feature in a way that could be upstreamed:
systemd-nspawn containers as an additional backend for the test driver’s Python Machine class.
This was a lot of work:
Getting complex changes into nixpkgs takes more than working code, so we redesigned the change until it fit and worked with the people who needed to review it.
Other community members reviewed our pull requests and pointed out further optimization opportunities we would have seen much later if the project had remained private.
The pull request (docs) went through extensive review and was merged in early 2026. Container tests have been part of NixOS since release 26.05.
Switching a test to containers usually takes one word:

VMs stay the right choice when a test needs its own kernel or setuid binaries. NixOS integration tests can now also run both VMs and containers side by side. Our manual lists the advantages and limitations of containers.
Result
The client can now run their CUDA tests in the test driver, also on developer laptops. GPU devices still need to be mapped into the test containers, but with the current implementation, this is a matter of a few configuration lines. CUDA applications now run with the very same NixOS modules that also deploy them later in production, so the tests match the real setup better. The test itself stays small, as this public example with a minimal CUDA program shows:
# file: cuda-test.nix
{
name = "saxpy-cuda-test";
requiredFeatures.cuda = true;
containers.container = { pkgs, ... }: {
# minimal cuda app example
environment.systemPackages = [ pkgs.cudaPackages.saxpy ];
virtualisation.systemd-nspawn.options = [
"--bind=/dev/nvidia-modeset:/dev/nvidia-modeset"
# ...
];
};
testScript = ''
container.start()
output = container.succeed("saxpy 2>&1")
assert "Max error: 0.000000" in output
'';
}
The full example lists the GPU device paths for NVIDIA and AMD hardware.
Engineers can now run relatively production-near scenarios on their own laptops, not only in CI.
Community benefit: Faster, lighter tests for everyone
Most test driver use cases don’t use a GPU. These can now be ported to containers and run faster and cheaper.
How much faster depends on the nature of the test:
- Short tests dominated by boot time gain the most, because containers don’t boot their own kernel. In our workshop demo, two hosts pinging each other took 6.8 seconds with VMs and 2.7 seconds with containers.
- Longer tests doing real work gain less. Here, we have seen improvements of up to 25%.
- Tests with many hosts gain the most on memory. VMs get a gigabyte of RAM each by default, while a hundred containers would easily fit on a laptop.
Infrastructure gets cheaper: VM tests need KVM to run fast. This usually means bare-metal builders or special instances with nested virtualization. Container tests run on ordinary and cheap cloud VMs that cost only a few dollars/euros per month.
Open source
After the merge, others in the community took the feature further:
- Soon after, contributors started migrating nixpkgs tests to containers. Examples: prometheus-exporters, hedgedoc, and php.
- X11 support was already added to containers, removing one of the original limitations, so graphical tests like the Firefox suite can run in containers, too.
Because containers have strong potential to speed up most tests and reduce resource usage, improving the project’s overall CI throughput, the container backend feature gained acceptance across the NixOS infrastructure team. The team rolled out the necessary changes to the Nix builders and ofBorg, so container tests now run on the project’s own infrastructure. Since then, more and more tests have been ported to containers.
None of this would have happened if the development was a private consulting gig behind closed doors. A feature built for one client’s needs became something a whole community keeps improving, and the client gets every follow-up improvement for free.
For everyone who wants to get started, our NixOS test driver manual covers containers, GPU tests, and much more. The background article on the Nixcademy blog goes through the setup.
Value proposition
- CUDA tests now come much closer to production and cover the NixOS modules that deploy the applications, so the core test nearly matches the real deployment.
- Engineers no longer spend hours crafting special sandbox runs that differ from the product.
- GPU tests run on developer laptops, not only in special infrastructure, and a GPU can be shared between tests.
- The client funded the feature once, and the community now helps to maintain and improve it.
- Every NixOS user gets faster tests and can run them on much cheaper machines.
Facing a similar problem?
Talk to our engineersRelated posts
Open source
- GitHub · Docsnixos-test-driver-manual
Hands-on manual for the NixOS test driver: interactive mode, VMs, containers, GPU tests and best practices.



