76 lines
2.3 KiB
Nix
76 lines
2.3 KiB
Nix
# ncli/commands/maintenance.nix — cleanup, diag, list-gens, trim, home-backups
|
|
lib: let
|
|
inherit (lib) project;
|
|
in {
|
|
cleanup_case = ''
|
|
echo "Warning! This will remove old generations of your system."
|
|
read -p "How many generations to keep (default: all)? " keep_count
|
|
|
|
if [ -z "$keep_count" ]; then
|
|
read -p "This will remove all but the current generation. Continue (y/N)? " -n 1 -r
|
|
echo
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
nh clean all -v
|
|
else
|
|
echo "Cleanup cancelled."
|
|
fi
|
|
else
|
|
read -p "This will keep the last $keep_count generations. Continue (y/N)? " -n 1 -r
|
|
echo
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
nh clean all -k "$keep_count" -v
|
|
else
|
|
echo "Cleanup cancelled."
|
|
fi
|
|
fi
|
|
|
|
LOG_DIR="$HOME/ncli-cleanup-logs"
|
|
mkdir -p "$LOG_DIR"
|
|
LOG_FILE="$LOG_DIR/ncli-cleanup-$(date +%Y-%m-%d_%H-%M-%S).log"
|
|
echo "Cleaning up old log files..." >> "$LOG_FILE"
|
|
find "$LOG_DIR" -type f -mtime +3 -name "*.log" -delete >> "$LOG_FILE" 2>&1
|
|
echo "Cleanup process logged to $LOG_FILE"
|
|
'';
|
|
|
|
diag_case = ''
|
|
echo "Generating system diagnostic report..."
|
|
{
|
|
echo "=== NixOS System Diagnostic Report ==="
|
|
echo "Generated: $(date)"
|
|
echo ""
|
|
echo "=== System Information ==="
|
|
inxi --full 2>/dev/null || echo "inxi not available"
|
|
echo ""
|
|
echo "=== Git Status ==="
|
|
cd "$HOME/${project}" 2>/dev/null && git status 2>/dev/null || echo "Git status not available"
|
|
echo ""
|
|
} > "$HOME/diag.txt"
|
|
echo "Diagnostic report saved to $HOME/diag.txt"
|
|
'';
|
|
|
|
list_gens_case = ''
|
|
echo "--- User Generations ---"
|
|
nix-env --list-generations | cat || echo "Could not list user generations."
|
|
echo ""
|
|
echo "--- System Generations ---"
|
|
nix profile history --profile /nix/var/nix/profiles/system | cat || echo "Could not list system generations."
|
|
'';
|
|
|
|
trim_case = ''
|
|
echo "Running 'sudo fstrim -v /' may take a few minutes and impact system performance."
|
|
read -p "Enter to run now or enter to exit (y/N): " -n 1 -r
|
|
echo
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
echo "Running fstrim..."
|
|
sudo fstrim -v /
|
|
echo "fstrim complete."
|
|
else
|
|
echo "Trim operation cancelled."
|
|
fi
|
|
'';
|
|
|
|
home_backups_case = ''
|
|
ls -a ~ | grep backup
|
|
'';
|
|
}
|