]> git.scottworley.com Git - nix-profile-gc/commitdiff
Separate monitorHomeProfiles option that defaults to true master
authorScott Worley <scottworley@scottworley.com>
Thu, 14 May 2026 17:57:37 +0000 (10:57 -0700)
committerScott Worley <scottworley@scottworley.com>
Thu, 14 May 2026 17:57:37 +0000 (10:57 -0700)
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

index e2f0e3ddfdde276072829f0abdc69f84f637ee21..bc6eb5afb140abb72872f1d609283b5b83833143 100644 (file)
@@ -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