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

Cannot delete store path with no roots #6141

Open
asymmetric opened this issue Feb 21, 2022 · 20 comments
Open

Cannot delete store path with no roots #6141

asymmetric opened this issue Feb 21, 2022 · 20 comments
Labels
bug error-messages Confusing messages and better diagnostics new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store

Comments

@asymmetric
Copy link
Contributor

Describe the bug

Can't delete a store path, even if it isn't reachable by any root.

Steps To Reproduce

❯ nix store delete /nix/store/r3n40nbgq8x9kac2lg3b1daw9g8kxp4q-centrifuge-chain-2.0.0-2df8df-source
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/r3n40nbgq8x9kac2lg3b1daw9g8kxp4q-centrifuge-chain-2.0.0-2df8df-source' since it is still alive. To find out why, use: nix-store --query --roots
❯ nix-store -q --roots /nix/store/r3n40nbgq8x9kac2lg3b1daw9g8kxp4q-centrifuge-chain-2.0.0-2df8df-source
{temp:3862} -> /nix/store/mqvmj5rijym5nkj0p05nddb3jaf5s85k-centrifuge-chain-2.0.0-2df8df-vendor.tar.gz.drv
{temp:3862} -> /nix/store/r3n40nbgq8x9kac2lg3b1daw9g8kxp4q-centrifuge-chain-2.0.0-2df8df-source
{temp:3862} -> /nix/store/9qy3ksajzqkdm77nc3wkcc2kix3w7z83-centrifuge-chain-2.0.0-2df8df.drv
❯ rm -f `/nix/var/nix/temproots/3862
❯ nix-store -q --roots /nix/store/r3n40nbgq8x9kac2lg3b1daw9g8kxp4q-centrifuge-chain-2.0.0-2df8df-source

i.e. no output

❯ nix store delete /nix/store/r3n40nbgq8x9kac2lg3b1daw9g8kxp4q-centrifuge-chain-2.0.0-2df8df-source
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/r3n40nbgq8x9kac2lg3b1daw9g8kxp4q-centrifuge-chain-2.0.0-2df8df-source' since it is still alive. To find out why, use: nix-store --query --roots
❯ nix store delete --ignore-liveness /nix/store/r3n40nbgq8x9kac2lg3b1daw9g8kxp4q-centrifuge-chain-2.0.0-2df8df-source
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/r3n40nbgq8x9kac2lg3b1daw9g8kxp4q-centrifuge-chain-2.0.0-2df8df-source' since it is still alive. To find out why, use: nix-store --query --roots

Expected behavior

I should be able to remove the store path.

nix-env --version output

nix-env (Nix) 2.6.0

Additional context

Question posted on Discourse.

@asymmetric asymmetric added the bug label Feb 21, 2022
@manveru
Copy link
Contributor

manveru commented Feb 26, 2022

I also encountered the same issue, and it's caused by nix checking all /proc/*/environ files for references to that path... which just happens to include invocations of nix store delete. I only managed to delete paths using sudo nix store delete --ignore-liveness.

IMHO the liveness check should exclude its own PID.

@manveru
Copy link
Contributor

manveru commented Feb 26, 2022

also seems to be a duplicate of #6135

@Artturin
Copy link
Member

same issue here

> ./result/bin/nix store delete /nix/store/51cgjmc4ql9r8w8953y865fhbg63cxq9-zlib-1.2.11-static --ignore-liveness
0 store paths deleted, 0.00 MiB freed
error: you are not allowed to ignore liveness
> ./result/bin/nix store delete /nix/store/51cgjmc4ql9r8w8953y865fhbg63cxq9-zlib-1.2.11-static
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/51cgjmc4ql9r8w8953y865fhbg63cxq9-zlib-1.2.11-static' since it is still alive. To find out why, use: nix-store --query --roots
> nix-store --query --roots /nix/store/51cgjmc4ql9r8w8953y865fhbg63cxq9-zlib-1.2.11-static

@tomberek
Copy link
Contributor

Sometimes it is better to do:

nix-store --query --referrers /nix/store/k43kmk5gnd2k1bi2k94ps5rp0ajwrqp1-source | xargs nix-store --delete

as it is not a root, but a drv blocking deletion (nix.conf: keep-derivations?)

@573
Copy link

573 commented Jun 24, 2022

Sometimes it is better to do:

nix-store --query --referrers /nix/store/k43kmk5gnd2k1bi2k94ps5rp0ajwrqp1-source | xargs nix-store --delete

as it is not a root, but a drv blocking deletion (nix.conf: keep-derivations?)

Followed in my case by:

nix-store --delete /nix/store/k43kmk5gnd2k1bi2k94ps5rp0ajwrqp1-source

so not only the drv store path gets deleted.

@winterqt
Copy link
Member

winterqt commented Aug 4, 2022

I can reproduce this on Darwin (which rules out /proc checking), with Nix 2.10.3:

  • --roots is blank
  • --referrers is also blank
  • I can delete other paths just fine
  • GC removes the path just fine

If there are any other details I can add to aid debugging, please let me know.

@DavHau
Copy link
Member

DavHau commented Oct 18, 2022

Sometimes it is better to do:

nix-store --query --referrers /nix/store/k43kmk5gnd2k1bi2k94ps5rp0ajwrqp1-source | xargs nix-store --delete

as it is not a root, but a drv blocking deletion (nix.conf: keep-derivations?)

This did the trick for me, though the other referrers weren't .drv's but just other normal store paths.

Should the error message of nix store --delete be changed to this?:

error: Cannot delete path '...' since it is still alive. To find out why, use:
  - nix-store --query --roots '...'
  - nix-store --query --referrers '...'

@drupol
Copy link
Contributor

drupol commented Nov 26, 2022

Hi!

I got the same issue, but I can't find a proper way to remove it from the store:

image

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-store-cannot-remove-a-package/20770/11

@risicle
Copy link

risicle commented Mar 19, 2023

I've also come across this, in my case it was extra puzzling because the path in question (a .drv) didn't even have any referrers as such, it was because of keep-derivations (on by default) meaning that I would have to also include the .drv's output paths in the delete request too for it to work.

This issue (and its variants) having kicked around for multiple years, I really think the "quick win" would be to simply change the error message @

"Cannot delete path '%1%' since it is still alive. "
to be less incorrect. When it gets to that point in the code what it actually means is:

Cannot delete path foo because it has referrers or output paths that weren't included in the delete request.

If we were really feeling fancy we could conditionally include the "or output paths" part only if keep-derivations were set and/or direct people to find these via --referrers or --outputs.

@symphorien
Copy link
Member

Sometimes it is better to do:

nix-store --query --referrers /nix/store/k43kmk5gnd2k1bi2k94ps5rp0ajwrqp1-source | xargs nix-store --delete

as it is not a root, but a drv blocking deletion (nix.conf: keep-derivations?)

I had to use --referrers-closure to be able to delete. Thank you for the trick!

@ca5ua1
Copy link

ca5ua1 commented Mar 21, 2023

I had to use --referrers-closure to be able to delete. Thank you for the trick!

Thanks! The only thing that worked that easily!

nix-store --query --referrers-closure /nix/store/k43kmk5gnd2k1bi2k94ps5rp0ajwrqp1-source | xargs nix-store --delete

I guess it removes entire system derivation but in my case it's fine (I guess???)

@ca5ua1
Copy link

ca5ua1 commented Mar 21, 2023

My story in nutshell:

I got broken Nextcloud instance after instilling NC app (app resulted broken) on existent instance. I tried to deal with it via nextcloud-occ and got it working. Then tried to reinstall it via NixOS config. At the end of the night Nextcloud (in maintance mode) tried to update app that doesn't exist but the thing is that for unknown reason it was referencing for previous system derivation????
Nextcloud[1956]: {"reqId":"wZHJOcrgc8FK0nT5k5fB","level":3,"time":"2023-03-21T00:20:09+00:00","remoteAddr":"","user":"--","app":"PHP","method":"","url":"--","message":"Cannot declare class OCA\\Recognize\\AppInfo\\Application, because the name is already in use at /nix/store/l20b0hdn36rqfx1igzwpwyibbmrpk12n-source-patched/lib/AppInfo/Application.php#25","userAgent":"--","version":"25.0.4.1","data":{"app":"PHP"}}

# nix-store --query  --referrers-closure /nix/store/l20b0hdn36rqfx1igzwpwyibbmrpk12n-source-patched/
/nix/store/l20b0hdn36rqfx1igzwpwyibbmrpk12n-source-patched
/nix/store/mmjhhcbk2cw7w9vfr0cfl9x0mmkh98c9-nix-apps
/nix/store/nj253ndrjmi63d06mf9r2vi606giaf2v-unit-script-nextcloud-setup-start
/nix/store/pr75md91blwfycqivlzdfnhm9gwx50s3-unit-nextcloud-setup.service
/nix/store/7z42i3cpm63ssg5kcig3ba9vvbyby8a1-system-units
/nix/store/hkrdlswphc272kg9k09zq550glpyv46p-etc
/nix/store/s0wazf7fidnvdp9abi8bbsxb0wsifqsq-nixos-system-Servicer01-22.11.2510.103fe0800b9

@risicle
Copy link

risicle commented Mar 21, 2023

On a side note, my guess would be that if you also have keep-outputs enabled, the two would form reference loops that would only be manually removable by identifying the loop and specifying all the participants in the delete request together. I have not tried this.

@bobvanderlinden
Copy link
Member

I also ran into this problem. For me it was triggered because (I think) my disk was full and Nix wrote a large number of empty .drv files. The error I kept getting was:

error: error parsing derivation ‘/nix/store/XXX.drv’: expected string ‘Derive([’

I was able to delete each of them manually using the command from #6141 (comment), but it seemed there was no end to the number of .drv.

To delete all empty .drv:

find /nix/store -maxdepth 1 -name '*.drv' -type f -empty | xargs nix-store --query --referrers-closure | xargs nix-store --delete

@fricklerhandwerk fricklerhandwerk added new-cli Relating to the "nix" command error-messages Confusing messages and better diagnostics store Issues and pull requests concerning the Nix store labels Sep 4, 2023
@KCynk
Copy link

KCynk commented Nov 11, 2023

NixOS/nixpkgs#266858

@thufschmitt thufschmitt added this to the CLI Stabilisation milestone Dec 20, 2023
@thufschmitt thufschmitt moved this to To triage in Nix team Dec 22, 2023
@thufschmitt thufschmitt removed the status in Nix team Dec 22, 2023
@edolstra
Copy link
Member

edolstra commented Jan 5, 2024

Nix team discussion notes:

@herberteuler
Copy link
Member

herberteuler commented Apr 3, 2024

I came across a similar issue. In my case, the paths were of the pattern /nix/store/...-system-path. It was after a system rebooting that these paths became recyclable.

The paths led me to discover the redundant system-paths were not system-paths themselves though; they were other paths. nix-store --query --referrers was able to show referrers for those paths, which included system-paths. However, nix-store --query --referrers showed nothing but the system-paths as referrers to system-paths.

@ayrtons2k
Copy link

ayrtons2k commented Jun 6, 2024

Guys, Im new to Nix and having a ball setting up my box (using flakes and HM)... until today.

I am now having this issue myself have tried al the suggestions above:

sudo nix-store --query --referrers /nix/store/qrs0f7n5v9hgw8kqbl5lff32wjrb6rm4-source

no result

nix-store --delete /nix/store/k43kmk5gnd2k1bi2k94ps5rp0ajwrqp1-source

finding garbage collector roots... deleting '/nix/store/k43kmk5gnd2k1bi2k94ps5rp0ajwrqp1-source' deleting unused links... note: currently hard linking saves 2476.05 MiB 1 store paths deleted, 0.00 MiB freed

No effect

sudo nix-store --delete /nix/store/qrs0f7n5v9hgw8kqbl5lff32wjrb6rm4-source --ignore-liveness

finding garbage collector roots... deleting '/nix/store/qrs0f7n5v9hgw8kqbl5lff32wjrb6rm4-source' deleting unused links... note: currently hard linking saves 2476.05 MiB 1 store paths deleted, 0.01 MiB freed

No effect

*nix-store --query --referrers /nix/store/qrs0f7n5v9hgw8kqbl5lff32wjrb6rm4-source | xargs nix-store --delete

finding garbage collector roots... deleting unused links... note: currently hard linking saves 2476.05 MiB 0 store paths deleted, 0.00 MiB freed

No effect

Any other workarounds you can think of? Thanks in advance

@FeliciousX
Copy link

FeliciousX commented Aug 12, 2024

i've also recently encountered this.

nix-store --delete /nix/store/vvvk6igaqw7xr8zskqx5dd7fy3761zpn-coreutils-armv7l-unknown-linux-gnueabihf-9.3

outputs:

finding garbage collector roots...
removing stale link from '/nix/var/nix/gcroots/auto/ivk1qq0phqsam4bzwdbdpz4f2la5w4q0' to '/tmp/nixos-rebuild.jpEVXl/nixos-rebuild'
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/vvvk6igaqw7xr8zskqx5dd7fy3761zpn-coreutils-armv7l-unknown-linux-gnueabihf-9.3' since it is still alive. To find out why, use: nix-store --query --root
nix-store --query --roots /nix/store/vvvk6igaqw7xr8zskqx5dd7fy3761zpn-coreutils-armv7l-unknown-linux-gnueabihf-9.3

returns empty

nix-store --query --referrers /nix/store/vvvk6igaqw7xr8zskqx5dd7fy3761zpn-coreutils-armv7l-unknown-linux
-gnueabihf-9.3

output:-

/nix/store/vvvk6igaqw7xr8zskqx5dd7fy3761zpn-coreutils-armv7l-unknown-linux-gnueabihf-9.3
/nix/store/apn3kd0k28pv4spgfgaclrwvr652pl7w-nixos-rebuild
/nix/store/h0bbhl4sa58kz5r8xyhcbmd2n3pg4371-lvm2-armv7l-unknown-linux-gnueabihf-2.03.22-bin
/nix/store/j355bha459zjbpaj4qr86qr7028fidxg-lvm2-armv7l-unknown-linux-gnueabihf-2.03.22
/nix/store/jn645ph9w88arjyqj28ay7cjv0pq1l8f-fix-blkdeactivate.patch
/nix/store/np9nnakxmnkqfiz2afimdi84fpwwjl7s-kbd-armv7l-unknown-linux-gnueabihf-2.6.3
/nix/store/ws680sb6vmjhxhzka4ydnp3wvv2dslag-systemd-armv7l-unknown-linux-gnueabihf-254.10
nix-store --query --referrers /nix/store/vvvk6igaqw7xr8zskqx5dd7fy3761zpn-coreutils-armv7l-unknown-linux
-gnueabihf-9.3 | xargs nix-store --delete

outputs:

finding garbage collector roots...
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/apn3kd0k28pv4spgfgaclrwvr652pl7w-nixos-rebuild' since it is still al
ive. To find out why, use: nix-store --query --roots
nix-store --query --roots /nix/store/apn3kd0k28pv4spgfgaclrwvr652pl7w-nixos-rebuild
nix-store --query --referrers /nix/store/apn3kd0k28pv4spgfgaclrwvr652pl7w-nixos-rebuild

both returns nothing

nix-store --query --referrers-closure /nix/store/apn3kd0k28pv4spgfgaclrwvr652pl7w-nixos-rebuild

returns itself? im not sure how that works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug error-messages Confusing messages and better diagnostics new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store
Projects
Status: Defined work
Development

Successfully merging a pull request may close this issue.