NixOS / nix

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

nix-store --verify --repair tripping on files that aren't in the store #5765

Open andir opened 2 years ago

andir commented 2 years ago

Describe the bug

I've just ran nix-store --verify --repair on my system to check the integrity of my store. Unfortunately that didn't work as Nix complained about a path that isn't in the (current?) store:

$ nix-store --verify --repair
reading the Nix store...
checking path existence...
error: path '/foo/nix/store/005wyppmhxmbwc9lj8vy26bjms0mc0n6-unit-gnome-session.target' is not in the Nix store

I am certain that at some point I had used /foo to test with an alternative store path. Nix should still try to verify the rest of the (valid) store paths regardless of the database containing whatever it currently contains.

Steps To Reproduce

This is my best guess as this likely happened a while ago.

  1. Build something into a temporary store / a chrooted store / perhaps even the execution of nix tests?
  2. At some point you should have a /foo/nix/store path in your sqlite db.
  3. Running the above nix-store command should fail as posted above.

Expected behavior

Invalid paths should / can be reported but it should really try to verify the other still valid paths in the store instead of bailing on some path that doesn't exist.

nix-env --version output 2.4

arianvp commented 2 years ago

I got into this situation on MacOS for some reason.

funnily enough nix-store --verify --repair works but the experimental nix command trips up:

arian@Arians-MacBook-Pro ~ % sudo nix store verify --all --no-trust
error: getting status of '/nix/store/3glray2y14jpk1h6i599py7jdn3j2vns-mkdir.drv': No such file or directory
arian@Arians-MacBook-Pro ~ % sudo nix store repair --all           
error: cannot repair path '/nix/store/3glray2y14jpk1h6i599py7jdn3j2vns-mkdir.drv'

I then touched the file to solve. But repair doesn't handle when .drv files are corrupted:

% sudo nix store repair /nix/store/3glray2y14jpk1h6i599py7jdn3j2vns-mkdir.drv
error: error parsing derivation '/nix/store/3glray2y14jpk1h6i599py7jdn3j2vns-mkdir.drv': error: expected string 'Derive(['

so i then copied another .drv file but now nix segfaults:

arian@Arians-MacBook-Pro store % sudo cp zzwv8gdmaia5pwllm6kwcr7y0bs8yjav-apple-framework-AudioUnit-11.0.0.drv /nix/store/3glray2y14jpk1h6i599py7jdn3j2vns-mkdir.drv
arian@Arians-MacBook-Pro store % sudo nix store repair /nix/store/3glray2y14jpk1h6i599py7jdn3j2vns-mkdir.drv                                                        
this path will be fetched (0.03 MiB download, 0.12 MiB unpacked):
  /nix/store/8likbyrypv66bhsc7jpds6j3fyj1w02p-mkdir
[0.0 MiB DL]zsh: segmentation fault  sudo nix store repair /nix/store/3glray2y14jpk1h6i599py7jdn3j2vns-mkdir.drv

:shrug:

andir commented 1 year ago

Still the same with 2.11.0:

$ nix-store --verify --repair
reading the Nix store...
checking path existence...
error: path '/foo/nix/store/005wyppmhxmbwc9lj8vy26bjms0mc0n6-unit-gnome-session.target' is not in the Nix store
$ nix --version
nix (Nix) 2.11.0
wucke13 commented 11 months ago

I'm also getting

error: getting status of '/nix/store/p6dnqlq09jwcka4acqyrxpja284yzlss-bash-5.1.tar.gz.drv': No such file or directory

from a sudo nix store verify --all on

yu-re-ka commented 10 months ago

I'm also running into this having used an alternative store path previously. Is there any workaround?