414 Commits

Author SHA1 Message Date
nixpkgs-ci[bot] 1b4836a2ba Merge master into staging-next 2026-07-05 06:14:54 +00:00
Maximilian Bosch 26bafa1f8d nixos/test-driver: deprecate shell_interact() (#535097) 2026-06-29 13:05:59 +00:00
Maximilian Bosch 5da4d05168 nixos/test-driver: keep nspawn notify socket drained after boot (#533429) 2026-06-29 10:33:21 +00:00
K900 caea65bc86 Merge remote-tracking branch 'origin/master' into staging-next 2026-06-27 17:13:58 +03:00
Maximilian Bosch 59249b1624 nixos/test-driver: show deprecation warnings in the REPL
Apparently this wasn't the case before, but now it is

    In [3]: machine.shell_interact()
    ??? Warning (DeprecationWarning): Use the SSH backdoor instead
        File "<ipython-input-3-4e72ea6a987e>", line 1
2026-06-26 12:27:42 +02:00
Maximilian Bosch b9706678ac nixos/test-driver: deprecate shell_interact()
Reviewing #512771 got me thinking and I'm not sure I see a good reason
to keep this method given the SSH backdoor functionality has a much
better UX.

I'd propose we deprecate it, await 26.11 to see if people complain and
remove it alltogether after that.
2026-06-26 12:27:41 +02:00
Maximilian Bosch 534768de33 nixos-test-driver: drop unneeded qemu dep (#523313) 2026-06-25 22:56:27 +00:00
cinereal be55bcfa50 nixos/test-driver: keep nspawn notify socket drained after boot
The nspawn test machine passes a driver-owned AF_UNIX SOCK_DGRAM socket as the
container's NOTIFY_SOCKET (systemd-nspawn --notify-ready=yes). The driver only
drained it while waiting for the initial READY=1 during boot.

A container's PID 1 re-sends READY=1 on every `systemctl daemon-reexec` (the
same Manager.Reexecute that switch-to-configuration issues whenever the systemd
package changed). With nothing draining the socket after boot, its receive
buffer fills and PID 1 blocks in sendmsg() to NOTIFY_SOCKET (wchan
unix_wait_for_peer) while re-executing, so it never finishes re-initializing.
From then on every in-container `systemctl` call hangs or fails with
'Transport endpoint is not connected', which hangs wait_for_unit /
switch-to-configuration for the full timeout. QEMU nodes have no such notify
socket and are unaffected.

Drain the notify socket in a dedicated daemon thread for the container's whole
lifetime so PID 1 never blocks on the re-exec READY=1 send. Readiness and the
leader PID are now read from that thread's state instead of polling the socket
inline during boot.

Assisted-by: Claude:claude-opus-4-8
2026-06-25 23:38:28 +02:00
Arian van Putten 711b692108 nixos/virtualisation/nspawn-container: add virtualisation.credentials support (#535258) 2026-06-25 15:37:09 +00:00
Arian van Putten 612ff7f23c nixos/test-driver: support state_dir for container tests
Assisted-by: Claude <noreply@anthropic.com>
2026-06-25 13:44:57 +02:00
K900 dc0f4cd301 Merge remote-tracking branch 'origin/staging-next' into staging 2026-06-24 16:12:11 +03:00
Maximilian Bosch 1b9913d415 nixos/tests: Load root profile in nspawn tests (#534299) 2026-06-24 08:07:38 +00:00
Nina Fromm 0dc4ca4c71 nixos/tests: Load root profile in nspawn tests
This is currently a hacky workarround, but bettern than nothing until we come up
with a better solution.
2026-06-24 09:36:11 +02:00
K900 3aebc40624 nixos/test-driver: abort if we didn't connect to the backdoor in 5 minutes
This is a lot of minutes, but less than the 1 hour it would normally take
to time out the entire build.
2026-06-23 21:43:33 +03:00
Arthur Gautier 648b2e9555 nixos/test-driver: add utils to manipulate efi variables (#456099) 2026-06-05 16:16:08 +00:00
Arthur Gautier 4e5b779a75 nixos/test-driver: rework timeout for wait_for_console_text
Before this commit, `wait_for_console_text` would read one line every
900ms before trying again to read the next line.

This commit fixes that behavior by greedily reading all buffer that is
available for match trying to find a match rather than reading one per
retry iteration.

In effect this moves the loop inside the `console_matches` helper and
makes the behavior of `wait_for_console_text` with timeout behave the
same way as with timeout.

This also provides a test that showcases the problem.
2026-06-01 19:12:06 -07:00
Arthur Gautier 956eb0479a nixos/test-driver: add utils to manipulate efi variables
```python
machine.create_efi_vars()
machine.write_efi_vars([
    EfiVariable(
        uuid.UUID("65a72bd9-f42b-4039-8084-66cd1702cb24"),
        "AbrNextBoot",
        b"a",
        flags=EfiVariable.Flags.NON_VOLATILE
    )
])

machine.start()
```
2026-05-30 22:22:03 -07:00
Benjamin Sparks e20cd6adb0 nixos-test-driver: adher to select's interface
TL;DR add `assert` to correct location for type-narrowing

typeshed recently updated their definition of `select` in https://github.com/python/typeshed/commit/bcb6399e155cb6444150fe98dfd9c24eb0343016.
The result is that the members of the lists passed to `select` now
require an upper bound of `FileDescriptorLike`.

The `self.shell` variable is typed as `socket | None`, but previously
passed checking against typeshed due to the missing upper-bound.
Despite the source code including a type-narrowing `assert`, `ty` does
not make use of it within the inner function that `select` is used in,
meaning `self.shell` wasn't narrowed at the appropriate place.
Now that typeshed has added this upper-bound, type-checking starts to fail, as evidenced in
https://github.com/NixOS/nixpkgs/pull/523288#issuecomment-4529738483.

So the correct fix is just to add the `assert` into the inner function.
2026-05-28 00:01:49 +02:00
Jacek Galowicz cdb35b67b3 nixos-test-driver: drop unneeded qemu dep 2026-05-23 21:40:22 +02:00
Jeremy Fleischman b0ac1aa864 nixos/test-driver: remove redundant self.pid state from NspawnMachine
We can access it via `self.process`, and this avoids bugs where we
weren't keeping the 2 in sync.
2026-05-22 01:53:43 -07:00
Jeremy Fleischman 11855b765c nixos/test-driver: null out self.pid when shutting down the container
Without this, we end up with `self.pid` set to the pid of a dead
process, and `self.process == None`. This causes us to blow [this
assert](https://github.com/jfly/nixpkgs/blob/dd51e81af9226ee80e6f0891f4649e12ea15dfd0/nixos/lib/test-driver/src/test_driver/machine/__init__.py#L1496)
in `NspawnMachine.release`.

It would probably be cleaner to just get rid of `self.pid`. It's
redundant given that we have `self.process`. I'll do that in a followup
commit.

This was discovered here:
https://github.com/NixOS/nixpkgs/pull/522886#discussion_r3285395646, and
will be protected against future regression by a test introduced in that
PR.
2026-05-22 01:53:43 -07:00
Jacek Galowicz 948c5d0da2 nixos-test-driver: fix vlan/bridge cleanup 2026-05-03 17:45:52 +02:00
Maximilian Bosch 5342316c89 Nixos test driver: Use ty and ruff instead of mypy and pyflakes on test scripts (#509615) 2026-05-03 14:07:49 +00:00
Jacek Galowicz 392f3f8fc1 nixos-test-driver: Use ty anf ruff instead of mypy and pyflakes 2026-05-02 15:40:02 +02:00
Jacek Galowicz 7a50142dfd nixos/test-driver: deprecate referring to the only node via variable machine (#511859) 2026-05-02 11:49:33 +00:00
Maximilian Bosch 9b2a6da44f nixos-test-driver: don't assert on vhost_vsock (#512730) 2026-04-24 09:57:16 +00:00
nixpkgs-ci[bot] 6714212dd9 Merge master into staging-nixos 2026-04-23 18:26:38 +00:00
Vladimír Čunát ea9c3ae589 nixos-test-driver: reduce unnecessary rebuilds for now 2026-04-23 14:43:46 +02:00
Jacek Galowicz 6c0ab2edd5 nixos-test-driver: only depend on vsock things on linux 2026-04-23 11:09:45 +01:00
Jacek Galowicz b35551e838 nixos-test-driver: don't assert on vhost_vsock as tests without VMs
would be just fine without it
2026-04-23 09:43:12 +00:00
Maximilian Bosch 9b42f787bb nixos/test-driver: fix driverInteractive test_script invocation
See https://github.com/NixOS/nixpkgs/pull/510385/changes/BASE..f1bcb61731224bd8440510fc620d3c51f3e51c85
2026-04-21 00:24:25 +02:00
Maximilian Bosch 4c907dbb68 Revert "nixos-test-driver: use info/error/debug log feature more"
This reverts commit a2ff6e406e.

Pushed by accident to staging-nixos: https://matrix.to/#/%21UNVBThoJtlIiVwiDjU%3Anixos.org/%24UUtlLXPAwZaoeDXDT0wHC1PRZIWVhRNNgyvkKTVRG24?via=nixos.org&via=matrix.org&via=tchncs.de
2026-04-20 22:11:01 +02:00
Maximilian Bosch 4797207171 nixos/test-driver: deprecate using machine variable when only VM has a different name
For backwards-compat reason it's legal to do

    runTest {
      nodes.foo = { /* ... */ };
      testScript = ''
        machine.start()
        # do your thing
      '';
    }

This makes several places in the codebase unnecessarily complex and is
something people shouldn't be using anyways. Additionally, I was
reminded by people that this can actually be confusing when you expect
the variable to be named differently.

Hence, deprecate this behavior and kill it in a few releases down the
road.
2026-04-19 20:01:32 +02:00
Jacek Galowicz a2ff6e406e nixos-test-driver: use info/error/debug log feature more 2026-04-19 18:02:46 +01:00
Maximilian Bosch f3b69f2a71 nixos/test-driver: colorized warnings 2026-04-19 12:17:18 +02:00
Michael Daniels ece6acc1e3 nixos-test-driver: fix handling of type-check-disabled case
f1bcb61731 did not handle this correctly,
causing failures (e.g. https://hydra.nixos.org/build/326659503/nixlog/2/tail)
2026-04-18 16:18:17 -04:00
Jacek Galowicz f1bcb61731 nixos-test-driver: use configuration file instead of scattered env vars 2026-04-17 14:55:56 +01:00
Jacek Galowicz b998b489db nixos-test-driver: don't prepare sandbox environemnt outside of sandbox. (#510559) 2026-04-17 13:00:19 +00:00
Jacek Galowicz b55b2eff0f nixos/test-driver: add remaining tests to passthru.tests (#510699) 2026-04-17 11:59:11 +00:00
Michael Schneider df17d7a149 nixos/test-driver: add remaining tests to passthru.tests 2026-04-17 12:35:06 +01:00
Jacek Galowicz 73c3836552 nixos-test-driver: don't prepare sandbox environemnt outside of sandbox 2026-04-16 20:38:52 +01:00
Jacek Galowicz ca0c8d9aa2 nixos-test-driver: Don't document internal methods prefixed with
underscore
2026-04-16 11:55:45 +01:00
Jacek Galowicz c62f8fff2e nixos-test-driver: drop unneeded sentinel object 2026-04-16 11:47:04 +01:00
Jacek Galowicz b9ca7eaae0 nixos/test-driver: Hide vde switch log messages (#509488) 2026-04-15 18:20:27 +00:00
Jacek Galowicz ea044acd82 nixos/test-driver: use vhost-device-vsock for SSH backdoor (#453305) 2026-04-15 18:15:52 +00:00
Michael Schneider b787cf0ca3 nixos/test-driver: Hide vde switch log messages 2026-04-15 18:43:50 +01:00
Maximilian Bosch 1987c483d8 nixos/test-driver: use vhost-device-vsock for SSH backdoor
`vhost-device-vsock`[1] is a custom implementation of AF_VSOCK, but the
application on the host-side uses a UNIX domain-socket. This gives us
the following nice properties:

* We don't need to do `--arg sandbox-paths /dev/vhost-vsock` anymore for
  debugging builds within the sandbox. That means, untrusted users can
  also debug these kinds of tests now.

* This prevents CID conflicts on the host-side, i.e. there's no need for
  using `sshBackdoor.vsockOffset` for tests anymore.

A big shout-out goes to Allison Karlitskaya, the developer of test.thing[2]
who talked about this approach to do AF_VSOCK on All Systems Go 2025.

This patch requires systemd 258[3] because this contains `vhost-mux` in
its SSH config which is needed to connect to the VMs from now on.

To not blow up the patches even more, this only uses AF_VSOCK for the
debugger. A potential follow-up for the future would be a removal of the
current `backdoor.service` and replace it entirely by this
functionality.

The internal implementation tries to be consistent with how VLANs and
machines are handled, i.e. the processes are started when the Driver's
context is entered and cleaned up in __exit__().

I decided to push the process management and creation of sockets for
vhost-device-vsock into its own class, that's an implementation detail
and not a concern for the test-driver. In fact, `vhost-device-vsock` is
something we can drop once QEMU implements native support for using
AF_UNIX on the host-side[4]. `VsockPair` is its own class since
returning e.g. a triple of `(Path, Path, Int)` would be ambiguous in
what is the guest and what the host path (and frankly, I found it hard
to distinguish the two when reading the docs of `vhost-device-vsock`
initially).

Finally, now that we can do the SSH backdoor without adding additional
devices to the sandbox, I figured, it's time to write a test-case for
it.

[1] https://github.com/rust-vmm/vhost-device/blob/main/vhost-device-vsock/README.md
[2] https://codeberg.org/lis/test.thing
[3] https://github.com/NixOS/nixpkgs/pull/427968
[4] https://gitlab.com/qemu-project/qemu/-/issues/2095
2026-04-15 15:45:33 +01:00
Maximilian Bosch 9dcf711303 nixos/test-driver: push allocation into the context-manager
The context manager's purpose is to allocate its resources in `__enter__` and
release them again in `__exit__`.

Right now, the approach is merely a hack since we allocate everything in
the constructor, but use the context-manager protocol as way to reliably
terminate everything.

This isn't a functional change, but merely a correctness change by using
the methods the way they were intended.
2026-04-15 15:45:33 +01:00
Michael Schneider 5f5734db9d nixos/test-driver: add option to force kvm use 2026-04-15 12:15:00 +01:00
Jacek Galowicz bffdf7c2a8 nixos-test-driver: Use ty instead of mypy for test driver package 2026-04-15 12:13:45 +01:00