nix-community / lorri

Your project’s nix-env [maintainer=@Profpatsch,@nyarly]
Apache License 2.0
638 stars 24 forks source link

feature: add a command to remove gc roots for old or removed projects #63

Closed symphorien closed 1 year ago

symphorien commented 2 years ago

I copied the functionality and option names of nix-store --gc --print-roots and nix-collect-garbage --delete-older-than. To print the original project a gc root corresponds to, I store a symlink to the shell.nix file along with the gc root.

Profpatsch commented 2 years ago

Before looking at this PR, here’s an unprimed design mockup of what I’d expect the gc root cleaning CLI to look like:

GC

lorri gc info

Shows info about projects (shell files) that exist and have been evaluated.

Shows info about which projects don’t have a corresponding directory (or just can’t be reached anymore)

--json prints a json representation that can be parsed in scripts. It contains

lorri gc rm --shell-file path/to/shell.nix --shell-file …

Removes any gc roots to the shell file, so that the next nix garbage collect removes the project store paths.

Removes the project from lorri’s database.

Afterwards runs nix-store --delete on all drvs and store paths that we know about (how to determine? Do we have references to the store paths? Or do we need an extra nix-store --query to find the paths?

Since there is no way to figure out if a drv has some IfD-paths it instantiates (is there?), we should print a message to run nix-store --gc to remove all artifacts, also the ones from previous runs.

lorri gc rm --all

Removes all gc roots that were created by lorri.

Convenience for parsing gc info --json and constructing a long gc rm command line with all files.

lorri gc rm --older-than=\<days>

Removes all gc roots that haven’t been updated <days> ago.

Convenience for parsing this information from the gc info --json output and creating a gc rm command line with all files.

symphorien commented 2 years ago

I implemented something very close to what you proposed. Differences:

symphorien commented 2 years ago

I rebased but ci fails because cachix/cachix-action is out of date.

symphorien commented 2 years ago

I pushed a commit updating nix-related actions. It fixes CI on ubuntu at least.

symphorien commented 2 years ago

could you review again, @Profpatsch ?

symphorien commented 2 years ago

ping @Profpatsch

nyarly commented 1 year ago

@symphorien Apologies for letting this linger so long. Could you merge canon back to your branch? Notably, the CI configs need to be updated (I think -X theirs would work fine)

symphorien commented 1 year ago

done

symphorien commented 1 year ago

ci fixed :)