Bad error message for wrong types going into derivation dependency lists #879

Open
opened 2025-06-25 20:42:30 +00:00 by jade · 0 comments
Owner

Related:

       … while evaluating attribute 'nativeBuildInputs' of derivation 'my-derivation'
         at /Users/wiggles/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:391:7:
          390|       depsBuildBuild              = elemAt (elemAt dependencies 0) 0;
          391|       nativeBuildInputs           = elemAt (elemAt dependencies 0) 1;
             |       ^
          392|       depsBuildTarget             = elemAt (elemAt dependencies 0) 2;

       … while evaluating one element of the list

       error: cannot coerce a function to a string: «lambda @ /Users/wiggles/nixpkgs/xxx-derivation.nix:7:28»

Or, today in Lix, it is much worse without --show-trace (nix (Lix, like Nix) 2.94.0-dev-pre20250625-9a59106) if we apply approximately the same thing as https://github.com/NixOS/nixpkgs/pull/293560:

which is due to #664 and #239

dev/nixpkgs » nix build -f test2.nix
error:
       … while evaluating an expression to select 'drvPath' on it
         at «internal»:1:552:
       … while evaluating strict
         at «internal»:1:552:
       (stack trace truncated; use '--show-trace' to show the full trace)

       error: cannot coerce a function to a string: «lambda @ /Users/jade/dev/nixpkgs/test2.nix:3:53»

or with --show-trace:

dev/nixpkgs » nix build --show-trace -f test2.nix                                           jadel/ci-eval-nix-stable
error:
       … while evaluating an expression to select 'drvPath' on it
         at «internal»:1:552:
       … while evaluating strict
         at «internal»:1:552:
       … while calling the 'derivationStrict' builtin
         at «internal»:1:208:
       … while evaluating derivation 'meow'
         whose name attribute is located at /Users/jade/dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:469:13

       … while evaluating attribute 'nativeBuildInputs' of derivation 'meow'
         at /Users/jade/dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:521:13:
          520|             depsBuildBuild = elemAt (elemAt dependencies 0) 0;
          521|             nativeBuildInputs = elemAt (elemAt dependencies 0) 1;
             |             ^
          522|             depsBuildTarget = elemAt (elemAt dependencies 0) 2;

       … while evaluating one element of the list

       error: cannot coerce a function to a string: «lambda @ /Users/jade/dev/nixpkgs/test2.nix:3:53»
let pkgs = import ./. {};
in
pkgs.runCommandLocal "meow" { nativeBuildInputs = [(a: a)]; } ''
  meow
''
diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix
index bc58907fbe5b..5f93d0f28036 100644
--- a/pkgs/stdenv/generic/make-derivation.nix
+++ b/pkgs/stdenv/generic/make-derivation.nix
@@ -381,9 +381,10 @@ let
           else if isList dep then
             checkDependencyList' ([ index ] ++ positions) name dep
           else
-            throw "Dependency is not of a valid type: ${
-              concatMapStrings (ix: "element ${toString ix} of ") ([ index ] ++ positions)
-            }${name} for ${attrs.name or attrs.pname}"
+            dep
+            # throw "Dependency is not of a valid type: ${
+            #   concatMapStrings (ix: "element ${toString ix} of ") ([ index ] ++ positions)
+            # }${name} for ${attrs.name or attrs.pname}"
         ) deps;
     in
     if builtins.length erroneousHardeningFlags != 0 then

Let us consider the parts of this error message:

dev/nixpkgs » nix build --show-trace -f test2.nix                                           jadel/ci-eval-nix-stable
error:
       … while evaluating an expression to select 'drvPath' on it
         at «internal»:1:552:
        ^^^ Why were we doing that? *I* know why (it's the CLI doing it) but we aren't telling the user.
       … while evaluating strict
         at «internal»:1:552:
        ^^^ This is garbage caused by builtins.derivation being a wrapper. I dunno if we should show that. Also, we aren't saying *what* internal file it is or whose.
        ^^^ https://git.lix.systems/lix-project/lix/issues/664
       … while calling the 'derivationStrict' builtin
         at «internal»:1:208:
        ^^^ This is reasonable enough.
       … while evaluating derivation 'meow'
         whose name attribute is located at /Users/jade/dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:469:13
        ^^^ This doesn't consider wrappers, but that's impossible to avoid on the part of nixpkgs in this case since we don't receive an attrset with required attrs in runCommand. So it goes.
        ^^^ This part is good, it should be in the the not show-trace one https://git.lix.systems/lix-project/lix/issues/239

       … while evaluating attribute 'nativeBuildInputs' of derivation 'meow'
         at /Users/jade/dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:521:13:
          520|             depsBuildBuild = elemAt (elemAt dependencies 0) 0;
          521|             nativeBuildInputs = elemAt (elemAt dependencies 0) 1;
             |             ^
          522|             depsBuildTarget = elemAt (elemAt dependencies 0) 2;

       … while evaluating one element of the list
      ^^^ Which one? How long was the list?

       error: cannot coerce a function to a string: «lambda @ /Users/jade/dev/nixpkgs/test2.nix:3:53»
      ^^^ This is reasonable, but we don't say why we were trying to coerce it to a string

So, is this a duplicate of all the issues involved? I don't know. I think it's a good overview of why our error messages are bad and how we could concretely fix them.

Related: - https://git.lix.systems/lix-project/lix/issues/665 - https://github.com/NixOS/nixpkgs/pull/293560 - https://git.lix.systems/lix-project/lix/issues/820 - https://git.lix.systems/lix-project/lix/issues/239 - https://git.lix.systems/lix-project/lix/issues/664 ``` … while evaluating attribute 'nativeBuildInputs' of derivation 'my-derivation' at /Users/wiggles/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:391:7: 390| depsBuildBuild = elemAt (elemAt dependencies 0) 0; 391| nativeBuildInputs = elemAt (elemAt dependencies 0) 1; | ^ 392| depsBuildTarget = elemAt (elemAt dependencies 0) 2; … while evaluating one element of the list error: cannot coerce a function to a string: «lambda @ /Users/wiggles/nixpkgs/xxx-derivation.nix:7:28» ``` Or, today in Lix, it is much worse without `--show-trace` (nix (Lix, like Nix) 2.94.0-dev-pre20250625-9a59106) if we apply approximately the same thing as https://github.com/NixOS/nixpkgs/pull/293560: which is due to https://git.lix.systems/lix-project/lix/issues/664 and https://git.lix.systems/lix-project/lix/issues/239 ``` dev/nixpkgs » nix build -f test2.nix error: … while evaluating an expression to select 'drvPath' on it at «internal»:1:552: … while evaluating strict at «internal»:1:552: (stack trace truncated; use '--show-trace' to show the full trace) error: cannot coerce a function to a string: «lambda @ /Users/jade/dev/nixpkgs/test2.nix:3:53» ``` or with `--show-trace`: ``` dev/nixpkgs » nix build --show-trace -f test2.nix jadel/ci-eval-nix-stable error: … while evaluating an expression to select 'drvPath' on it at «internal»:1:552: … while evaluating strict at «internal»:1:552: … while calling the 'derivationStrict' builtin at «internal»:1:208: … while evaluating derivation 'meow' whose name attribute is located at /Users/jade/dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:469:13 … while evaluating attribute 'nativeBuildInputs' of derivation 'meow' at /Users/jade/dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:521:13: 520| depsBuildBuild = elemAt (elemAt dependencies 0) 0; 521| nativeBuildInputs = elemAt (elemAt dependencies 0) 1; | ^ 522| depsBuildTarget = elemAt (elemAt dependencies 0) 2; … while evaluating one element of the list error: cannot coerce a function to a string: «lambda @ /Users/jade/dev/nixpkgs/test2.nix:3:53» ``` ```nix let pkgs = import ./. {}; in pkgs.runCommandLocal "meow" { nativeBuildInputs = [(a: a)]; } '' meow '' ``` ```diff diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index bc58907fbe5b..5f93d0f28036 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -381,9 +381,10 @@ let else if isList dep then checkDependencyList' ([ index ] ++ positions) name dep else - throw "Dependency is not of a valid type: ${ - concatMapStrings (ix: "element ${toString ix} of ") ([ index ] ++ positions) - }${name} for ${attrs.name or attrs.pname}" + dep + # throw "Dependency is not of a valid type: ${ + # concatMapStrings (ix: "element ${toString ix} of ") ([ index ] ++ positions) + # }${name} for ${attrs.name or attrs.pname}" ) deps; in if builtins.length erroneousHardeningFlags != 0 then ``` --- Let us consider the parts of this error message: ``` dev/nixpkgs » nix build --show-trace -f test2.nix jadel/ci-eval-nix-stable error: … while evaluating an expression to select 'drvPath' on it at «internal»:1:552: ^^^ Why were we doing that? *I* know why (it's the CLI doing it) but we aren't telling the user. … while evaluating strict at «internal»:1:552: ^^^ This is garbage caused by builtins.derivation being a wrapper. I dunno if we should show that. Also, we aren't saying *what* internal file it is or whose. ^^^ https://git.lix.systems/lix-project/lix/issues/664 … while calling the 'derivationStrict' builtin at «internal»:1:208: ^^^ This is reasonable enough. … while evaluating derivation 'meow' whose name attribute is located at /Users/jade/dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:469:13 ^^^ This doesn't consider wrappers, but that's impossible to avoid on the part of nixpkgs in this case since we don't receive an attrset with required attrs in runCommand. So it goes. ^^^ This part is good, it should be in the the not show-trace one https://git.lix.systems/lix-project/lix/issues/239 … while evaluating attribute 'nativeBuildInputs' of derivation 'meow' at /Users/jade/dev/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:521:13: 520| depsBuildBuild = elemAt (elemAt dependencies 0) 0; 521| nativeBuildInputs = elemAt (elemAt dependencies 0) 1; | ^ 522| depsBuildTarget = elemAt (elemAt dependencies 0) 2; … while evaluating one element of the list ^^^ Which one? How long was the list? error: cannot coerce a function to a string: «lambda @ /Users/jade/dev/nixpkgs/test2.nix:3:53» ^^^ This is reasonable, but we don't say why we were trying to coerce it to a string ``` So, is this a duplicate of all the issues involved? I don't know. I think it's a good overview of why our error messages are bad and how we could concretely fix them.
jade added this to the Error reporting project 2025-06-25 20:42:30 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#879
No description provided.