git.iko.soy/typeable/nixpkgs
on master help sign in
dovecot, opensmtpd: add link to test in `meta.tests`

Rationale --------- Currently, tests are hard to discover. For instance, someone updating `dovecot` might not notice that the interaction of `dovecot` with `opensmtpd` is handled in the `opensmtpd.nix` test. And even for someone updating `opensmtpd`, it requires manual work to go check in `nixos/tests` whether there is actually a test, especially given not so many packages in `nixpkgs` have tests and this is thus most of the time useless. Finally, for the reviewer, it is much easier to check that the “Tested via one or more NixOS test(s)” has been checked if the file modified already includes the list of relevant tests. Implementation -------------- Currently, this commit only adds the metadata in the package. Each element of the `meta.tests` attribute is a derivation that, when it builds successfully, means the test has passed (ie. following the same convention as NixOS tests). Future Work ----------- In the future, the tools could be made aware of this `meta.tests` attribute, and for instance a `--with-tests` could be added to `nix-build` so that it also builds all the tests. Or a `--without-tests` to build without all the tests. @Profpatsch described in his NixCon talk such systems. Another thing that would help in the future would be the possibility to reasonably easily have cross-derivation nix tests without the whole NixOS VM stack. @7c6f434c already proposed such a system. This RFC currently handles none of these concerns. Only the addition of `meta.tests` as metadata to be used by maintainers to remember to run relevant tests.

commit02e1f00ffdd0c1a74fbc0be5f314b8921b0c9165 authorLéo Gaspard <leo@gaspard.io> dateSat 4 Aug 2018, 12:18 (8 years ago) parentde8f3b4
7 files changed+98−4
doc/meta.xml+55 nixos/lib/testing.nix+3−1 nixos/tests/opensmtpd.nix+2 pkgs/servers/mail/dovecot/default.nix+4 pkgs/servers/mail/opensmtpd/default.nix+4−1 pkgs/stdenv/generic/check-meta.nix+10−2 pkgs/top-level/all-packages.nix+20
doc/meta.xml+55
@@ -250,6 +250,61 @@ meta.platforms = stdenv.lib.platforms.linux;
250250 </para>
251251 </listitem>
252252 </varlistentry>
253+ <varlistentry>
254+ <term>
255+ <varname>tests</varname>
256+ </term>
257+ <listitem>
258+ <para>
259+ An attribute set with as values tests. A test is a derivation, which
260+ builds successfully when the test passes, and fails to build otherwise. A
261+ derivation that is a test requires some <literal>meta</literal> elements
262+ to be defined: <literal>needsVMSupport</literal> (automatically filled-in
263+ for NixOS tests) and <literal>timeout</literal>.
264+ </para>
265+ <para>
266+ The NixOS tests are available as <literal>nixosTests</literal> in
267+ parameters of derivations. For instance, the OpenSMTPD derivation
268+ includes lines similar to:
269+<programlisting>
270+{ /* ... */, nixosTests }:
271+{
272+ # ...
273+ meta.tests = {
274+ basic-functionality-and-dovecot-integration = nixosTests.opensmtpd;
275+ };
276+}
277+</programlisting>
278+ </para>
279+ </listitem>
280+ </varlistentry>
281+ <varlistentry>
282+ <term>
283+ <varname>timeout</varname>
284+ </term>
285+ <listitem>
286+ <para>
287+ A timeout (in seconds) for building the derivation. If the derivation
288+ takes longer than this time to build, it can fail due to breaking the
289+ timeout. However, all computers do not have the same computing power,
290+ hence some builders may decide to apply a multiplicative factor to this
291+ value. When filling this value in, try to keep it approximately
292+ consistent with other values already present in
293+ <literal>nixpkgs</literal>.
294+ </para>
295+ </listitem>
296+ </varlistentry>
297+ <varlistentry>
298+ <term>
299+ <varname>needsVMSupport</varname>
300+ </term>
301+ <listitem>
302+ <para>
303+ A boolan that states whether the derivation requires build-time support
304+ for Virtual Machine to build successfully.
305+ </para>
306+ </listitem>
307+ </varlistentry>
253308 <varlistentry>
254309 <term>
255310 <varname>hydraPlatforms</varname>
nixos/lib/testing.nix+3−1
@@ -69,7 +69,9 @@ in rec {
6969 mkdir -p $out/coverage-data
7070 mv $i $out/coverage-data/$(dirname $(dirname $i))
7171 done
72− ''; # */
72+ '';
73+
74+ meta.needsVMSupport = true;
7375 };
7476
7577
nixos/tests/opensmtpd.nix+2
@@ -120,4 +120,6 @@ import ./make-test.nix {
120120 $smtp2->waitUntilFails('smtpctl show queue | egrep .');
121121 $client->succeed('check-mail-landed >&2');
122122 '';
123+
124+ meta.timeout = 30;
123125}
pkgs/servers/mail/dovecot/default.nix+4
@@ -1,6 +1,7 @@
11{ stdenv, lib, fetchurl, perl, pkgconfig, systemd, openssl
22, bzip2, zlib, lz4, inotify-tools, pam, libcap
33, clucene_core_2, icu, openldap, libsodium, libstemmer, cyrus_sasl
4+, nixosTests
45# Auth modules
56, withMySQL ? false, mysql
67, withPgSQL ? false, postgresql
@@ -74,5 +75,8 @@ stdenv.mkDerivation rec {
7475 description = "Open source IMAP and POP3 email server written with security primarily in mind";
7576 maintainers = with stdenv.lib.maintainers; [ peti rickynils fpletz ];
7677 platforms = stdenv.lib.platforms.unix;
78+ tests = {
79+ opensmtpd-interaction = nixosTests.opensmtpd;
80+ };
7781 };
7882}
pkgs/servers/mail/opensmtpd/default.nix+4−1
@@ -1,5 +1,5 @@
11{ stdenv, lib, fetchurl, fetchpatch, autoconf, automake, libtool, bison
2−, libasr, libevent, zlib, libressl, db, pam
2+, libasr, libevent, zlib, libressl, db, pam, nixosTests
33}:
44
55stdenv.mkDerivation rec {
@@ -61,5 +61,8 @@ stdenv.mkDerivation rec {
6161 license = licenses.isc;
6262 platforms = platforms.linux;
6363 maintainers = with maintainers; [ rickynils obadz ekleog ];
64+ tests = {
65+ basic-functionality-and-dovecot-interaction = nixosTests.opensmtpd;
66+ };
6467 };
6568}
pkgs/stdenv/generic/check-meta.nix+10−2
@@ -165,6 +165,16 @@ let
165165 platforms = listOf (either str lib.systems.parsedPlatform.types.system);
166166 hydraPlatforms = listOf str;
167167 broken = bool;
168+ # TODO: refactor once something like Profpatsch's types-simple will land
169+ tests = attrsOf (mkOptionType {
170+ name = "test";
171+ check = x: isDerivation x &&
172+ x ? meta.timeout &&
173+ x ? meta.needsVMSupport;
174+ merge = lib.options.mergeOneOption;
175+ });
176+ needsVMSupport = bool;
177+ timeout = int;
168178
169179 # Weirder stuff that doesn't appear in the documentation?
170180 knownVulnerabilities = listOf str;
@@ -184,8 +194,6 @@ let
184194 isIbusEngine = bool;
185195 isGutenprint = bool;
186196 badPlatforms = platforms;
187− # Hydra build timeout
188− timeout = int;
189197 };
190198
191199 checkMetaAttr = k: v:
pkgs/top-level/all-packages.nix+20
@@ -71,6 +71,26 @@ with pkgs;
7171
7272 common-updater-scripts = callPackage ../common-updater/scripts.nix { };
7373
74+ ### Push NixOS tests inside the fixed point
75+
76+ nixosTests =
77+ let
78+ # TODO(Ericson2314,ekleog): Check this will work correctly with cross-
79+ system = builtins.currentSystem;
80+ rawTests = (import ../../nixos/release.nix {
81+ nixpkgs = pkgs;
82+ }).tests;
83+ testNames = builtins.attrNames rawTests;
84+ filteredList = builtins.filter
85+ (test: rawTests.${test} ? ${system})
86+ testNames;
87+ finalList = map
88+ (test: { name = test; value = rawTests.${test}.${system}; })
89+ filteredList;
90+ finalTests = builtins.listToAttrs finalList;
91+ in
92+ finalTests;
93+
7494 ### BUILD SUPPORT
7595
7696 autoreconfHook = makeSetupHook