From 1f910c8b63eaecd0043615db59bcb0c27410da1b Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 14 May 2026 10:57:37 -0700 Subject: [PATCH] Separate monitorHomeProfiles option that defaults to true This gives us a way to put just the new home-profiles management in dry-run mode. This way, home-profiles management can be gently turned on by first enabling monitorHomeProfiles, running for awhile, and only then enabling manageHomeProfiles once it has active-usage data to work with. This also allows a safer path to flipping the manageHomeProfiles default from false to true. --- modules/profile-gc.nix | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/profile-gc.nix b/modules/profile-gc.nix index e2f0e3d..bc6eb5a 100644 --- a/modules/profile-gc.nix +++ b/modules/profile-gc.nix @@ -22,7 +22,7 @@ let parsed=$(systemd-analyze timespan ${escapeShellArg duration} | awk '$1 == "μs:" { print $2 }') echo "$parsed" > "$out" ''; - gather_home_profiles = lib.optionalString cfg.manageHomeProfiles '' + gather_home_profiles = '' while read -r home_dir;do home_profile_dir="$home_dir/.local/state/nix/profiles" if [[ -d "$home_profile_dir" ]];then @@ -34,6 +34,11 @@ in { options = { nix.profile-gc = { enable = lib.mkEnableOption "Automatic profile garbage collection"; + monitorHomeProfiles = lib.mkOption { + description = "Monitor profiles in users' $HOME/.local/state/nix/profiles/"; + type = lib.types.bool; + default = true; + }; manageHomeProfiles = lib.mkOption { description = "Manage profiles in users' $HOME/.local/state/nix/profiles/"; type = lib.types.bool; @@ -120,6 +125,10 @@ in { assertion = cfg.enable -> config.nix.gc.automatic; message = ''nix.profile-gc.enable requires nix.gc.automatic''; } + { + assertion = cfg.manageHomeProfiles -> cfg.monitorHomeProfiles; + message = ''nix.profile-gc.manageHomeProfiles requires nix.profile-gc.monitorHomeProfiles''; + } ]; systemd.services.nix-gc.serviceConfig.ExecStartPre = pkgs.writeShellScript "nix-profile-gc" '' set -euo pipefail @@ -174,7 +183,7 @@ in { ) home_profile_dirs=() - ${gather_home_profiles} + ${lib.optionalString cfg.manageHomeProfiles gather_home_profiles} now=$(${pkgs.coreutils}/bin/date +%s) age_threshold="$(< ${parse-duration cfg.keepLatest})" @@ -238,7 +247,7 @@ in { serviceConfig.Type = "oneshot"; script = '' home_profile_dirs=() - ${gather_home_profiles} + ${lib.optionalString cfg.monitorHomeProfiles gather_home_profiles} ${pkgs.coreutils}/bin/mkdir -p ${cfg.logdir} ${pkgs.coreutils}/bin/readlink /run/current-system >> ${cfg.logdir}/active-system -- 2.51.2