I’ve been experiencing weird issues with a specific package (JB RustRover), and I suspected there was something corrupted with the installation. I couldn’t find anything online about how to force a rebuild in nix (builds and installs are fallible!) and so I (in my stupidity) deleted some files in the /nix/store directory. Now, my system refuses to rebuild:
unpacking 0 channels...
building Nix...
building the system configuration...
error: opening file '/nix/store/mdchwscx6l2kkvjpw8l4f29k9qizpfl1-rust-rover-2024.3.4.drv': No such file or directory
For an OS priding itself on reproducibility and stability, I can’t seem to find a way to rebuild/recheck everything. Any ideas?
So first of all, for future reference, this is why you don’t ever manually modify /nix/store ever ever ever. You could have used nix-store --verify --check-contents --repair to check your store for corrupted files and attempt to repair them from the binary cache.
With that said, this is going to be very difficult to fix. Do nix-store --verify --check-contents --repair to repair as much as you can, but it’s not going to fix everything. Anything that’s generated locally, critically including those .drv paths, will not be repaired. These paths will have to be deleted and purged from the nix DB, but the DB won’t allow you to do that unless everything that depends on them is also deleted and purged.
If you’ve also corrupted non-.drv paths, then you’ll likely have to delete GC roots from the system before those will be allowed to be deleted.
From here you can hopefully rebuild. If these are your system generations that you’ve been messing with, then you must rebuild your system before you reboot, or it will likely fail to boot.
I can’t stress enough how extreme of a circumstance this is, and I strongly urge you to read the manuals and understand the commands I’ve given before you run them. This is why you don’t manually modify the store. Always use commands like nix-store or nix-collect-garbage to make modifications to it.
I’m sorry, I’m new to NixOS and Nix and I truly did search for any command to verify or repair the system but I couldn’t find anything in the places I looked, deleting parts of the store was my last resort.
From your reply, I tried going through the store roots/referrers but I don’t think I can fix it that way. I climbed all the way up the referrer tree and ended up at the store for my current system (at least I think? it’s [...]nixos-system-hostname-24.11[...] and it’s referred to by some paths in /proc/, as well as /nix/var/nix/profiles/system-23-link.) If there’s a way to just reinstall all of nixpkgs somehow, I would take that.
Oh, right, that makes sense. I think you would have to do this from a live image. You would mount your file systems, e.g. at /mnt, and then use --store /mnt to do these operations on that store.
Alright, I got it working! Had a few issues along the way, but I figured them out (having to flush out a couple more packages from the store, a bunch of nix profile links were broken) but everything seems to be working now. I’ll see if this fixes my issues with RustRover. If it doesn’t, 1) I’ll be pretty disappointed and 2) I’ll just go file a ticket with JetBrains support. Thanks for the help!
You missed the whole process about cleaning up the broken paths by deleting them and their referrers-closures. That needed to be done from the live image too, for reasons I forgot to anticipate in my original response but clarified in the following one.
Create an new partition for /nix use nixos-install to install NixOs to the new location, make sure to update your config to use the new store beforehand but leave /boot untouched. After nixos-install completes reboot.