wildfire: 242 current 2025-06-20 13:02:09 25.05.20250617.36ab78d 6.15.2 *

smarter rebuild GC
This commit is contained in:
2025-06-20 13:02:14 +02:00
parent 6f9f670e8e
commit 00ea956f6a
2 changed files with 20 additions and 3 deletions

View File

@ -29,7 +29,7 @@ in {
gaps_in = 5; gaps_in = 5;
gaps_out = 15; gaps_out = 15;
border_size = 1; border_size = 1;
"col.active_border" = "rgba(${colors.gruvbox-rgb.bright_orange}, 1.0) rgba(${colors.gruvbox-rgb.red}, 1.0) 45deg"; "col.active_border" = "rgb(${colors.gruvbox-rgb.bright_orange}) rgb(${colors.gruvbox-rgb.red}) 45deg";
"col.inactive_border" = "rgba(${colors.gruvbox-rgb.bg4}, 0.66)"; "col.inactive_border" = "rgba(${colors.gruvbox-rgb.bg4}, 0.66)";
layout = "dwindle"; layout = "dwindle";
allow_tearing = false; allow_tearing = false;

View File

@ -2,6 +2,13 @@
set -e set -e
# Days of nix generations to keep
KEEP_DAYS=60
# extra buffer before we trigger a GC
BUFFER_DAYS=30
# minimum number of generations to keep
KEEP_MIN=5
# Check for force flag # Check for force flag
FORCE_REBUILD=false FORCE_REBUILD=false
if [[ "$1" == "-f" || "$1" == "--force" ]]; then if [[ "$1" == "-f" || "$1" == "--force" ]]; then
@ -61,7 +68,17 @@ current=$(nixos-rebuild list-generations | grep current)
# Commit all changes witih the generation metadata # Commit all changes witih the generation metadata
git commit -am "$NIXOS_HOST: $current" git commit -am "$NIXOS_HOST: $current"
# Clean up old generations older than 180 days # Clean up old generations if conditions are met
sudo nix-collect-garbage --delete-older-than 180d &>logs/nixos-gc.log || (cat logs/nixos-gc.log | grep --color error && exit 1) gens=$(nixos-rebuild list-generations | tail -n +2)
# If there are less than KEEP_MIN generations, exit
(( $(wc -l <<<"$gens") <= KEEP_MIN )) && exit 0
# Get the oldest generation
old=$(awk 'END{print $2" "$3}' <<<"$gens")
# Calculate the age of the oldest generation in days
age=$(( ( $(date +%s) - $(date -d "$old" +%s) )/86400 ))
# If the age is greater than KEEP_DAYS+BUFFER_DAYS, delete the oldest generation
(( age > KEEP_DAYS+BUFFER_DAYS )) || exit 0
sudo nix-collect-garbage --delete-older-than ${KEEP_DAYS}d &>logs/nixos-gc.log || (cat logs/nixos-gc.log | grep --color error && exit 1)