nix icon indicating copy to clipboard operation
nix copied to clipboard

Add a way to recursively GC paths

Open balsoft opened this issue 2 years ago • 19 comments

Motivation

Refactor GCOptions to make the types reflect possible GC operations, add a way to delete a specific path recursively, and add a --recursive flag to nix store delete.

Context

Fixes https://github.com/NixOS/nix/issues/7239

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • [ ] agreed on idea
  • [ ] agreed on implementation strategy
  • [ ] tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • [ ] documentation in the manual
  • [ ] documentation in the internal API docs
  • [ ] code and comments are self-explanatory
  • [ ] commit message explains why the change was made
  • [ ] new feature or incompatible change: updated release notes

Priorities

Add :+1: to pull requests you find important.

balsoft avatar May 30 '23 08:05 balsoft

Can't this be done using nix-store --delete $(nix-store -qR <path>)?

edolstra avatar May 30 '23 09:05 edolstra

Can't this be done using nix-store --delete $(nix-store -qR )?

AFAIU in that case the entire operation will fail if at least one path in the closure is still alive. This PR adds a way to remote all dead paths in a closure. I should clarify that in the documentation.

balsoft avatar May 30 '23 09:05 balsoft

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

https://discourse.nixos.org/t/tweag-nix-dev-update-49/29047/1

nixos-discourse avatar Jun 12 '23 13:06 nixos-discourse

Still didn't manage to review this (sorry about that, I've blocked an hour tomorrow afternoon for it), but one thing I can say any way is that it will require tests and documentation

thufschmitt avatar Jun 29 '23 05:06 thufschmitt

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

https://discourse.nixos.org/t/tweag-nix-dev-update-50/29793/1

nixos-discourse avatar Jun 29 '23 13:06 nixos-discourse

Just to reassure myself: this covers the use case of release version pinning while using the nix store as backend, right?

(By sort of inverting the logic)

blaggacao avatar Jun 29 '23 13:06 blaggacao

Thanks a lot for doing this!

domenkozar avatar Jul 21 '23 09:07 domenkozar

@balsoft any chance to rebase and squash?

domenkozar avatar Jul 25 '23 10:07 domenkozar

@domenkozar thanks, done

balsoft avatar Jul 27 '23 09:07 balsoft

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

https://discourse.nixos.org/t/2023-08-04-nix-team-meeting-minutes-77/31487/1

nixos-discourse avatar Aug 09 '23 05:08 nixos-discourse

Whats the status for this?

nyabinary avatar Aug 27 '23 13:08 nyabinary

@balsoft this PR doesn't work yet, do you plan to work on it?

domenkozar avatar Nov 15 '23 11:11 domenkozar

Yep. I'm planning to finish the work at some point, definitely.

balsoft avatar Nov 15 '23 19:11 balsoft

@balsoft still the plan?

domenkozar avatar Jan 11 '24 11:01 domenkozar

Yep! Currently tied up on https://github.com/NixOS/nix/pull/9287 , once that's done-ish I'll get back to other PRs including this one!

balsoft avatar Jan 11 '24 15:01 balsoft

I've rewritten it a bit to make it less invasive (kept the original changes under https://github.com/tweag/nix/commits/gc-closure_ because the cleanup of GCOptions is rather nice and it would be good to come back to it later).

I've also changed the interface to use nix store gc <installable> instead as that felt more coherent

thufschmitt avatar Mar 01 '24 16:03 thufschmitt

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

https://discourse.nixos.org/t/tweag-nix-dev-update-55/40996/1

nixos-discourse avatar Mar 08 '24 08:03 nixos-discourse

I've found a bug:

❯ nix store gc /nix/store/w53sjb6pmzdqfcflh92rlmjfzz6xbc33-devenv-shell-env
error:
       error: unexpected argument '/nix/store/w53sjb6pmzdqfcflh92rlmjfzz6xbc33-devenv-shell-env'
Try '/nix/store/a0i9g29xgmk42gjjglzd6k0kzyjkay3n-nix-2.21-devenv/bin/nix --help' for more information.

Where '/nix/store/w53sjb6pmzdqfcflh92rlmjfzz6xbc33-devenv-shell-env is a derivation for nix-shell.

domenkozar avatar Apr 29 '24 15:04 domenkozar

I've also changed the interface to use nix store gc instead as that felt more coherent

I would prefer a different command for that, e.g. nix store delete-path .... Apart from being clearer (you're not doing a GC but deleting a specific path), overloading a command to either delete everything or some paths has the problem that shell code like

nix store gc "${paths[@]}"

will do a full GC if the paths array is empty, which is probably not intended.

edolstra avatar Apr 29 '24 15:04 edolstra