So you have to understand what this does:
$ nix-build '<nixpkgs>' -A phoronix-test-suite.tests
will go to the folder pointed by <nixpkgs> (chech echo $NIX_PATH for details), then it will evaluate the file default.nix in this folder. In nixpkgs this file outputs all top-level packages, including notably the programs loaded in pkgs/top-level/all-packages.nix. In particular, if you see this file, you can see that it contains the phoronix-test-suite program:
$ cat pkgs/top-level/all-packages.nix | grep phoronix
phoronix-test-suite = callPackage ../tools/misc/phoronix-test-suite { };
If you look at this file you will see that it contains a passthru:
$ cat pkgs/tools/misc/phoronix-test-suite/default.nix
…
passthru.tests = {
simple-execution = callPackage ./tests.nix { };
};
…
So after evaluating default.nix (itself calling pkgs/tools/misc/phoronix-test-suite/default.nix), you end up with a huge attribute set containing:
{
…
phoronix-test-suite = {
tests = {
simple-execution = DERIVATION FOR THE TEST WRITTEN IN pkgs/tools/misc/phoronix-test-suite/tests.nix;
}
}
…
}
The role of -A phoronix-test-suite.tests is exactly to compile all the derivations in phoronix-test-suite.tests, so it will compile and pass the test with success!
Now if you want to compile your own test, say that you created in /tmp/a.nix this file:
{ pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation {
name = "example-test";
meta.timeout = 60;
src = ./.;
passthru.tests = {
full-sdk-shell = pkgs.runCommand "shell-test" {} ''
echo "I'm running the test"
exit 1
'';
};
}
Then you can run your test by doing:
$ nix-build /tmp/a.nix -A tests
this derivation will be built:
/nix/store/nwcva6f5dpra77byb9fyhz46g6k7kkyx-shell-test.drv
building '/nix/store/nwcva6f5dpra77byb9fyhz46g6k7kkyx-shell-test.drv'...
I'm running the test
error: builder for '/nix/store/nwcva6f5dpra77byb9fyhz46g6k7kkyx-shell-test.drv' failed with exit code 1;
last 1 log lines:
> I'm running the test
For full logs, run 'nix log /nix/store/nwcva6f5dpra77byb9fyhz46g6k7kkyx-shell-test.drv'.
that fails as expected as it will evaluate a.nix, the passthru will provide an attribute called tests, which is used to compile all the derivations in this attribute.
Note that if you rename /tmp/a.nix into /tmp/default.nix, then once you cd /tmp you don’t need to specify the .nix file to use as it will automatically pick default.nix.
I hope it’s clearer.