feat(nixos): add scheduled garbage collection and optimization for Nix 🎨

Implement launchd daemons for automatic Nix garbage collection and store optimization on a weekly schedule. The configuration includes intervals for both tasks to ensure efficient management of Nix store resources.
This commit is contained in:
DannyDannyDanny 2026-03-25 10:49:37 +01:00
parent be4233a53b
commit 309d97c708

View file

@ -3,6 +3,11 @@
let let
alacrittySyncSystemTheme = pkgs.writeShellScriptBin "alacritty-sync-system-theme" alacrittySyncSystemTheme = pkgs.writeShellScriptBin "alacritty-sync-system-theme"
(builtins.readFile ../../scripts/alacritty-sync-system-theme.sh); (builtins.readFile ../../scripts/alacritty-sync-system-theme.sh);
# nix-darwin's nix.gc / nix.optimise require nix.enable; with Determinate (nix.enable = false)
# we schedule the same commands via launchd using nixpkgs' nix CLI (same defaults as upstream modules).
nixGcInterval = [{ Weekday = 7; Hour = 3; Minute = 15; }];
nixOptimiseInterval = [{ Weekday = 7; Hour = 4; Minute = 15; }];
in { in {
# Apple Silicon + nix-darwin basics # Apple Silicon + nix-darwin basics
nixpkgs.hostPlatform = "aarch64-darwin"; nixpkgs.hostPlatform = "aarch64-darwin";
@ -72,6 +77,24 @@ in {
}; };
}; };
launchd.daemons = {
nix-gc-determ = {
command =
"${lib.getExe' pkgs.nix "nix-collect-garbage"} --delete-older-than 14d";
serviceConfig = {
RunAtLoad = false;
StartCalendarInterval = nixGcInterval;
};
};
nix-store-optimise-determ = {
command = "${lib.getExe' pkgs.nix "nix-store"} --optimise";
serviceConfig = {
RunAtLoad = false;
StartCalendarInterval = nixOptimiseInterval;
};
};
};
# Keep for darwin as well (tracks defaults across upgrades) # Keep for darwin as well (tracks defaults across upgrades)
# current max per nix-darwin; bump only if a release notes says so # current max per nix-darwin; bump only if a release notes says so
system.stateVersion = 6; system.stateVersion = 6;