How to use nix-store --delete?

Hello!

I’m trying to delete an ISO I built that is currently in the nix store:

  1. I removed the result symbolic link
  2. When running nix-store --delete /nix/store/qrp2lj4dydrr4cyrzgl73afqg7kbdydi-nixos-22.11.20220924.fde244a-x86_64-linux.iso it fails with this error
finding garbage collector roots...
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/qrp2lj4dydrr4cyrzgl73afqg7kbdydi-nixos-22.11.20220924.fde244a-x86_64-linux.iso' since it is still alive. To find out why, use: nix-store --query --roots
  1. as suggested, I run the command but it returns nothing: nix-store --query --roots /nix/store/qrp2lj4dydrr4cyrzgl73afqg7kbdydi-nixos-22.11.20220924.fde244a-x86_64-linux.iso

What am I doing wrong?

If you are sure that nothing depends on it, you can just add the --ignore-liveness, to force deletion. I’ve hit this situation once or twice, might be a bug somewhere but not sure off hand how to triage.

If you wanna be safe before resorting to that, check if a symlink to this output exists anywhere in /nix/var/nix/gcroots

find /nix/var/nix/gcroots/ -type l -exec readlink -f {} \; | grep qrp2l returned nothing

But with --ignore-liveness and running the nix-store command as root, it worked.

I’ll try to see if I can make a reproducible example and report it as a bug.

Check for sudo nix-store --gc --print-roots as well! there might be processes directly or indirectly holding a reference. You need sudo to see their PIDs.

That’s a good idea, I’m going to try again.
Although, I’m certain there any PID holding it because that ISO file was generated a few weeks ago, I see no reason for a PID to have it :sweat_smile: but this deserves trying again.

I found a way to reproduce it, generating a NixOS ISO seems reliable. But it’s super weird, using sudo to find references, there are 2 PID constantly changing that don’t exist when I look for them

solene@t470 ~/d/iso (master)> nix-store --delete /nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso
finding garbage collector roots...
removing stale link from '/nix/var/nix/gcroots/auto/9hvx7qbzij3f59gri8a1hmw53hjckgwg' to '/home/solene/dev/iso/result'
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso' since it is still alive. To find out why, use: nix-store --query --roots

solene@t470 ~/d/iso (master) [1]> nix-store --query --roots /nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso

solene@t470 ~/d/iso (master)> sudo nix-store --query --roots /nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso
/proc/13444/environ -> /nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso
/proc/13449/environ -> /nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso

solene@t470 ~/d/iso (master)> sudo nix-store --query --roots /nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso
/proc/13465/environ -> /nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso
/proc/13470/environ -> /nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso

solene@t470 ~/d/iso (master)> sudo nix-store --query --roots /nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso
/proc/13595/environ -> /nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso
/proc/13600/environ -> /nix/store/29qxfyv1gr5qxkvx0y3bs2chhg8a9f46-nixos-22.11.20220924.fde244a-x86_64-linux.iso

Some users in the inofficial discord made the assumption that nix itself or the shell invoking it is holding the reference.

This could not been confirmed nor reproduced so far.

But problems like this come up occasionally.

It seems I’m lucky as I can reproduce it 100% of the time…

I’ll open an issue in Nix repo.

I mean, can you make use of lsof or something similar that tells you those pids are nix or your shell or terminal emulator?

This is what we failed to reproduce/confirm!

there is already Cannot delete a store path when sudo-ing nix-store --delete $storePath · Issue #7053 · NixOS/nix · GitHub

I can’t look at the PID because they instantly vanish after calling nix