Can I force-rebuild /nix/store/.links?

Hi everyone,

Somehow or other one of the files in my /nix/store/.links has been corrupted. I am running ZFS and discovered this by running sudo zpool status -v.

Is there some way for me to force nix to rebuild this file? Can’t find much about it online.

I understand that .links consists of hard links to files to deduplicate the nix store, and is created by nix-store --optimize. I was hoping that nix-store --optimize would then rebuild the file, but it doesn’t seem to.

Also, I cannot readlink the link because it is corrupted. So I don’t even know what it is. Hah!

Thanks
M

You can possibly use nix-store --verify --check-contents --repair to attempt to repair any corrupted store paths.

2 Likes

Rebuild from what? The file is, by definition, the same everywhere. If one corrupted that means all are corrupted; of course it can’t rebuild.

This is a hard link, not a symlink. You can’t look at its symbolic target.

What you have to do is find out its inode ID and look for all other files with the same inode ID in the same volume.

find /nix/ -samefile /nix/store/.links/yourlinkhere

Unfortunately nix-store --verify --check-contents --repair fails, presumably when it hits the broken file

Ok, that makes sense

Strangely this produced no results. (Although find did have some trouble looking into some directories, even with sudo. From what I can tell this is some further kind of corruption.)

I can say that not the entire file is corrupted, and I was able to look at large portions of it. From what I can tell it appears to be an ffmpeg binary. I don’t know if this is useful information really.

I think I might try nuking my /nix and rebuilding it off of a bootable USB using nixos-install

Well, I was able to rebuild /nix/store/.links by way of rebuilding my entire /nix. I wrote up the process here, and in case of link rot here’s the gist of it:

I booted into a NixOS installer USB, mounted my machine’s /nix to /mnt/nix, my machine’s /boot to /mnt/boot, and symlinked /mnt/etc/nixos/configuration.nix to my machine’s configuration.nix (which required another mount).

Then I rm -rf’d /mnt/nix/* and finally ran

nixos-install --no-password -I nixpkgs='https://releases.nixos.org/nixos/23.05/nixos-23.05.1092.c7ff1b9b956/nixexprs.tar.xz'

And that seemed to do the trick!

A large hammer, for sure, but certainly applicable to other problems as well.

1 Like