Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems deleting store paths #7488

Open
tpwrules opened this issue Dec 21, 2022 · 2 comments
Open

Problems deleting store paths #7488

tpwrules opened this issue Dec 21, 2022 · 2 comments
Labels

Comments

@tpwrules
Copy link
Contributor

Describe the bug

nix-store --delete /nix/store/<blah> fails, claiming that the path is still alive due to a GC root. However, running nix-store -q --roots /nix/store/<blah> as suggested by Nix shows no GC roots.

The path can be properly deleted using a command such as nix-store -q --referrers-closure /nix/store/<blah> | xargs nix-store --delete

Steps To Reproduce

tpwrules@machine:~$ nix-store -r /nix/store/phrb1ggdm7bbmdqbyy461mrfvl1j781z-neuron-7.5
these 2 paths will be fetched (2.85 MiB download, 12.70 MiB unpacked):
  /nix/store/hlxkwc1fbnsxd1wpgl7sdgalynf4kn5f-iv-19
  /nix/store/phrb1ggdm7bbmdqbyy461mrfvl1j781z-neuron-7.5
copying path '/nix/store/hlxkwc1fbnsxd1wpgl7sdgalynf4kn5f-iv-19' from 'https://cache.nixos.org'...
copying path '/nix/store/phrb1ggdm7bbmdqbyy461mrfvl1j781z-neuron-7.5' from 'https://cache.nixos.org'...
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/phrb1ggdm7bbmdqbyy461mrfvl1j781z-neuron-7.5

tpwrules@machine:~$ nix-store --delete /nix/store/hlxkwc1fbnsxd1wpgl7sdgalynf4kn5f-iv-19
finding garbage collector roots...
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/hlxkwc1fbnsxd1wpgl7sdgalynf4kn5f-iv-19' since it is still alive. To find out why, use: nix-store --query --roots

tpwrules@machine:~$ nix-store -q --roots /nix/store/hlxkwc1fbnsxd1wpgl7sdgalynf4kn5f-iv-19

tpwrules@machine:~$ nix-store -q --referrers-closure /nix/store/hlxkwc1fbnsxd1wpgl7sdgalynf4kn5f-iv-19
/nix/store/hlxkwc1fbnsxd1wpgl7sdgalynf4kn5f-iv-19
/nix/store/phrb1ggdm7bbmdqbyy461mrfvl1j781z-neuron-7.5

tpwrules@machine:~$ nix-store -q --referrers-closure /nix/store/hlxkwc1fbnsxd1wpgl7sdgalynf4kn5f-iv-19 | xargs nix-store --delete
finding garbage collector roots...
deleting '/nix/store/phrb1ggdm7bbmdqbyy461mrfvl1j781z-neuron-7.5'
deleting '/nix/store/hlxkwc1fbnsxd1wpgl7sdgalynf4kn5f-iv-19'
deleting unused links...
note: currently hard linking saves 1593.08 MiB
2 store paths deleted, 12.58 MiB freed

Expected behavior

I expect Nix to not send me on a chase for a GC root which does not exist, and either delete the path and its referrers, or be more clear with the reason the path was not deleted and how to diagnose the problem.

nix-env --version output
nix-env (Nix) 2.12.0

Additional context

This is really a place to centralize the discussion around this issue and provide a workaround as it is a continual problem for me and the community. Other instances of this issue include #7160, #6141 .

This used to work properly in Nix 2.4 and before, but the behavior was changed. The former behavior was somewhat dangerous, but at least it worked. Perhaps it can be reintroduced under a --force flag. In any case the message needs to be fixed, ideally with the names of the paths preventing deletion or the correct command (nix-store --query --referrers-closure) to list them.

There is a similar issue (includes explanation and workaround) triggered by involving sudo. There is also a proposal to delete (as much as possible of) a closure of a specific path, which is in some sense the opposite of the request here (and the reason --recursive was not suggested as the name of the flag above).

There might be a different bug where even the workaround above is not sufficient: #6354 (comment), #6141 (comment) . I could not reproduce these problems myself. If the workaround here does not work for you, please get in touch on Matrix and, if possible, note down the affected store path and create some sort of system snapshot for experimentation.

Priorities

Add 👍 to issues you find important.

@tpwrules tpwrules added the bug label Dec 21, 2022
@DavidEGrayson
Copy link

DavidEGrayson commented Dec 29, 2022

I had a lot of trouble deleting store paths today so I just thought I'd add my voice to this issue. The issue has been fixed now thanks to the amazing advice of @tpwrules, so I can't give exact error messages, but I'll try to relate what happened as accurately as possible.

In my case, /nix/store/gz9ax98bz4866farkgphizsywhm9jkl0-libidn2-2.3.1.drv was missing from the disk, but it was present in the ValidPaths table of the Nix SQLite database.

I tried running nix store delete /nix/store/gz9ax98bz4866farkgphizsywhm9jkl0-libidn2-2.3.1.drv and it just gave me the paradoxical error message that was something like:

Cannot open /nix/store/gz9ax98bz4866farkgphizsywhm9jkl0-libidn2-2.3.1.drv: No such file or directory.

Then I tried this:

$ nix-store --delete /nix/store/gz9ax98bz4866farkgphizsywhm9jkl0-libidn2-2.3.1.drv
finding garbage collector roots...
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/gz9ax98bz4866farkgphizsywhm9jkl0-libidn2-2.3.1.drv' since it is still alive.               To find out why, use: nix-store --query --roots

Now most of the time when I ran nix-store --query --roots /nix/store/gz9ax98bz4866farkgphizsywhm9jkl0-libidn2-2.3.1.drv it would just print a blank line and I'm not sure how to interpret that. If I ran it with sudo then it would print some extra lines that started like "/proc/5499/environ ->".

I tried doing the @tpwrules xargs trick above and it initially didn't work. Then I rebooted and it finally worked, fully deleting the problematic derivation. The final command I ran which worked was:

nix-store -q --referrers-closure /nix/store/gz9ax98bz4866farkgphizsywhm9jkl0-libidn2-2.3.1.drv | xargs nix-store --option keep-outputs false --option keep-derivations false --delete

I did see nix store repair but I don't think I tried it because it didn't seem like it really applies to derivations.

It seems to me like there are no good tools available for repairing the Nix store. The path /nix/store/gz9ax98bz4866farkgphizsywhm9jkl0-libidn2-2.3.1.drv was not a valid path in reality, because it didn't exist. But it was very hard for me to tell the system that it doesn't exist. There should probably be a way to mark it as invalid and delete every other path that depends on it, including GC roots. Or at least if there are real GC roots depending on it, I should be able to see what they are.

@StillerHarpo
Copy link

StillerHarpo commented Jul 3, 2023

This is still a problem. I build this (for testing)

derivation {
  name = "test";
  builder = "/bin/sh";
  args = [ "-c" "echo \"\" > $out"];
  system="x86_64-linux";
}

Running

nix-store --query --roots /nix/store/zirsqs56w9rjccllldjkk21fldmkffn7-test

give no result, however this happens

> nix store delete /nix/store/zirsqs56w9rjccllldjkk21fldmkffn7-test
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/zirsqs56w9rjccllldjkk21fldmkffn7-test' since it is still alive. To find out why, use: nix-store --query --roots
> nix-store -q --referrers-closure /nix/store/zirsqs56w9rjccllldjkk21fldmkffn7-test | xargs nix-store --delete
finding garbage collector roots...
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/zirsqs56w9rjccllldjkk21fldmkffn7-test' since it is still alive. To find out why, use: nix-store --query --roots

nix store gc will delete the path. I tested this on 2 different systems

> nix --version
nix (Nix) 2.15.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants