Compare commits

...

14 Commits

Author SHA1 Message Date
Robert Hensing
e54227b0df Revert "nixosTests: Resolve alias kgx = gnome-console"
This reverts commit a486968a6e.
2023-05-11 15:07:45 +02:00
Robert Hensing
ad048019ad Revert "nixosTests: Resolve use of trivial aliases"
This reverts commit 7e2d8c4ace.
2023-05-11 15:07:42 +02:00
Robert Hensing
20ed39a036 Revert "linuxKernel.packages.linux_stable: init as reference"
This reverts commit 936309cb9b.
2023-05-11 15:07:37 +02:00
Robert Hensing
95e249772f Revert "nixos/release.nix: Pass a pkgs without aliases to tests"
We don't have a good way of adding `allowAliases = false` to an existing
`pkgs`, which means that we can't enable this on `nixosTests.*` because
that would break coherence between `pkgs` as in literally `pkgs.nixosTest`
and the `pkgs` module argument that is available there.

Having a discrepancy between the two means that neither OfBorg nor users
will catch the eval errors that makes tests effectively disappear from
Hydra. This is a Hydra UX issue, not a nixpkgs issue but a blocker
nonetheless.

This reverts commit 2d0a47236d.
2023-05-11 15:02:47 +02:00
Robert Hensing
936309cb9b linuxKernel.packages.linux_stable: init as reference
Or call it an alias, although that has the wrong connotation,
from aliases.nix. This alias is not deprecated.
2023-05-10 20:43:09 +02:00
Robert Hensing
7e2d8c4ace nixosTests: Resolve use of trivial aliases 2023-05-10 18:26:36 +02:00
Robert Hensing
a486968a6e nixosTests: Resolve alias kgx = gnome-console 2023-05-10 18:14:50 +02:00
Robert Hensing
9edbbf1633 nixos/all-tests: Enable readOnlyPkgs by default for runTest
Most tests are not affected by this because they use the `handleTest`
function instead.
2023-05-10 15:57:15 +02:00
Robert Hensing
5400041d4a nixos/testing/nodes.nix: Do not rely on disabledModules
It's just not necessary.
2023-05-10 15:55:10 +02:00
Robert Hensing
ae64e1b4cf 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-10 15:55:10 +02:00
Robert Hensing
7a32a2eb7d 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-10 15:55:10 +02:00
Robert Hensing
4f21de5214 nixosTests.acme: Use a read-only pkgs
This speeds up evaluation by a factor 2.

Ballpark figures from my machine:

```
$ time nix-build nixos/release.nix -A tests.acme
/nix/store/q4fxp55k64clcarsx8xc8f6s10szlfvz-vm-test-run-acme
/nix/store/lnfqg051sxx05hclva84bcbnjfc71c8x-vm-test-run-acme

real    1m28.142s
user    1m7.474s
sys     0m7.932s

$ time nix-build nixos/release.nix -A tests.acme
/nix/store/q4fxp55k64clcarsx8xc8f6s10szlfvz-vm-test-run-acme
/nix/store/lnfqg051sxx05hclva84bcbnjfc71c8x-vm-test-run-acme

real    0m38.235s
user    0m33.814s
sys     0m2.283s

```
2023-05-10 15:55:10 +02:00
Robert Hensing
35068dc47f nixos/all-tests.nix: Add readOnlyPkgs module 2023-05-10 15:55:09 +02:00
Robert Hensing
2d0a47236d nixos/release.nix: Pass a pkgs without aliases to tests
The tests currently only use it for support packages such as qemu, but
by changing this, the `pkgs` argument becomes suitable for use as the
`pkgs` argument in NixOS. Using a single Nixpkgs improves performance.
2023-05-10 15:55:09 +02:00
2 changed files with 63 additions and 4 deletions

View File

@@ -1,7 +1,18 @@
testModuleArgs@{ config, lib, hostPkgs, nodes, ... }:
let
inherit (lib) mkOption mkForce optional types mapAttrs mkDefault mdDoc;
inherit (lib)
literalExpression
literalMD
mapAttrs
mdDoc
mkDefault
mkIf
mkOption mkForce
optional
optionalAttrs
types
;
baseOS =
import ../eval-config.nix {
@@ -16,7 +27,8 @@ let
{
virtualisation.qemu.package = testModuleArgs.config.qemu.package;
})
({
(optionalAttrs (!config.node.pkgsReadOnly) {
key = "nodes.nix-pkgs";
config = {
# Ensure we do not use aliases. Ideally this is only set
# when the test framework is used by Nixpkgs NixOS tests.
@@ -71,6 +83,30 @@ in
default = { };
};
node.pkgs = mkOption {
description = mdDoc ''
The Nixpkgs to use for the nodes.
Setting this will make the `nixpkgs.*` options read-only, to avoid mistakenly testing with a Nixpkgs configuration that diverges from regular use.
'';
type = types.nullOr types.pkgs;
default = null;
defaultText = literalMD ''
`null`, so construct `pkgs` according to the `nixpkgs.*` options as usual.
'';
};
node.pkgsReadOnly = mkOption {
description = mdDoc ''
Whether to make the `nixpkgs.*` options read-only. This is only relevant when [`node.pkgs`](#test-opt-node.pkgs) is set.
Set this to `false` when any of the [`nodes`](#test-opt-nodes) needs to configure any of the `nixpkgs.*` options. This will slow down evaluation of your test a bit.
'';
type = types.bool;
default = config.node.pkgs != null;
defaultText = literalExpression ''node.pkgs != null'';
};
node.specialArgs = mkOption {
type = types.lazyAttrsOf types.raw;
default = { };
@@ -103,5 +139,11 @@ in
config.nodes;
passthru.nodes = config.nodesCompat;
defaults = mkIf config.node.pkgsReadOnly {
nixpkgs.pkgs = config.node.pkgs;
imports = [ ../../modules/misc/nixpkgs/read-only.nix ];
};
};
}

View File

@@ -46,7 +46,7 @@ let
inherit
(rec {
doRunTest = arg: ((import ../lib/testing-python.nix { inherit system pkgs; }).evalTest {
imports = [ arg ];
imports = [ arg readOnlyPkgs ];
}).config.result;
findTests = tree:
if tree?recurseForDerivations && tree.recurseForDerivations
@@ -65,6 +65,23 @@ let
runTestOn
;
# Using a single instance of nixpkgs makes test evaluation faster.
# To make sure we don't accidentally depend on a modified pkgs, we make the
# related options read-only. We need to test the right configuration.
#
# If your service depends on a nixpkgs setting, first try to avoid that, but
# otherwise, you can remove the readOnlyPkgs import and test your service as
# usual.
readOnlyPkgs =
# TODO: We currently accept this for nixosTests, so that the `pkgs` argument
# is consistent with `pkgs` in `pkgs.nixosTests`. Can we reinitialize
# it with `allowAliases = false`?
# warnIf pkgs.config.allowAliases "nixosTests: pkgs includes aliases."
{
_class = "nixosTest";
node.pkgs = pkgs;
};
in {
# Testing the test driver
@@ -77,7 +94,7 @@ in {
_3proxy = runTest ./3proxy.nix;
aaaaxy = runTest ./aaaaxy.nix;
acme = runTest ./acme.nix;
acme = runTest { imports = [ ./acme.nix ]; };
adguardhome = runTest ./adguardhome.nix;
aesmd = runTestOn ["x86_64-linux"] ./aesmd.nix;
agate = runTest ./web-servers/agate.nix;