Can't switch to flakes (error: cached failure of attribute)

Hello there! So I’m trying to switch to flakes with help of NixOS & Flakes book. After sudo nixos-rebuild switch command I got an error:

error:
       … while calling the 'head' builtin
         at /nix/store/6nfpbajyzwxq6wrhn20l13rhckhv26rc-source/lib/attrsets.nix:922:11:
          921|         || pred here (elemAt values 1) (head values) then
          922|           head values
             |           ^
          923|         else
       … while evaluating the attribute 'value'
         at /nix/store/6nfpbajyzwxq6wrhn20l13rhckhv26rc-source/lib/modules.nix:807:9:
          806|     in warnDeprecation opt //
          807|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          808|         inherit (res.defsFinal') highestPrio;
       (stack trace truncated; use '--show-trace' to show the full trace)
       error: in pure evaluation mode, 'fetchTarball' requires a 'sha256' argument

And another call gives me:

building the system configuration...
error: cached failure of attribute 'nixosConfigurations.nixos.config.system.build.toplevel'

Any suggestions how can I fix this? I thought it will be an easy walk in a park.
It seems like this error should be common but I can’t find any meaningful answers in the internet. I’m on stable 23.11 channel.

Hey,
I think that means that there was an error building that attribute in the past and nix has stored that, so it does not need to rerun everything if nothing changed. You can manually delete this cache by removing .cache/nix.

1 Like

Thank for your response! I had this error both in virtual machine and on real hardware. Unfortunately I gave up and switched back to arch for now :confused: But I tested flakes again on clean installation in qemu, and I don’t have this error, so maybe it’s a cache. I didn’t have too much in previous configuration file, only support for unstable packages and AppImages. Anyways I’ll keep cache in mind from now on. Thanks!

I’m pretty sure throwing an --impure on the command line will avoid any of the caching behavior, and shouldn’t really impact anything from a purity standpoint if you’re already using flakes and know it (should) eval purely.

You can also use --option eval-cache false

1 Like