142 Commits
Author SHA1 Message Date
Maximilian Bosch 93b2178163 nixos/testing: allow meta.teams in tests, fix maintainer pings for tests
With this patch I essentially get the expected list of maintainers for changes in
nixos-tests.

The downside of this approach is that the CI facility assumes that
there's at most a single definition of `meta.maintainers`, however it
can be more in a module-system context.

For simplicity, just use the first definition location for the time
being.

Verified with

    let
      lib = import ./lib;
      maintainers = import ./ci/eval/compare/maintainers.nix { inherit lib; };
    in
    maintainers {
      changedFiles = [
	"nixos/tests/matrix/matrix-authentication-service.nix"
      ];
      affectedAttrPaths = map (lib.splitString ".") [
	"nixosTests.matrix-authentication-service"
      ];
    }
2026-07-10 16:29:13 +02:00
K900 caea65bc86 Merge remote-tracking branch 'origin/master' into staging-next 2026-06-27 17:13:58 +03:00
Emily c11129861a nixos/testing: drop x86_64-darwin support 2026-06-26 07:55:10 +01:00
Maximilian BoschandGitHub 534768de33 nixos-test-driver: drop unneeded qemu dep (#523313) 2026-06-25 22:56:27 +00:00
Martin Weinelt be9a0ac992 nixos/test-driver: properly tokenize udev rule
When running a container test the udev linter complains, that tokens
should be separate by a comma followed by a space.
2026-06-20 20:19:18 +02:00
Doron Behar 48995a6ef9 nixos/virtualisation: (Aarch64) remove -device virtio-gpu-pci
In 9e78baf, Aarch64 machines were added the `-device virtio-gpu-pci`
argument, to mirror `-vga std` option that was added unconditionally to
virtualised x86_64 machines. This also enabled screenshots on aarch64
machines to be taken in tests. Since then, in a7ca287, the `-vga std`
option was removed, because that is the default value of this option
embedded in QEMU since version 2.2.

Removing it from the hard-coded list of qemu options makes it possible
for the user to choose their own `-vga` value. Similarly, for Aarch
virtualised machines, choosing unconditionally the `-device virtio-gpu-pci`
option instead of e.g `-device virtio-gpu-gl-pci`, can be bothersome too - see:

https://discourse.nixos.org/t/test-an-aarch64-linux-vm-wayland-compositor-from-an-x86-64-linux-host/77416/2

This commit is similar to 44c6c2ef16 which
was reverted in #527048.
2026-06-03 13:50:32 +03:00
Philip Munksgaard 8e5d6f456d nixos/test-driver: add defaultText to pythonTestDriverPackage
After d95261b435, the following flake.nix fails:

```nix
{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  outputs = { nixpkgs, ... }: {
    nixosConfigurations.demo = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ({ lib, ... }: {
          boot.loader.grub.enable = false;
          fileSystems."/" = { device = "none"; fsType = "tmpfs"; };
          nixpkgs.config.packageOverrides =
            lib.mkIf false (_: { });
        })
      ];
    };
  };
}
```

This is the error:

```
$ nix build /tmp/tmp.vWEVitTgK9/#nixosConfigurations.demo.config.system.build.toplevel
evaluation warning: system.stateVersion is not set, defaulting to 26.05. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion.
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:37:12:
           36|
           37|   strict = derivationStrict drvAttrs;
             |            ^
           38|

       … while evaluating derivation 'nixos-system-nixos-26.05.20260409.4c1018d'
         whose name attribute is located at /nix/store/anvdcc2arw7kqrvwnidvhw6ypkkvws68-source/pkgs/stdenv/generic/make-derivation.nix:541:11

       … while evaluating attribute 'buildCommand' of derivation 'nixos-system-nixos-26.05.20260409.4c1018d'
         at /nix/store/anvdcc2arw7kqrvwnidvhw6ypkkvws68-source/nixos/modules/system/activation/top-level.nix:64:7:
           63|       passAsFile = [ "extraDependencies" ];
           64|       buildCommand = systemBuilder;
             |       ^
           65|

       … while evaluating the option `environment.etc.dbus-1.source':

       … while evaluating the default value of option `pythonTestDriverPackage`

       … while evaluating the module argument `hostPkgs' in "/nix/store/anvdcc2arw7kqrvwnidvhw6ypkkvws68-source/nixos/lib/testing/driver.nix":

       … noting that argument `hostPkgs` is not externally provided, so querying `_module.args` instead, requiring `config`

       … while evaluating the option `hostPkgs':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: The option `hostPkgs' was accessed but has no value defined. Try setting the option.
```

Setting a `defaultText` fixes the issue.

I've also added a regression test under `nixos/tests/nixos-test-driver/` and
fixed a typo in the option description ("implemetnation").
2026-05-29 11:17:25 +02:00
Jacek Galowicz cdb35b67b3 nixos-test-driver: drop unneeded qemu dep 2026-05-23 21:40:22 +02:00
zowoqandJeremy Fleischman 9e0eff34c5 nixos/test-driver: change run name to distinguish between different kinds of tests
Co-Authored-By: Jeremy Fleischman <me@jfly.fyi>
2026-05-22 19:24:35 +10:00
Jared Baur 68e2e2bde3 nixos/test-driver: fix eval with noUserModules
When "non-user" modules are not placed in baseModules or
extraModules (arguments of eval-config.nix), noUserModules.evalModules
breaks if the options defined in those modules are consumed. In order
to restore noUserModules functionality for NixOS VM (and now nspawn)
tests, the modules implementing test behavior are moved to baseModules.
2026-05-09 18:31:52 -07:00
nixpkgs-ci[bot]andGitHub 1debf4679f Merge master into staging-nixos 2026-05-04 18:34:56 +00:00
Jacek Galowicz 5b78f85154 nixos-test-driver: don't make warnings in the linter errors at this
point
2026-05-02 15:40:03 +02:00
79100aff14 nixos/test-driver: fix duplicate names in type check
ignore the NixOS configuration's hostname and only use the test driver
attribute for the type hints. This allows for setting a different host
name than the node name in the test without trigggering type errors in
the typecheck phase.

co-authored-by: phanirithvij <phanirithvij2000@gmail.com>
2026-05-02 15:40:03 +02:00
Jacek GalowiczandJacek Galowicz 392f3f8fc1 nixos-test-driver: Use ty anf ruff instead of mypy and pyflakes 2026-05-02 15:40:02 +02:00
Michael Daniels 2e87c2f8f4 nixos/*: remove unused let bindings
Generated using deadnix (with some manual work); split from #514611.
2026-05-01 20:39:14 -04:00
Jacek Galowicz 133e3555ff nixos-test-driver: only use sharedMemory qemu config setting on linux 2026-04-23 11:09:46 +01:00
Jacek Galowicz 6668b5b381 nixos-test-driver: use hostPkgs to write config files to store 2026-04-23 11:09:45 +01:00
Jacek Galowicz 1ecef5cad6 nixos-test-driver: require "/dev/net" in tests that need containers 2026-04-20 18:35:34 +01: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 GalowiczandGitHub b9ca7eaae0 nixos/test-driver: Hide vde switch log messages (#509488) 2026-04-15 18:20:27 +00:00
Jacek GalowiczandGitHub 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 28a450372a nixos/testing: allow setting test-wide warnings and assertions
This allows us to e.g. use `mkRemovedOptionModule` which will come in
handy in the upcoming commits.
2026-04-15 15:45:32 +01:00
Michael Schneider 5f5734db9d nixos/test-driver: add option to force kvm use 2026-04-15 12:15:00 +01:00
Michael Schneider 45e2f9a67e nixos/test-driver: use log levels 2026-04-14 10:09:15 +01:00
Jacek Galowicz d95261b435 nixos-test-driver: Make overridable 2026-03-26 13:58:05 +01:00
Jörg ThalheimandGitHub 5e3302e01c nixos/testing: fix testScript eval for functions without elipsis (#501599) 2026-03-21 15:12:08 +00:00
Jörg Thalheim 00f5ae0602 nixos/testing: fix testScript eval for functions without ...
The nspawn container support (23f1e6370d) added a `containers`
argument to the testScript caller. This breaks tests whose testScript
uses strict pattern matching without ellipsis, e.g. `{ nodes }:`,
since Nix rejects unexpected arguments.

Use `builtins.intersectAttrs` to only pass arguments the function
actually expects, making the caller forward-compatible with future
argument additions.

Fixes: 23f1e6370d ("nixos/test-driver: add support for nspawn containers")
2026-03-21 16:05:53 +01:00
Kierán Meinhardt 4e91a4a0f3 nixos/doc: document systemd-nspawn test containers 2026-03-19 12:14:51 +01:00
Kierán Meinhardtandcinereal 01d5f7a0d9 nixos/test-driver: pass containers to tests
Co-authored-by: cinereal <cinereal@riseup.net>
2026-03-18 09:21:28 +01:00
Kierán MeinhardtandKieran Meinhardt 8615a25cbe nixos/test-driver: make /etc/hosts VLAN-aware with primary IP fallback
Resolves an issue where nodes on shared secondary VLANs could not reach
each other if their primary IPs were on isolated networks.
2026-03-16 13:56:02 +01:00
Kierán Meinhardt 7f6ea2a15f nixos/test-driver: make /etc/hosts resolution VLAN-aware
Filter /etc/hosts entries by shared VLANs to ensure nodes resolve to
reachable interface addresses.
2026-03-04 16:48:57 +01:00
Kierán Meinhardt e4df4c2b1d nixos/test-driver: disable DHCP in nspawn containers 2026-03-03 16:32:02 +01:00
Kierán Meinhardt 184674895e nixos/test-driver: remove systemd dependency if no containers are configured 2026-03-03 16:32:01 +01:00
Kierán Meinhardt 0d1a353600 nixos/test-driver: provide all machines from read-only allMachines option 2026-03-03 16:32:00 +01:00
Kierán Meinhardt 8e0487c5a3 nixos/test-driver: use systemd container interface for SSH backdoor 2026-02-06 17:05:35 +01:00
Kierán Meinhardt 1dbb1741f2 nixos/test-driver: improve overlapping machine name warning 2026-01-28 11:28:33 +01:00
Kierán MeinhardtandJeremy Fleischman 23f1e6370d nixos/test-driver: add support for nspawn containers
Co-authored-by: Jeremy Fleischman <jeremyfleischman@gmail.com>
2026-01-28 11:28:32 +01:00
Kierán MeinhardtandJeremy Fleischman 799cafcc23 nixos/test-driver: refactor Machine to BaseMachine and QemuMachine
This prepares the driver for non-QEMU backends by abstracting
the machine logic.

Co-authored-by: Jeremy Fleischman <jeremyfleischman@gmail.com>
2026-01-28 11:28:32 +01:00
Dyego Aurélio 28096cc5e3 treewide: apply nixfmt 1.2.0 2026-01-22 18:37:56 -03:00
Jeremy FleischmanandKierán Meinhardt 4bd5482aa6 nixos/nspawn-container: init a new nspawn-container profile
This shares a lot in common with the
<nixos/modules/virtualisation/nixos-containers.nix> infrastructure, but
is designed to behave like our `qemu-vm.nix` profile (provides a lot of
the same `virtualisation.*` options, produces a simple script you can
run).

This lays the groundwork to be able to rework the nixos test
infrastructure to allow for containers as well as qemu nodes. That work
isn't quite done yet, but if you want more context, you can see the
followup work in <https://github.com/applicative-systems/nixpkgs/compare/nspawn-container-profile...applicative-systems:nixpkgs:nixos-test-containers>.

Credit due to the [Clan.lol](https://clan.lol/) team for first
implementing this. I'm just cleaning it up and making it play nicely
with upstream.

To try it out, create a `demo.nix`:

```nix
let
  pkgs = import ./. { };
  mkContainer =
    {
      nodeNumber,
      vlans,
    }:
    pkgs.nixos (
      {
        config,
        modulesPath,
        pkgs,
        lib,
        ...
      }:
      let
        interfaces = lib.attrValues config.virtualisation.allInterfaces;

        # Automatically assign IP addresses to requested interfaces.
        assignIPs = lib.filter (i: i.assignIP) interfaces;
        ipInterfaces = lib.forEach assignIPs (
          i:
          lib.nameValuePair i.name {
            ipv4.addresses = [
              {
                address = "192.168.${toString i.vlan}.${toString nodeNumber}";
                prefixLength = 24;
              }
            ];
          }
        );
      in
      {
        imports = [ "${modulesPath}/virtualisation/nspawn-container" ];
        users.users.root.password = "";

        networking.hostName = "c${toString nodeNumber}";
        virtualisation.vlans = vlans;
        networking.interfaces = lib.listToAttrs ipInterfaces;

        environment.systemPackages = [ pkgs.neovim ];
        system.stateVersion = lib.trivial.release;
      }
    );
in
{
  container1 = mkContainer {
    nodeNumber = 1;
    vlans = [ 1 ];
  };
  container2 = mkContainer {
    nodeNumber = 2;
    vlans = [ 2 ];
  };
  container12 = mkContainer {
    nodeNumber = 12;
    vlans = [
      1
      2
    ];
  };
}
```

Build and run the machines in separate terminals (unfortunately,
`systemd-nspawn` requires `sudo`):

```console
$ sudo $(nix-build ./demo.nix -A container1.config.system.build.nspawn)/bin/run-c1-nspawn
$ sudo $(nix-build ./demo.nix -A container2.config.system.build.nspawn)/bin/run-c2-nspawn
$ sudo $(nix-build ./demo.nix -A container12.config.system.build.nspawn)/bin/run-c12-nspawn
```

You can log into this machines as `root`, and verify they can ping each
other:

`c1` can ping `c12`:

```
[root@c1:~]# ping 192.168.1.12 -c 1
PING 192.168.1.12 (192.168.1.12) 56(84) bytes of data.
64 bytes from 192.168.1.12: icmp_seq=1 ttl=64 time=0.164 ms
...
```

So can `c2`:

```
[root@c2:~]# ping 192.168.2.12
PING 192.168.2.12 (192.168.2.12) 56(84) bytes of data.
64 bytes from 192.168.2.12: icmp_seq=1 ttl=64 time=0.127 ms
```
2026-01-19 10:36:37 +01:00
NAHO a2ed7e8d88 nixos: remove optional builtins prefixes from prelude functions
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd \
      --exclude doc/manual/release-notes \
      --type file \
      . \
      nixos \
      --exec-batch sed --in-place --regexp-extended "
        s/\<builtins\.($(
          printf '%s\n' "${builtins[@]}" |
            paste --delimiter '|' --serial -
        ))\>/\1/g
      "

    nix fmt
2026-01-15 16:07:55 +01:00
Philip Taron 9d6ee21262 nixos: pass stdenv into qemu-common
We also don't export it from `vmTools` anymore.
2026-01-05 09:57:13 -08:00
Jacek Galowicz 0024056f2b test driver: normalize callpackage call 2025-12-08 21:15:00 +01:00
Wolfgang Walther f2640ee208 top-level: return __splicedPackages 2025-10-31 20:34:05 +01:00
Wolfgang Walther 91a8fee3aa treewide: remove redundant parentheses
Auto-fixed by nixf-diagnose.
2025-10-05 10:52:03 +02:00
Wolfgang Walther 535b720589 Merge branch 'master' into staging-next 2025-07-24 14:27:50 +02:00
Wolfgang Walther 5a0711127c treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00