Home Explore Blog Models CI



nixpkgs

4th chunk of `nixos/doc/manual/development/writing-nixos-tests.section.md`
be3757418d09181af0f6ff01b715106f24df62961e64cf2300000001000008ee
        Just as with `overrideAttrs`, an abbreviated form can be used, e.g. `prevAttrs: { /* … */ }` or even `{ /* … */ }`.
        See [`lib.extends`](https://nixos.org/manual/nixpkgs/stable/#function-library-lib.fixedPoints.extends).

`extendNixOS { module = ` *module* `; specialArgs = ` *specialArgs* `; }`
:   Evaluates the test with additional NixOS modules and/or arguments.

    `module`
    :   A NixOS module to add to all the nodes in the test. Sets test option [`extraBaseModules`](#test-opt-extraBaseModules).

    `specialArgs`
    :   An attribute set of arguments to pass to all NixOS modules. These override the existing arguments, as well as any `_module.args.<name>` that the modules may define. Sets test option [`node.specialArgs`](#test-opt-node.specialArgs).

    This is a convenience function for `extend` that overrides the aforementioned test options.

    :::{.example #ex-nixos-test-extendNixOS}

    # Using extendNixOS in `passthru.tests` to make `(openssh.tests.overrideAttrs f).tests.nixos` coherent

    ```nix
    mkDerivation (finalAttrs: {
      # …
      passthru = {
        tests = {
          nixos = nixosTests.openssh.extendNixOS {
            module = {
              services.openssh.package = finalAttrs.finalPackage;
            };
          };
        };
      };
    })
    ```
    :::

`extend { modules = ` *modules* `; specialArgs = ` *specialArgs* `; }`
:   Adds new `nixosTest` modules and/or module arguments to the test, which are evaluated together with the existing modules and [built-in options](#sec-test-options-reference).

    If you're only looking to extend the _NixOS_ configurations of the test, and not something else about the test, you may use the `extendNixOS` convenience function instead.

    `modules`
    :   A list of modules to add to the test. These are added to the existing modules and then [evaluated](https://nixos.org/manual/nixpkgs/stable/index.html#module-system-lib-evalModules) together.

    `specialArgs`
    :   An attribute of arguments to pass to the test. These override the existing arguments, as well as any `_module.args.<name>` that the modules may define. See [`evalModules`/`specialArgs`](https://nixos.org/manual/nixpkgs/stable/#module-system-lib-evalModules-param-specialArgs).

Title: NixOS Test Framework: `extendNixOS` and `extend` for Test Customization
Summary
This chunk details two methods for extending and overriding NixOS tests: `extendNixOS` and `extend`. `extendNixOS` is a convenience function that allows evaluating a test with additional NixOS modules (`module`) and/or special arguments (`specialArgs`). The `module` is added to all test nodes via `extraBaseModules`, and `specialArgs` override existing arguments for all NixOS modules on the nodes. An example demonstrates its use in `passthru.tests` to customize an `openssh` test. The more general `extend` function allows adding new `nixosTest` modules (`modules`) and/or `specialArgs` directly to the test's evaluation, with `extendNixOS` being a specialized version for modifying only the NixOS configurations of the test nodes.