NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.08k stars 1.47k forks source link

empty derivation and can't repair the various wrong store paths, thus blocking nixos-rebuild #11148

Open teto opened 1 month ago

teto commented 1 month ago

Describe the bug

I find myself in a situation where I can't rebuild my system and I am not sure how to repair the store without manually deleting lots of derivations.

Upon nixos-rebuild, I've got an error I've never seen before: error: error parsing derivation '/nix/store/8ihsdsn00n2p9hy9hz2jmw5z5wfl3w9r-nss-3.102.drv': error: expected string 'D'. When I look at /nix/store/8ihsdsn00n2p9hy9hz2jmw5z5wfl3w9r-nss-3.102.drv, it's empty :/

sudo nix-store --verify --check-contents shows around ~80 failures in the store (wrong hash, which might be because of unexpected shutdowns?!. The command finishes with the weird : warning: not all store errors were fixed.. Since it was run without --repair, i dont think it tried to fix any error so this specific message is weird: either no message or warning: no repair was done: rerun with --repair.

I then tried to actually repair the paths:

error: cannot repair path '/nix/store/aigwdcmwand90dasgsh3837p5n5zkvac-swaybg-1.2.1.drv'
path '/nix/store/apc6ihyrk677wb5q6dw80qbjz1nhvd8x-sway.conf.drv' was modified! expected hash 'sha256:15830m1af8hv8mz1y403ajh9lqibb4y3p46py9b5icviv51ghalh', got 'sha256:0ip26j2h11n1kgkz36rl4akv694yz65hr72q4kv4b3lxcbi65b3p'
error: cannot repair path '/nix/store/apc6ihyrk677wb5q6dw80qbjz1nhvd8x-sway.conf.drv'
path '/nix/store/b0llvi2bw2hhlfl1nimmbz938prf2zwg-qtlanguageserver-6.7.2.drv' was modified! expected hash 'sha256:1wy52gqzkya5qwcl6jrlgvzas6gs6ay7bg73dxq088i7368yk72f', got 'sha256:0ip26j2h11n1kgkz36rl4akv694yz65hr72q4kv4b3lxcbi65b3p'
error: cannot repair path '/nix/store/b0llvi2bw2hhlfl1nimmbz938prf2zwg-qtlanguageserver-6.7.2.drv'

It's not clear why it can't repair the path ? ( as a sidenote I also tried:

nix store repair --all 
error: operation 'repairPath' is not supported by store 'daemon'

)

so I thought I would nee

sudo nix-store --ignore-liveness --delete /nix/store/2zjwchn4vwcpbqxfzi24fmzzdcgibs9b-source.drv 
finding garbage collector roots...
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/2zjwchn4vwcpbqxfzi24fmzzdcgibs9b-source.drv' since it is still alive. To find out why, use: nix-store --query --roots and nix-store --query --referrers

I am not sure how to proceed to unblock the repair. Maybe delete all the referrers manually ? Isn't it possible to force delete a .drv store path ? --ignore-liveness could become --force instead for a more standard flag.

nix-env --version output

nix --version         
nix (Nix) 2.23.1

Additional context

My laptop oftenu shut down unexpected recently for various reasons, which could explain the wrong store paths.

Priorities

Add :+1: to issues you find important.

teto commented 1 month ago

garbage-collecting everything unblocked me but this doesn't seem like a good workaround. I'll leave this open in case the maintainers want to requalify the UX problems (more actionable messages: why can't nix repair the pat ? when --check ing, mention how to --repair etc) I mentioned but feel free to close otherwise.

roberth commented 1 month ago

.drv files are often not pushed to a cache, in which case the only way to restore them is to perform instantiation again, ie evaluate. Currently these files are not checked; the instantiation process assumes that "valid" (ie extant) store paths are not corrupted. That's a choice that was made for performance, but with an extra bit in the database, we could get both performance and automatic recovery.

TODO: