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

Make nix-store --delete explain why a path is alive #4850

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

orivej
Copy link
Contributor

@orivej orivej commented May 25, 2021

Fixes #1810

The output looks like this:

$ nix-store --delete /nix/store/85i1173dllq1s23k5wnyiw9a33k808bp-perl-5.32.1-man
finding garbage collector roots...
need '/nix/store/clp069h9m0hmdhi6v86gf90n1p2gqhr1-nixos-system-orivej-21.05.git.b26b54f0563' because it's a root
need '/nix/store/0ywlmj5i7gsjm0vx9nzmkmr0zrws0lac-perl-5.32.1-env' for '/nix/store/clp069h9m0hmdhi6v86gf90n1p2gqhr1-nixos-system-orivej-21.05.git.b26b54f0563'
need '/nix/store/85i1173dllq1s23k5wnyiw9a33k808bp-perl-5.32.1-man' for '/nix/store/0ywlmj5i7gsjm0vx9nzmkmr0zrws0lac-perl-5.32.1-env'
0 store paths deleted, 0.00 MiB freed
error: cannot delete path '/nix/store/85i1173dllq1s23k5wnyiw9a33k808bp-perl-5.32.1-man' since it is still alive
$ nix-store --delete /nix/store/amfzfi6gfxnjndmmff3kz9vmkq9lzh35-perl-5.32.0-devdoc
finding garbage collector roots...
need '/nix/store/clp069h9m0hmdhi6v86gf90n1p2gqhr1-nixos-system-orivej-21.05.git.b26b54f0563' because it's a root
need '/nix/store/4xixizlfkjp0z8z9xbg76zvgqpjb7rvq-nixos-system-orivej-21.05.git.b26b54f0563.drv' for '/nix/store/clp069h9m0hmdhi6v86gf90n1p2gqhr1-nixos-system-orivej-21.05.git.b26b54f0563'
need '/nix/store/22srqan5h3vk09r0vzqkbnbv4dvb3lx2-system-path.drv' for '/nix/store/4xixizlfkjp0z8z9xbg76zvgqpjb7rvq-nixos-system-orivej-21.05.git.b26b54f0563.drv'
need '/nix/store/68iqmqk0qp6vwwwwgclgkwyr4hbfjq3v-lilypond-2.22.1.drv' for '/nix/store/22srqan5h3vk09r0vzqkbnbv4dvb3lx2-system-path.drv'
need '/nix/store/vyxhlf79jibd4pq0fxfr14fxiq49ri7a-texlive-combined-2021.drv' for '/nix/store/68iqmqk0qp6vwwwwgclgkwyr4hbfjq3v-lilypond-2.22.1.drv'
need '/nix/store/3xnyaqjgd9izsc7a5s5qfc97pi2fxlnd-texlive-combined-2021' for '/nix/store/vyxhlf79jibd4pq0fxfr14fxiq49ri7a-texlive-combined-2021.drv'
need '/nix/store/7d7s9ln9scd20v41r3ihhs7xskyx9cqy-texlive-lualibs-2.73' for '/nix/store/3xnyaqjgd9izsc7a5s5qfc97pi2fxlnd-texlive-combined-2021'
need '/nix/store/li12jji15fz0i71ia90cnnf5i8l9r1zz-texlive-lualibs-2.73.drv' for '/nix/store/7d7s9ln9scd20v41r3ihhs7xskyx9cqy-texlive-lualibs-2.73'
need '/nix/store/2fl1ypicql8gfkzx31c0nfgkps2i939a-lualibs.r57277.tar.xz.drv' for '/nix/store/li12jji15fz0i71ia90cnnf5i8l9r1zz-texlive-lualibs-2.73.drv'
need '/nix/store/cb21wchxnmjkkxlj22qv7782b2is6141-curl-7.74.0.drv' for '/nix/store/2fl1ypicql8gfkzx31c0nfgkps2i939a-lualibs.r57277.tar.xz.drv'
need '/nix/store/0fyhz66ybzb0gnyrnjbl9jma09s220yp-nghttp2-1.41.0.drv' for '/nix/store/cb21wchxnmjkkxlj22qv7782b2is6141-curl-7.74.0.drv'
need '/nix/store/1zf9plakb12amj6f6b2i29b7ssbs95ly-openssl-1.1.1i.drv' for '/nix/store/0fyhz66ybzb0gnyrnjbl9jma09s220yp-nghttp2-1.41.0.drv'
need '/nix/store/jpj7rxchjh6ql0gf2y6s01ii1rdzwlmp-perl-5.32.0.drv' for '/nix/store/1zf9plakb12amj6f6b2i29b7ssbs95ly-openssl-1.1.1i.drv'
need '/nix/store/amfzfi6gfxnjndmmff3kz9vmkq9lzh35-perl-5.32.0-devdoc' for '/nix/store/jpj7rxchjh6ql0gf2y6s01ii1rdzwlmp-perl-5.32.0.drv'
0 store paths deleted, 0.00 MiB freed
error: cannot delete path '/nix/store/amfzfi6gfxnjndmmff3kz9vmkq9lzh35-perl-5.32.0-devdoc' since it is still alive

@roberth
Copy link
Member

roberth commented Jun 2, 2021

I like this functionality, but I don't think printing these info messages (unconditionally) is the responsibility of libstore. Perhaps the method could return a chain of references as a std::vector<string>. The CLI can then print it.

From a practical perspective, this is to prevent that unrelated callers start spamming these messages for no good reason.

@stale
Copy link

stale bot commented Jan 3, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Jan 3, 2022
@@ -558,7 +558,7 @@ bool LocalStore::canReachRoot(GCState & state, StorePathSet & visited, const Sto
if (state.dead.count(path)) return false;

if (state.roots.count(path)) {
debug("cannot delete '%1%' because it's a root", printStorePath(path));
printInfo("need '%1%' because it's a root", printStorePath(path));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with what @roberth said.

Let's return something like:

struct DeadAlready {};
struct IsRoot {};
struct RootedBy { StorePath root; };

typedef std::variant<DeadAlready, IsRoot, RootedBy> OptLiveness;

to indicate why.

state.alive can likewise be a map of:

typedef std::variant<IsRoot, RootedBy> Liveness;

Making OptLiveness be std::optional<Liveness> is fine me too.

@stale stale bot removed the stale label Mar 1, 2022
@asymmetric
Copy link
Contributor

Shut up bot.

@fricklerhandwerk fricklerhandwerk added the UX The way in which users interact with Nix. Higher level than UI. label Sep 9, 2022
@stale stale bot added the stale label May 21, 2023
@jakubgs
Copy link

jakubgs commented Jun 4, 2024

Is this dead?

@roberth
Copy link
Member

roberth commented Jun 6, 2024

Is this dead?

If it's a store path, who knows ;)

I don't think anyone should feel inhibited to work on solving this problem.

To make this more actionable, I think an improved solution could perform a graph search on the retrieved dependency edges, and report the path in the thrown exception.

That's perhaps a bit easier to manage than reporting all the data internally and then still having to implement such logic in the CLI.

(fwiw I wasn't a maintainer yet when I reviewed this; this was from before the Nix team)

@jakubgs
Copy link

jakubgs commented Jun 6, 2024

I would love to work on and learn more about how Nix works internally, but honestly I don't have the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale UX The way in which users interact with Nix. Higher level than UI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tell user why a given path is live when it can't be deleted (continued from #171)
6 participants