about summary refs log tree commit diff
path: root/pkgs/test/stdenv
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2023-01-15 20:54:48 +0100
committerRobert Hensing <robert@roberthensing.nl>2023-01-16 12:57:01 +0100
commit01d7f19346bc5de4508244b7b1dd23355d026899 (patch)
treedfae1438b4cb83ec6ccda84dddef2cd2b20dbeb5 /pkgs/test/stdenv
parent5fb9ccbd5bf373994d1e0bc45e0e0cfae27465bf (diff)
multi-outputs.sh: Improve _assignFirst error message
Closes #16182

This improves the error message

    Error: _assignFirst found no valid variant!

which occurred when the set of outputs was not sufficient to set
the various outputDev, outputBin, etc variables. Specifically, this
would mean that "out" is not among the outputs, which is valid for
a derivation.

This changes the message to something like

    error: _assignFirst: could not find a non-empty variable to assign to outputDev. The following variables were all unset or empty: dev out.
          If you did not define an "out" output, make sure to define all the specific required outputs: define an output for one of the unset variables.

While this isn't a full explanation of what stdenv can and can not do,
I think it's vast improvement over the 0 bits of information that it
used to provide. This at least gives a clue as to what's going on, and
even suggests a fix, although probably multiple such fixes are required
in an instance where someone starts with a no-out derivation from scratch
(and decide to persist).
Diffstat (limited to 'pkgs/test/stdenv')
-rw-r--r--pkgs/test/stdenv/default.nix22
1 files changed, 21 insertions, 1 deletions
diff --git a/pkgs/test/stdenv/default.nix b/pkgs/test/stdenv/default.nix
index 5ff18298f217a..bad6eb7ba7aa3 100644
--- a/pkgs/test/stdenv/default.nix
+++ b/pkgs/test/stdenv/default.nix
@@ -4,7 +4,8 @@
 { stdenv
 , pkgs
 , lib
-,
+, runCommand
+, testers
 }:
 
 let
@@ -99,6 +100,25 @@ in
   # tests for hooks in `stdenv.defaultNativeBuildInputs`
   hooks = lib.recurseIntoAttrs (import ./hooks.nix { stdenv = bootStdenv; pkgs = earlyPkgs; });
 
+  outputs-no-out = runCommand "outputs-no-out-assert" {
+    result = testers.testBuildFailure (stdenv.mkDerivation {
+      NIX_DEBUG = 1;
+      name = "outputs-no-out";
+      outputs = ["foo"];
+      buildPhase = ":";
+      installPhase = ''
+        touch $foo
+      '';
+    });
+
+    # Assumption: the first output* variable to be configured is
+    #   _overrideFirst outputDev "dev" "out"
+    expectedMsg = "_assignFirst: could not find a non-empty variable to assign to outputDev. The following variables were all unset or empty: dev out.";
+  } ''
+    grep -F "$expectedMsg" $result/testBuildFailure.log >/dev/null
+    touch $out
+  '';
+
   test-env-attrset = testEnvAttrset { name = "test-env-attrset"; stdenv' = bootStdenv; };
 
   # Test compatibility with derivations using `env` as a regular variable.