From 309d97c708c94852c7bf0914bd6af724a9b9f476 Mon Sep 17 00:00:00 2001 From: DannyDannyDanny Date: Wed, 25 Mar 2026 10:49:37 +0100 Subject: [PATCH] feat(nixos): add scheduled garbage collection and optimization for Nix :zap::art: 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. --- nixos/hosts/daniel-macbook-air.nix | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/nixos/hosts/daniel-macbook-air.nix b/nixos/hosts/daniel-macbook-air.nix index 63bb3f9..11ead3e 100644 --- a/nixos/hosts/daniel-macbook-air.nix +++ b/nixos/hosts/daniel-macbook-air.nix @@ -3,6 +3,11 @@ let alacrittySyncSystemTheme = pkgs.writeShellScriptBin "alacritty-sync-system-theme" (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 { # Apple Silicon + nix-darwin basics 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) # current max per nix-darwin; bump only if a release notes says so system.stateVersion = 6;