From d7447245d8295cf12fa53c94ce1b59a036f17699 Mon Sep 17 00:00:00 2001 From: Viacheslav Lotsmanov Date: Thu, 19 Dec 2024 07:43:00 +0200 Subject: [PATCH] =?UTF-8?q?clean-profile-gc-roots.raku:=20Add=20=E2=80=9C-?= =?UTF-8?q?-nuke-user-home-profiles=E2=80=9D=20feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clean-profile-gc-roots.raku | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/clean-profile-gc-roots.raku b/clean-profile-gc-roots.raku index 83753ec..55cb847 100755 --- a/clean-profile-gc-roots.raku +++ b/clean-profile-gc-roots.raku @@ -19,6 +19,12 @@ $*PROGRAM.dirname.&*chdir; # The main directory of Nix profiles where to find profile symlinks recursively in my IO::Path:D \nixProfilesRootDir = '/nix/var/nix/profiles'.IO; +# Root directory of current user profiles to find profile symlinks recursively in. +# +# For optional “--nuke-user-home-profiles” feature. +my IO::Path:D \userHomeNixProfilesRootDir = + %*ENV.IO.add(".local/state/nix/profiles"); + subset NonEmptyStr of Str where .trim !~~ ''; subset NonEmptyArr of Array where .elems > 0; @@ -782,13 +788,20 @@ sub getNixReleasesToNuke(NukeReleasesStr \releasesStr --> ProfileSymlink::Types: #| `--nuke-releases` accepts one or more NixOS release versions separated by #| comma (e.g. `23.05,23.11`). Note that if you add a release that matches #| current profile it won’t be nuked. -sub MAIN(NukeReleasesStr :$nuke-releases = Nil) { +#| `--nuke-user-home-profiles` is useful for cleaning up Home Manager profiles. +sub MAIN(NukeReleasesStr :$nuke-releases = Nil, Bool:D :$nuke-user-home-profiles = False) { my ProfileSymlink::Types::NixosVersionList:D \nixReleasesToNuke = getNixReleasesToNuke $nuke-releases; my ProfileSymlink::Types::Profile:D %profiles = ProfileSymlink::getDirectoryProfiles nixProfilesRootDir; + if $nuke-user-home-profiles { + my ProfileSymlink::Types::Profile:D %userHomeProfiles = + ProfileSymlink::getDirectoryProfiles userHomeNixProfilesRootDir; + %profiles.append(%userHomeProfiles); + } + my Cleanup::Types::ProfilesCleanupPlanMap:D \cleanupPlan = Cleanup::makePlan %profiles, nixReleasesToNuke;