From b3add6ddf85b3f1ff1885b1836e9f7fd7f1283a1 Mon Sep 17 00:00:00 2001 From: John Ogle Date: Sat, 6 Dec 2025 13:58:26 -0800 Subject: [PATCH] Add automatic garbage collection for home-manager user profiles Configure nix.gc to automatically clean up old home-manager generations weekly, which complements the existing system-level gc. Uses --delete-older-than 10d on Linux to maintain a rollback window, but overrides to -d on Darwin to work around a launchd bug where multi-part options aren't properly split into separate arguments. --- home/roles/base-darwin/default.nix | 4 ++++ home/roles/base/default.nix | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/home/roles/base-darwin/default.nix b/home/roles/base-darwin/default.nix index 1b89696..cc2503d 100644 --- a/home/roles/base-darwin/default.nix +++ b/home/roles/base-darwin/default.nix @@ -4,4 +4,8 @@ imports = [ ../aerospace ]; + + # Override to use -d instead of --delete-older-than on Darwin due to launchd bug + # https://github.com/nix-community/home-manager/issues/7211 + nix.gc.options = "-d"; } diff --git a/home/roles/base/default.nix b/home/roles/base/default.nix index d529a8d..31adcae 100644 --- a/home/roles/base/default.nix +++ b/home/roles/base/default.nix @@ -24,6 +24,17 @@ in tree ]; + # Automatic garbage collection for user profile (home-manager generations). + # This complements system-level gc which only cleans system generations. + # - Linux: Uses --delete-older-than to keep 10-day rollback window + # - Darwin: Overridden to use -d in base-darwin role to avoid launchd bug + # (https://github.com/nix-community/home-manager/issues/7211) + nix.gc = { + automatic = true; + randomizedDelaySec = mkIf pkgs.stdenv.isLinux "14m"; + options = "--delete-older-than 10d"; + }; + # Essential programs everyone needs programs.bash = { enable = true;