NixOS 101 Course / Section 6: NixOS integration tests
Premium

6.5 Debugging NixOS tests interactively

Lesson 26 of 28 · 13:27

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Interactive Test Driver Overview
  2. 2:06 Using the Python Shell and VM Console
  3. 4:39 SSH Backdoor and Interactive Configuration
  4. 8:51 Debugging Workflows and Container Caveats
Transcript

Interactive Test Driver Overview

0:00 Another really important feature of the test driver is the interactive mode, which is amazing. In general, each test derivation, regardless if you address it with flakes or not, has a sub-attribute, .driverInteractive, which we can simply build from our test. So let's have a quick look at that. With our test that we had before, we can, instead of running nix-build now, which would in this case just build the default.nix file and then build not only the test driver in the first derivation, but also in the second derivation, actually run it as we have seen earlier and that all happens in the sandbox and offline and everything.

0:42 That means that we cannot really watch the VM do something, or we cannot play around with it. And the test driver is exactly about that. So instead of just building the attribute, we can run .driverInteractive. With the old nix commands, this is capital A as a flag that accesses an attribute, expecting an attribute set, right, and every derivation is an attribute set. Then we can just build the driverInteractive mode, which uses a slightly different QEMU package.

1:16 And then we can say result/bin/nixos-test-driver. And what's amazing about this now, when we run this, we come into a getty-like interface, but that's actually a Python shell. And here we can have auto-completion where we can select machine 1, machine 2, and then we can say machine 1 dot start, where is it, start, and ta-da, the VM pops up in front of our face, like here, but also we can see the normal output as if we're running the test driver normally here in the shell.

The full transcript comes with the lesson.

About this lesson

A test that fails after an hour should not cost you another hour for every fix attempt. This lesson shows the interactive mode of the NixOS test driver: start machines from a Python shell, watch the test run, and log into the machines while they run.

In this video

  • Building driverInteractive and controlling machines from a Python prompt
  • Running the whole test script and inspecting the machines after a failure
  • The SSH backdoor that reaches every VM without any network setup
  • Debug-only settings that never affect your regular test runs
  • What changes when your test machines are containers

After this lesson

When a test fails, you can step into the failing setup and look around instead of guessing from logs.