Corruped nix store

Manged to corrupt my harddrive so some corrupt files in /nix/store.

But how I found out was that I got random looking build failure and then when I tried to build from exact same commit on other machine and it succeeds, I thought that I had found a reproducibility bug in nix. But then I ran nix-store --verify --check-contents --repair and it indeed it found a bunch of broken things.

I’ll have to try to save/fix this on my own but my question is why nix does not check this itself on every build? Like /nix/store being corrupted seems like a pretty serious reproducibilty problem. --verify was able to find it so why not check the hashes as part of every bulid and get clear warning. “/nix/store is corrupted, your disk is probably screwed, hopefully you made backups yesterday” or something? Any techical reson to not do this?

Might attempt vibe fix later if I have time.

Because it’s very expensive to read every file in the store and check it against the database, and almost always unnecessary. Why waste that electricity and wear down everybody’s hardware when it only finds something once every 10 years or so?

It also doesn’t help much to check only during builds, files can corrupt any time, and they affect runtime just as much as build time. This can happen on all distros, for what it’s worth, don’t treat this specially just because NixOS actually gives you the tools to see it.

7 Likes