Commit Graph

420 Commits

Author SHA1 Message Date
Aliaksandr
9921d05da3 treewide: replace stdenv.is* with stdenv.hostPlatform.is*
Assisted-by: claude-code with claude-opus-4-8
2026-08-12 20:27:00 +02:00
Maximilian Bosch
d9befc6484 nixos/test-driver: fix deprecation behavior
We have a lot of changes in the style of

    def foo(
      self,
      new: dt.timedelta | None = None,
      old: float | None = None,
    )

which is OK for cases where the API is used as

    foo(old=23.5)

however for named arguments that actually falls short in the `ty`-stage:

    foo(23.5)

As a workaround I flipped the order of old/new and changed the type of
`old` to accept both a timedelta and the old type, i.e.

    def foo(
      self,
      old: float | dt.timedelta | None = None,
      new: dt.timedelta | None = None,
    )

and only give a deprecation warning if `old` is not of type `dt.timedelta | None`.

That way, both

    foo(old=23.5)
    foo(23.5)

are still accepted, at the same time, both

    foo(new=timedelta(...))
    foo(timedelta(...))

are OK.
2026-08-07 15:52:09 +02:00
jtrrll
f31483b7b2 nixos/test-driver: use timedelta for timeouts and durations 2026-08-05 10:07:38 -04:00
Peter Bynum
50ec0c0d9b nixos-test-driver: Drop temporary directory in copy_from_machine 2026-07-23 09:50:36 -04:00
lassulus
3018f55da9 nixos-test-driver: reintroduce --test-script flag (#533988) 2026-07-20 14:30:44 +00:00
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
a-kenji
aaba92e0cc nixos-test-driver: reintroduce --test-script flag
Restore the ability to pass a test script on the command line through:
```
--test-script [PATH]
```
which was possible prior to its removal in: f1bcb61731

I have found the flag to be quite practical for NixOS test iteration and propose
hereby to reintroduce it again.

While it is still possible without this flag to pass an external test
script, it now needs to be done through the indirection of a `--config`
configuration file - which now has to have configuration which points towards
the test script, which adds enough friction as to not make it ergonomic anymore.

The `--test-script` flag overwrites the configuration from the test config.
2026-06-21 20:34:53 +02: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 bcb6399e15.
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](dd51e81af9/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