-
-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error messages by removing checkDependencyList
in stdenv.mkDerivation
#293560
base: master
Are you sure you want to change the base?
Conversation
7e7f35c
to
1e33d39
Compare
Hey thanks for this PR ! The fix to pict-rs can be merged immediately, but the patching of stdenv needs to go through a lot more review and discussion. |
Sure, split the |
1e33d39
to
d3cb52b
Compare
@infinisil ignoring the pict-rs changr, there is a proposition of a fix to stdenv, what do you think ? |
I recently encountered this error attempting to build a derivation: ``` error: … while calling the 'derivationStrict' builtin at /builtin/derivation.nix:9:12: (source not available) … while evaluating derivation 'infra-shell' whose name attribute is located at /nix/store/ppm74s0slima7385piksmdcnvcawgs1x-source/pkgs/stdenv/generic/make-derivation.nix:353:7 … while evaluating attribute 'nativeBuildInputs' of derivation 'infra-shell' at /nix/store/ppm74s0slima7385piksmdcnvcawgs1x-source/pkgs/stdenv/generic/make-derivation.nix:397:7: 396| depsBuildBuild = elemAt (elemAt dependencies 0) 0; 397| nativeBuildInputs = elemAt (elemAt dependencies 0) 1; | ^ 398| depsBuildTarget = elemAt (elemAt dependencies 0) 2; error: Dependency is not of a valid type: element 23 of nativeBuildInputs for infra-shell ``` This isn't very helpful; it doesn't tell me what the type of the dependency is. I'm also not directly constructing `stdenv.mkDerivation { nativeBuildInputs = [...]; }`, so it's not obvious what "element 23" would be (the derivation is constructed through several layers of helpers, like many derivations in nixpkgs are). Ultimately, element 23 was a function, which surfaces another issue: ``` nix-repl> throw "Dependency is not of a valid type: ${a: a}" error: … while evaluating a path segment at «string»:1:43: 1| throw "Dependency is not of a valid type: ${a: a}" | ^ error: cannot coerce a function to a string ``` (`builtins.toString` produces similar results.) The Nix language doesn't provide a safe value printing function, so we can't really construct a good error message here. The good news is that we can remove this error checking code from nixpkgs entirely without losing usability. Here's the error message on Nix 2.19.3: ``` error: … while calling the 'derivationStrict' builtin at /derivation-internal.nix:9:12: 8| 9| strict = derivationStrict drvAttrs; | ^ 10| … while evaluating derivation 'my-derivation' whose name attribute is located at /Users/wiggles/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:347:7 … 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; error: cannot coerce a function to a string ``` Thanks to PRs like NixOS/nix#9754, these error messages will improve in coming Nix releases: ``` … 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» ```
d3cb52b
to
5ecdbea
Compare
How is the error for Nix 2.3 users? That's the minimum version that Nixpkgs supports. |
@infinisil Looks OK:
|
While we should worry about older Nix versions too, I don't think this is worth it even for newer Nix versions. See also #24462 and the original motivation from https://unix.stackexchange.com/questions/350997/in-a-new-nixos-derivation-based-on-a-binary-distribution-why-am-i-getting-an-e?stw=2 Even if newer Nix versions show the location better, the underlying error message seems worse:
Compared to the old
Especially for newcomers it's not easy to figure out why something even gets coerced to a string in the first place (and what "coerce" even means!). While the custom error message isn't perfect either, we could easily improve it, e.g. by saying what the actual type is and what it should be, additionally printing a bit of the value (e.g. like the module system, though I also wrote this nice streaming |
@infinisil I'm not sure I understand -- even with Nix 2.3, the error message clearly states the derivation name (
I think newcomers will be well-served by the improved coercion error messages in recent Nix versions (see NixOS/nix#9754) as well as the improved source location information available in recent Nix versions. (And newcomers will tend to run recent Nix versions in general.) Moreover, having the custom-constructed error message in |
I must say that when you have lists of a hundred packages with some optionals inbetween I usually reside to binary search because not having any information about the wrong element makes it almost impossible to know what to fix even as an advanced nix user. Even just having the name of the package in the error message would eliminate that and save a bunch of time for many people. |
I think it's important to distinguish between developer-facing errors and user-facing errors:
Check out how While it's nice that stack traces now show the location of unexpected values, it would be even better if this would be exposed with e.g. |
I recently encountered this error attempting to build a derivation:
This isn't very helpful; it doesn't tell me what the type of the dependency is. I'm also not directly constructing
stdenv.mkDerivation { nativeBuildInputs = [...]; }
, so it's not obvious what "element 23" would be (the derivation is constructed through several layers of helpers, like many derivations in nixpkgs are).Ultimately, element 23 was a function, which surfaces another issue:
(
builtins.toString
produces similar results.) The Nix language doesn't provide a safe value printing function, so we can't really construct a good error message here.The good news is that we can remove this error checking code from nixpkgs entirely without losing usability. Here's the error message on Nix 2.19.3:
Thanks to PRs like NixOS/nix#9754, these error messages will improve in coming Nix releases:
(This shows the exact location of the failing value!)
Description of changes
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.