What does {lsof} mean in nix-store --query --roots?

Hello! I am new to Nix and trying to gradually move some of my system configuration to nix-darwin + home-manager. I have been trying to upgrade from Emacs 29 to 30 by switching from pkgs.emacs29 to pkgs.emacs… but I still have an Emacs 29 in my store and can’t figure out how to get rid of it (nix-collect-garbage -d and sudo nix-collect-garbage -d don’t do it). More confusingly, trying to figure out why it’s still around gives this:

❯ nix-store --query --roots /nix/store/b0x31dnx08qib6b7g2r534vmcg8dhbhd-emacs-29.4
{lsof} -> /nix/store/b0x31dnx08qib6b7g2r534vmcg8dhbhd-emacs-29.4

and I’m at a loss as to what that means. The docs on garbage collector roots say they “are all store paths” but {lsof} is not a store path, as far as I know. What does this actually mean and how can I clean up my old Emacs?

It’s a process holding a file handle afaik

Probably nix/src/libstore/gc.cc at c97f779dbb4720c5fb87060410a0d6df7202a5ba · NixOS/nix · GitHub I don’t know why I did not find this in the docs but someone must’ve written it down somewhere since I did not look for this line of code before today

You could try to kill the lsof process that still seems to be running(?)

1 Like

Thanks — interesting. I don’t think there is any lsof running?

❯ ps ax | grep lsof
16286 s002  R+     0:00.00 /nix/store/rc5aqp4axf0qdpr45w3m4mmambk230lk-gnugrep-3.11/bin/grep --color=auto lsof

Yes sorry I did not read far enough: nix/src/libstore/gc.cc at c97f779dbb4720c5fb87060410a0d6df7202a5ba · NixOS/nix · GitHub

When you call lsof exactly like nix does, you should see what holds the handle still open.

It seems to be logic to detect an open file even if the /proc/ Ansatz does not work

1 Like

I had the path open in another tmux tab! Unbelievable. cding out of it enabled nix-collect-garbage -d to clean it up. :person_facepalming:

Thanks so much! Hopefully this thread will be useful sometime to someone else confused about what {lsof} means…

1 Like