-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add automatic nix garbage collection and fix macOS shell tests #1514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,11 +213,19 @@ nvim-plugins-install: ## Download/build missing Neovim native plugin binaries (f | |
| switch: nix-switch services nvim-plugins-install dotagents-sync ## Apply Nix configuration, restart services, and sync plugins. | ||
|
|
||
| .PHONY: clean | ||
| clean: ## Clean up old Nix generations and garbage collect. | ||
| clean: ## Clean up Nix generations older than 30 days and garbage collect. | ||
| @echo "🧹 Cleaning up old generations and garbage collecting..." | ||
| @$(SUDO) nix-collect-garbage -d | ||
| @$(SUDO) nix-collect-garbage --delete-older-than 30d | ||
| @nix store optimise | ||
| @echo "✅ Cleanup complete" | ||
|
|
||
| .PHONY: clean-all | ||
| clean-all: ## Delete ALL old Nix generations and garbage collect (nuclear). | ||
| @echo "🧹 Removing all old generations..." | ||
| @$(SUDO) nix-collect-garbage -d | ||
| @nix store optimise | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| @echo "✅ Full cleanup complete" | ||
|
|
||
| .PHONY: reset | ||
| reset: git-submodule-sync ## Reset git status to clean (restore all changes and reinitialize submodules). | ||
| @echo "🔄 Resetting git status to clean..." | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,8 @@ | |
| }; | ||
| gc = { | ||
| automatic = true; | ||
| frequency = "weekly"; | ||
| options = "--delete-older-than 30d"; | ||
| }; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| lib, | ||
| isRunner, | ||
| ... | ||
| }: | ||
| lib.mkIf (!isRunner) { | ||
| launchd.daemons."com.shunkakinoki.nix-gc" = { | ||
| script = '' | ||
| /nix/var/nix/profiles/default/bin/nix-collect-garbage --delete-older-than 30d | ||
| ''; | ||
| serviceConfig = { | ||
| RunAtLoad = false; | ||
| StartCalendarInterval = [ | ||
| { | ||
| Weekday = 0; | ||
| Hour = 3; | ||
| Minute = 0; | ||
| } | ||
| ]; | ||
| }; | ||
| }; | ||
|
Comment on lines
+7
to
+21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of manually defining a |
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,26 @@ | |||||
|
|
||||||
| set -euo pipefail | ||||||
|
|
||||||
| # Portable alternative to `dirname "$(readlink -f "$(command -v cmd)")"`. | ||||||
| # macOS BSD readlink lacks -f; this uses Python as fallback. | ||||||
| resolve_cmd_dir() { | ||||||
| local cmd_path | ||||||
| cmd_path="$(command -v "$1")" | ||||||
| if readlink -f "$cmd_path" >/dev/null 2>&1; then | ||||||
| dirname "$(readlink -f "$cmd_path")" | ||||||
| else | ||||||
| dirname "$(python3 -c "import os; print(os.path.realpath('$cmd_path'))")" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||
| fi | ||||||
| } | ||||||
|
|
||||||
| # Portable file permission query (octal). macOS stat uses -f, GNU uses -c. | ||||||
| portable_stat_perms() { | ||||||
| if stat -c '%a' "$1" 2>/dev/null; then | ||||||
| return | ||||||
| fi | ||||||
| stat -f '%Lp' "$1" | ||||||
| } | ||||||
|
|
||||||
| mock_bin_setup() { | ||||||
| MOCK_BIN="$(mktemp -d)" | ||||||
| MOCK_LOG="$MOCK_BIN/mock.log" | ||||||
|
|
@@ -48,10 +68,12 @@ nix_script_preprocess() { | |||||
|
|
||||||
| # Replace @placeholder@ patterns with actual commands | ||||||
| sed \ | ||||||
| -e 's|@aws@|aws|g' \ | ||||||
| -e 's|@rsync@|rsync|g' \ | ||||||
| -e 's|@bash@|bash|g' \ | ||||||
| -e 's|@sed@|sed|g' \ | ||||||
| -e "s|@aws@|aws|g" \ | ||||||
| -e "s|@rsync@|rsync|g" \ | ||||||
| -e "s|@bash@|bash|g" \ | ||||||
| -e "s|@sed@|sed|g" \ | ||||||
| -e "s|@find@|$(command -v find)|g" \ | ||||||
| -e "s|@stat@|$(command -v stat)|g" \ | ||||||
| "$script" >"$processed" | ||||||
|
|
||||||
| chmod +x "$processed" | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
nix store optimisecommand should be run with$(SUDO)to ensure it has the necessary permissions to hardlink files across the entire Nix store. Since the precedingnix-collect-garbagecommand uses$(SUDO), it is consistent to use it here as well for a full system cleanup.