Commit graph

81 commits

Author SHA1 Message Date
Peder Bergebakken Sundt
c77ac9dfc3 treewide: fix typos 2025-06-02 16:07:07 +02:00
Robert Hensing
eed414caf1
Fix running NixOS tests on darwin (#405599) 2025-05-15 09:47:30 +02:00
Maximilian Bosch
c6978e8a58
nixos/test-driver: exit early if /dev/vhost-vsock isn't available
Right now it wrongly seems as if you can set
`sshBackdoor.enable = true;` for each test and not only for debugging
purposes.

This is wrong however since you'd need to pass /dev/vhost-vsock into the
sandbox for this (which is also a prerequisite for #392117).

To make that clear, two things were changed:

* add a warning to the manual to communicate this.
* exit both interactive and non-interactive driver early if
  /dev/vhost-vsock is missing and the ssh backdoor is enabled.

  If that's the case, we pass a CLI flag to the driver already in the
  interactive case. This change also sets the flag for the
  non-interactive case.

  That way we also get a better error if somebody tries to enable this
  on a system that doesn't support that.
2025-05-13 11:14:13 +02:00
Maximilian Bosch
b8b86834b7
nixos/test-driver: move sshBackdoor cfg from test-instrumentation to driver
That way, we don't need to duplicate the sshBackdoor options on NixOS-level.

Suggested-by: Jacek Galowicz <jacek@galowicz.de>
2025-05-10 10:40:35 +02:00
Maximilian Bosch
12c544e008
nixos/testing: improve wording of vsockOffset description
Co-authored-by: Jacek Galowicz <jacek@galowicz.de>
2025-05-10 10:28:44 +02:00
Robert Hensing
ee83bfa879 nixos/testing: Drop darwin from default hydraPlatforms
Litmus test: the following attribute disappears

    nix eval -f pkgs/top-level/release.nix tests.testers.nixosTest-example.x86_64-darwin.outPath
2025-05-09 19:25:46 +02:00
Robert Hensing
0433bf6a90 nixos/testing/meta.nix: lib.mkOption -> mkOption 2025-05-09 16:27:05 +02:00
Robert Hensing
51d915e451 nixos/testing: Add meta.hydraPlatforms 2025-05-09 16:27:05 +02:00
Robert Hensing
18e2327aa7 Revert "nixos/lib/testing: avoid generating darwin VM tests"
This reverts commit 72155225aa.
2025-05-09 16:00:18 +02:00
Maximilian Bosch
a9adfc631a
nixos/test-driver: allow assigning other vsock number ranges
I'm a little annoyed at myself that I only realized this _after_ #392030
got merged. But I realized that if something else is using AF_VSOCK or
you simply have another interactive test running (e.g. by another user
on a larger builder), starting up VMs in the driver fails with

    qemu-system-x86_64: -device vhost-vsock-pci,guest-cid=3: vhost-vsock: unable to set guest cid: Address already in use

Multi-user setups are broken anyways because you usually don't have
permissions to remove the VM state from another user and thus starting
the driver fails with

    PermissionError: [Errno 13] Permission denied: PosixPath('/tmp/vm-state-machine')

but this is something you can work around at least.

I was considering to generate random offsets, but that's not feasible
given we need to know the numbers at eval time to inject them into the
QEMU args. Also, while we could do this via the test-driver, we should
also probe if the vsock numbers are unused making the code even more
complex for a use-case I consider rather uncommon.

Hence the solution is to do

    sshBackdoor.vsockOffset = 23542;

when encountering conflicts.
2025-05-09 11:54:00 +02:00
Jacek Galowicz
8b3baa1402
nixos/test-driver: add backdoor based on systemd-ssh-proxy & AF_VSOCK (#392030) 2025-05-09 08:03:55 +02:00
Maximilian Bosch
8869265f93
nixos/test-driver: printout instructions on how to connect via AF_VSOCK 2025-05-08 10:51:39 +02:00
Vladimír Čunát
1a41b5c78e
nixos/lib/testing: avoid generating darwin VM tests (#393977) 2025-04-27 09:29:26 +02:00
Maximilian Bosch
b1394ba443
nixos/test-driver: improve wording of the enable option of SSH backdoor
Co-authored-by: Ryan Lahfa <masterancpp@gmail.com>
2025-04-26 12:20:10 +02:00
Maximilian Bosch
1bd8073958
nixos/test-driver: add backdoor based on systemd-ssh-proxy & AF_VSOCK
With this it's possible to trivially SSH into running machines from the
test-driver. This is especially useful when running VM tests
interactively on a remote system.

This is based on `systemd-ssh-proxy(1)`, so there's no need to configure
any additional networking on the host-side.

Suggested-by: Ryan Lahfa <masterancpp@gmail.com>
2025-04-26 11:35:47 +02:00
Silvan Mosberger
374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Vladimír Čunát
72155225aa
nixos/lib/testing: avoid generating darwin VM tests
We're getting 2x5 darwin VM jobs that aren't schedulable
on our current Hydra.nixos.org, which makes them hang around
and delay advancing of all `nixpkgs-*` channels.
To me that's quite an annoying effect, as it can be like an extra day
of additional delay without any benefit that I can really perceive.
(unless someone like me keeps manually cancelling the jobs all the time)
2025-03-29 19:32:31 +01:00
Silvan Mosberger
4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00
Will Fancher
37ee6ba681 Revert "NixOS apply script"
Reverts #344407

This has broken nixos-rebuild switch so that it no longer updates the profile, which has bad consequences including not updating the systemd-boot menu with new generations.
2024-11-01 20:18:09 -04:00
Robert Hensing
7902cea1de nixos: Update documentation to refer to bin/apply 2024-10-30 00:21:21 +01:00
Sandro Jäckel
729a6f3bd7
nixos/lib/testing: remove alias usage 2024-10-26 14:30:45 +02:00
Robert Hensing
729225e355 treewide: lib.isInOldestRelease -> lib.oldestSupportedReleaseIsAtLeast 2024-10-08 11:14:24 +02:00
K900
2bc5aac960 nixos/lib/testing: enable stc by default for installBootLoader VMs 2024-09-12 15:44:02 +03:00
K900
4cfbbb3c1d nixos/tests: don't include switch-to-configuration in DUT by default 2024-09-08 17:04:44 +03:00
Frédéric Christ
c6f6c28218 nixos/testing: Add ipv6 configuration
This contribution enables a working IPv6 setup by default. This works
analog to the current automatic IPv4 setup.
2024-07-18 10:22:32 +02:00
Donovan Glover
4afa9444ae
nixos/testing: fix markdown link in enableOCR description 2024-05-14 21:22:09 -04:00
Jacek Galowicz
8d3a38e8b1 NixOS Integration tests: Re-enable for macOS 2024-04-12 13:41:27 +02:00
Cole Helbling
dbc967d14d Revert "NixOS Integration Tests: Enable again for darwin" 2024-04-10 12:52:12 -07:00
Jacek Galowicz
e4bf075cff NixOS Integration Tests: Enable again for darwin 2024-04-10 17:59:11 +02:00
K900
7b602cff5c nixos/tests/installer: avoid create_machine, clean up
- use normal VM nodes for target, with some extra trickery
- rename preBootCommands to postBootCommands to match its actual intent
- rename VMs to installer and target, so they're not all called machine
- set platforms on non-UEFI tests properly
- add missing packages for systemd-boot test
- fix initrd secrets leaking into the store and having wrong paths
2024-04-03 16:16:11 +03:00
Philip Taron
ebde306504
nixos/lib, doc: remove references to mdDoc (#300738)
* doc: remove references to mdDoc in nixos/doc/manual/development/option-declarations.section.md

* nixos/lib: remove mdDoc in nixos/lib/make-options-doc/default.nix

* nixos/lib: remove mdDoc in nixos/lib/systemd-types.nix

* nixos/lib: remove mdDoc in nixos/lib/systemd-unit-options.nix

* nixos/lib: remove mdDoc in nixos/lib/testing/driver.nix

* nixos/lib: remove mdDoc in nixos/lib/testing/interactive.nix

* nixos/lib: remove mdDoc in nixos/lib/testing/meta.nix

* nixos/lib: remove mdDoc in nixos/lib/testing/name.nix

* nixos/lib: remove mdDoc in nixos/lib/testing/network.nix

* nixos/lib: remove mdDoc in nixos/lib/testing/nodes.nix

* nixos/lib: remove mdDoc in nixos/lib/testing/run.nix

* nixos/lib: remove mdDoc in nixos/lib/testing/testScript.nix
2024-04-01 16:58:23 -07:00
Gabriella Gonzalez
b8698cd8d6
macOS support for NixOS tests (#282401)
Closes #193336
Closes #261694
Related to #108984

The goal here was to get the following flake to build and run on
`aarch64-darwin`:

```nix
{ inputs.nixpkgs.url = <this branch>;

  outputs = { nixpkgs, ... }: {
    checks.aarch64-darwin.default =
      nixpkgs.legacyPackages.aarch64-darwin.nixosTest {
        name = "test";

        nodes.machine = { };

        testScript = "";
      };
  };
}
```

… and after this change it does.  There's no longer a need for the
user to set `nodes.*.nixpkgs.pkgs` or
`nodes.*.virtualisation.host.pkgs` as the correct values are inferred
from the host system.
2024-03-02 06:33:14 +01:00
K900
d93db9066a nixos/lib/testing: remove yet another source of unnecessary test rebuilds 2024-02-27 23:35:05 +03:00
K900
bde7471aa2 nixos/lib/testing: remove another source of unnecessary test rebuilds 2024-02-27 18:00:58 +03:00
Robert Hensing
ae5cb919f5 nixos/testing/nodes: Do allow aliases
Aliases exist for a reason. Sure it is nice to make sure that
some aliases aren't used within Nixpkgs, but this creates two problems
which are far worse than your failing to meet your neatness compulsions.

- Users encounter missing attributes, https://github.com/NixOS/nixpkgs/issues/264577
  wasting their time, stalling their progress, and even occupying others
  time that would be better spent on fixing *real* issues.

- Hydra doesn't treat evaluation errors seriously enough, with the
  effect that actual relevant test failures are masked by evaluation
  failures such as those caused by this no aliases business.

- We don't even have the infrastructure to get rid of aliases, because
  all warnings in package attributes are disallowed by Nixpkgs CI
  tooling, last I checked.

Before re-disabling this, make sure that

- An actually helpful deprecation process is in place.

- Aliases are still allowed when `nixos-lib.runTests` and
  `pkgs.testers.runNixOSTest` are invoked by external projects.
  For instance, `all-tests.nix` could provide such an
  override (e.g. with `newScope`).
2023-11-06 12:30:28 +01:00
Raito Bezarius
a0dc17bd57 nixos/lib/testing/run: expose rawTestDerivation
For `testBuildFailure` and similar functions, we need a full blown derivation and not a lazy one.
This is an internal option for test framework developers.
2023-10-29 12:45:00 +01:00
Raito Bezarius
d4d7550108 nixos/test-driver: provide a global timeout
Since the debut of the test-driver, we didn't obtain
a race timer with the test execution to ensure that tests doesn't run beyond
a certain amount of time.

This is particularly important when you are running into hanging tests
which cannot be detected by current facilities (requires more pvpanic wiring up, QMP
API stuff, etc.).

Two easy examples:

- Some QEMU tests may get stuck in some situation and run for more than 24 hours → we default to 1 hour max.
- Some QEMU tests may panic in the wrong place, e.g. UEFI firmware or worse → end users can set a "reasonable" amount of time

And then, we should let the retry logic retest them until they succeed and adjust
their global timeouts.

Of course, this does not help with the fact that the timeout may need to be
a function of the actual busyness of the machine running the tests.
This is only one step towards increased reliability.
2023-10-29 12:45:00 +01:00
K900
80cc25eb51 nixos/testing: fix eval for tests created without make-python-test.nix
We have too many test entrypoints and this is a problem.
2023-10-06 23:52:04 +03:00
K900
8a7282f90b nixosTest: fix tests defined with pkgs.nixosTest 2023-10-06 16:33:15 +03:00
Artturin
053e69578f nixos/testing/driver: Copy cross fix from modules/misc/nixpkgs.nix
f7077ba131

Fixes `error: makeWrapper/makeShellWrapper must be in nativeBuildInputs`

`pkgsCross.aarch64-multiplatform.nixosTests.sway`
2023-09-03 00:19:29 +03:00
Jacek Galowicz
846ad444c7 integration test driver: Auto-generate integration test driver's machine
method documentation of nixos docs from python doc strings
2023-07-10 08:51:52 +02:00
Jacek Galowicz
c97588eedc integration test driver: Adapt test script checking output 2023-07-09 13:57:07 +02:00
Arthur Gautier
18c734d7f2 nixosTest: adds support for lib.extend
When lib overrides were used, before this commit, they would not be made
available in the configuration evaluation of nixosTest's nodes.

Sample code:
``` nix
let
  pkgs = import ./. {
    overlays = [
      (new: old: {
        lib = old.lib.extend (self: super: {
          sorry_dave = builtins.trace "There are no pod bay doors" "sorry dave";
        });
      })
    ];
  };
in
pkgs.testers.nixosTest {
  name = "demo lib overlay";

  nodes = {
    machine = { lib, ... }: {
      environment.etc."got-lib-overlay".text = lib.sorry_dave;
    };
  };

  testScript = { nodes }:
    ''
      start_all()
      machine.succeed('grep dave /etc/got-lib-overlay')
    '';
}
```
2023-06-29 09:13:44 -07:00
Graham Dennis
8e58daad02 nixos/qemu-vm: quoted string reformat 2023-05-24 08:54:22 +10:00
Graham Dennis
93502aa3b1 nixos/qemu-vm: add option for named network interfaces
Adds a new option to the virtualisation modules that enables specifying explicitly named network interfaces in QEMU VMs.
The existing `virtualisation.vlans` option is still supported for cases where the name of the network interface is irrelevant.
2023-05-24 08:54:20 +10:00
Robert Hensing
b0e17891f2 nixos/testing/nodes.nix: Do not rely on disabledModules
It's just not necessary.
2023-05-11 16:24:01 +02:00
Robert Hensing
0f83261f0e nixos/testing: Add node.pkgsReadOnly escape hatch
By adding this option indirection, a test can declare all by itself
that it needs a custom nixpkgs. This is a more convenient way of
going about this when the caller of the test framework receives a
`node.pkgs` unconditionally.
2023-05-11 16:24:01 +02:00
Robert Hensing
f659db7ba2 nixos/testing: Add node.pkgs option
By factoring out this logic, it's easier for other projects to make
use of it this optimization too (and do it correctly).
2023-05-11 16:24:00 +02:00
Robert Hensing
b213791e7e nixos/all-tests.nix: Add readOnlyPkgs module 2023-05-11 16:24:00 +02:00
Robert Hensing
cd358fe24e nixos/all-tests.nix: Set nixpkgs.system 2023-05-10 15:55:09 +02:00