Skip to content
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

Nix flakes should not cache evaluation errors #3872

Closed
Mic92 opened this issue Jul 28, 2020 · 42 comments
Closed

Nix flakes should not cache evaluation errors #3872

Mic92 opened this issue Jul 28, 2020 · 42 comments
Labels
bug error-messages Confusing messages and better diagnostics flakes language The Nix expression language; parser, interpreter, primops, evaluation, etc

Comments

@Mic92
Copy link
Member

Mic92 commented Jul 28, 2020

Describe the bug

Currently error messages are only showed the first time they appear.
After that the error message looks like this:

$ sudo nixos-rebuild switch
building the system configuration...
error: --- EvalError -------------------------------------------------------------------------- nix
cached failure of attribute 'nixosConfigurations.turingmachine.config.system.build.toplevel.drvPath'

The problem is that the error message of the first time might be no longer visible,
so users would get stuck not knowing what its going on.

Steps To Reproduce

  1. Create an invalid nixos configuration i.e. add two conflicting options (but valid nix syntax)
  2. Run nixos-rebuild switch:
error: --- ThrownError --------------------------------------------------------------------------- nix
The option `system.nixos.versionSuffix' has conflicting definitions, in `<unknown-file>' and `<unknown-file>'.
(use '--show-trace' to show detailed location information)
  1. Run nixos-rebuild switch again:
building the system configuration...
error: --- EvalError -------------------------------------------------------------------------- nix
cached failure of attribute 'nixosConfigurations.turingmachine.config.system.build.toplevel.drvPath'

Expected behavior

It should not cache evaluation failures and show me the message agin

nix-env --version output

$ nix-env --version
nix-env (Nix) 2.4pre20200721_ff314f1
@Mic92 Mic92 added the bug label Jul 28, 2020
@edolstra
Copy link
Member

No, evaluation errors must be cached, because otherwise an operation like nix search nixpkgs has to evaluate stuff even in the cached case (since nixpkgs contains a lot of attributes that don't evaluate). However, we should probably store the error message in the cache (though that might require a lot of extra disk space).

@edolstra edolstra removed the bug label Jul 28, 2020
@Mic92
Copy link
Member Author

Mic92 commented Jul 28, 2020

It also looks like evaluation errors in flake.nix files have no file name / line number.

@Mic92
Copy link
Member Author

Mic92 commented Jul 28, 2020

Evaluation error messages tend to be small. If no stack is included.

@edolstra
Copy link
Member

They're pretty big, e.g.

Package ‘cudatoolkit-10.2.89’ in /home/eelco/Dev/nixpkgs-stable/pkgs/development/compilers/cudatoolkit/common.nix:214 has an unfree license (‘unfree’), refusing to evaluate.

a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowUnfree = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowUnfree = true; }
to ~/.config/nixpkgs/config.nix.

(use '--show-trace' to show detailed location information)

@Mic92
Copy link
Member Author

Mic92 commented Jul 28, 2020

How about an option that by-passes cached evaluation errors that is internally used by nixos-rebuild?

@kloenk
Copy link
Member

kloenk commented Jul 28, 2020

Normally that cache works just fine. Everytime I change something the cached failure is gone. The problem I have is, how do I remove the cached failure. Because when I play with the daemon I cache failures, where the fixed comes in a changed daemon and so no changes in the nix files.

@domenkozar
Copy link
Member

domenkozar commented Jul 28, 2020

What if the error message was also cached?

@edolstra
Copy link
Member

@kloenk Only EvalErrors should be cached, so daemon errors shouldn't be.

@kloenk
Copy link
Member

kloenk commented Jul 28, 2020

@kloenk Only EvalErrors should be cached, so daemon errors shouldn't be.

I got my wopAddToStoreNar (I think it was) to fail. This made it impossible to include sources in the eval step

@edolstra
Copy link
Member

Hm, that still shouldn't be cached because such an error is not a subclass of EvalError.

@kloenk
Copy link
Member

kloenk commented Jul 28, 2020

The daemon did not response with an error to addToStore, so the eval failed with no such file or directory

@colemickens
Copy link
Member

Can we --force in the meantime? Or is there already such a feature I've missed? It's a daily occurrence that I add a "1" somewhere to bust the cache, and similarly frequent that I forget to remove it.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/flakes-with-unfree-licenses/9405/1

@johanot
Copy link

johanot commented Jun 5, 2022

@Mic92 I might have just run into a variant of this:

> nix eval .#nixosConfigurations.myhost
error: in pure evaluation mode, 'fetchTarball' requires a 'sha256' argument
(use '--show-trace' to show detailed location information)

> nix eval .#nixosConfigurations.myhost
error: 'nixosConfigurations' is not an attribute set

> rm -fr ~/.cache/nix/

> nix eval .#nixosConfigurations.myhost
error: in pure evaluation mode, 'fetchTarball' requires a 'sha256' argument
(use '--show-trace' to show detailed location information)
> nix --version
nix (Nix) 2.9.0pre20220530_af23d38

Is this a regression or intended behavior somehow?

@Mic92
Copy link
Member Author

Mic92 commented Jun 5, 2022

Looks like this error is similar.

@ParetoOptimalDev
Copy link

This threw me off yesterday in my personal config. My workaround was just to change something and try rebuilding again to get around the cache.

@roberth
Copy link
Member

roberth commented Jun 17, 2023

@roberth roberth reopened this Jun 17, 2023
@roberth roberth added bug flakes error-messages Confusing messages and better diagnostics language The Nix expression language; parser, interpreter, primops, evaluation, etc labels Jun 17, 2023
@ikervagyok
Copy link

I agree that we should cache the evaluation error, since it doesn't make sense to wait an hour for a long build if we can be certain it will fail. I'm suggesting though that nix should print the command to retrieve the build log nix log /nix/store/...-failed-build.drv not only the first time, but on all subsequent attempts.

This would make life so much easier. The workaround of changing a variable and then forcing a rebuild is stealing focus from the actual problem at hand - the failing build. It also doesn't always work as expected, depending on the project size you need to find a suitable variable/dependency.

@peterbecich
Copy link
Contributor

#3872 (comment)

Instead of --force, how about the existing option --rebuild?

error: cached failure of attribute 'packages.x86_64-linux'

I have just tested --rebuild and it does not solve the error

@GuillaumeDesforges
Copy link
Contributor

If a build fails with little information

$ sudo nixos-rebuild switch --flake .
warning: Git tree '/home/gdforj/nixos-configuration' is dirty
building the system configuration...
warning: Git tree '/home/gdforj/nixos-configuration' is dirty
error:
       … while calling the 'head' builtin

         at /nix/store/j30ahz6pipp5wypar2f117l4f4fsjjvr-source/lib/attrsets.nix:780:11:

          779|         || pred here (elemAt values 1) (head values) then
          780|           head values
             |           ^
          781|         else

       … while evaluating the attribute 'value'

         at /nix/store/j30ahz6pipp5wypar2f117l4f4fsjjvr-source/lib/modules.nix:759:9:

          758|     in warnDeprecation opt //
          759|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          760|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: Invalid package attribute path 'qt6Packages qt6ct'

then I want the trace but I can't

$ sudo nixos-rebuild switch --flake . --show-trace 
warning: Git tree '/home/gdforj/nixos-configuration' is dirty
building the system configuration...
warning: Git tree '/home/gdforj/nixos-configuration' is dirty
error: cached failure of attribute 'nixosConfigurations.tosaka.config.system.build.toplevel'

How can I get the trace in this case?

@ncfavier
Copy link
Member

You can disable the eval cache as a workaround: --no-eval-cache (or --option eval-cache false)

@takeda
Copy link

takeda commented Jul 23, 2023

Thanks @ncfavier for the tip.

I think this cache should probably be ignored when --debugger option is used. It makes things very confusing.

@ncfavier
Copy link
Member

Also --show-trace.

@GuillaumeDesforges
Copy link
Contributor

A possible fix to my issue above could be to also cache the error when the eval fails to be able to print it again.

@hraban
Copy link
Member

hraban commented Aug 20, 2023

You can disable the eval cache as a workaround: --no-eval-cache (or --option eval-cache false)

This is a better solution than my rm -rf ~/.cache/nix 😂

stelcodes added a commit to stelcodes/nixos-config that referenced this issue Sep 13, 2023
Error caching is enabled by default when using nixos-rebuild with a
flake. This supresses error messages on subsequent retries of a bad
NixOS config which makes viewing related logs challenging. Disabling the
error cache ensures that the error messages will print every time a
rebuild is attempted.

See NixOS/nix#3872.
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/error-cached-failure-of-attribute-nixosconfigurations-framework-config-system-build-toplevel/35451/2

@cab404
Copy link
Member

cab404 commented Jan 27, 2024

Still an issue.

@roberth roberth added this to the Flakes milestone Jan 27, 2024
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/the-option-programs-kitty-does-not-exist/39447/1

@yshui
Copy link
Contributor

yshui commented Feb 27, 2024

people already asked above, but hadn't seem to get an answer. can't error messages also be cached? is this not feasible because the error message might be too big?

@thufschmitt
Copy link
Member

people already asked above, but hadn't seem to get an answer. can't error messages also be cached? is this not feasible because the error message might be too big?

I don't think there's a strong reason for not doing that. Mostly needs someone to go and fix it

@Ma27
Copy link
Member

Ma27 commented Apr 5, 2024

btw for everyone reading here, I started working on that: #10368 (again).

@dejanr
Copy link

dejanr commented Apr 7, 2024

The amount of time i have seen this cached error message and not knowing what it actually is, is getting ridiculous.

@edolstra
Copy link
Member

edolstra commented Apr 9, 2024

@dejanr Then please make an issue with a reproduction so we can fix it.

@Ma27
Copy link
Member

Ma27 commented Apr 9, 2024

@edolstra there's #10368 fixing the core issue (that by default eval errors are being cached) in the second commit.
Sure, we need to sort out how to deal with the dirty-trees thing on 2.20+ (left a longer comment on that), but the second commit applies cleanly (short of the modified regression test) on 2.19 at least and solves the problem there. Would appreciate some more input there on how we continue.

@Mic92
Copy link
Member Author

Mic92 commented May 17, 2024

I am no longer able to reproduce the cached eval errors with nix 2.22.
This will produce "cached eval errors" with 2.18. With nix 2.22 it works:

{
  description = "Fnord";
  outputs =
    { self, nixpkgs }:
    {
      # will complain about missing fileSystems
      nixosConfigurations.turingmachine = nixpkgs.legacyPackages.x86_64-linux.nixos [];
    };
}

@Mic92 Mic92 closed this as completed May 17, 2024
@jottr
Copy link

jottr commented Aug 19, 2024

I just witnessed this behavior on my system running nixos 24.05.
I'd be happy to help reproduce this issue if required.

@eclairevoyant
Copy link
Contributor

eclairevoyant commented Aug 19, 2024

@jottr check your nix version. This was fixed in 2.23 and I guess backported to 2.22.

@Buttars
Copy link

Buttars commented Sep 7, 2024

You can disable the eval cache as a workaround: --no-eval-cache (or --option eval-cache false)

This needs better documentation. This is currently the best documentation I could find. Having to dig through a 4 year old issue is not great documentation. Very frustrating.

@cab404
Copy link
Member

cab404 commented Sep 7, 2024

This needs better documentation. This is currently the best documentation I could find. Having to dig through a 4 year old issue is not great documentation. Very frustrating.

image

@roberth
Copy link
Member

roberth commented Sep 8, 2024

This needs better documentation.

If anything it needs backports, as the problem has been fixed in recent versions. PRs welcome.

If not backported, the fix will be delivered anyway to NixOS in the upcoming release, 24.11. Updated documentation will be obsolete by the end of the year.

@jottr
Copy link

jottr commented Sep 8, 2024 via email

@eclairevoyant
Copy link
Contributor

eclairevoyant commented Sep 8, 2024

created #11445 to backport to 2.18
edit: merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug error-messages Confusing messages and better diagnostics flakes language The Nix expression language; parser, interpreter, primops, evaluation, etc
Projects
Status: Done
Development

No branches or pull requests