aboutsummaryrefslogtreecommitdiff
path: root/src/bin/gc
blob: 0fd2ca78715ed6a86422ee620d5152fcfc531c34 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
set -eu

usage() {
	cat <<-'EOF'
	Usage:
	  gc
	  gc -h
EOF
}

help() {
	cat <<-'EOF'

	Options:
	  -h, --help    show this message
EOF
}

for flag in "$@"; do
	case "$flag" in
		--)
			break
			;;
		--help)
			usage
			help
			exit
			;;
		*)
			;;
	esac
done

while getopts 'h' flag; do
	case "$flag" in
		h)
			usage
			help
			exit
			;;
		*)
			usage >&2
			exit 2
			;;
	esac
done
shift $((OPTIND - 1))

set -x
before="$(df -h .)"

PROFILES='
per-user/root/channels
per-user/andreh/profile
per-user/andreh/channels
system
'

for p in $PROFILES; do
  doas nix-env --delete-generations old -p "/nix/var/nix/profiles/$p"
done
nix-env --delete-generations old
nix-store --gc
nix-collect-garbage -d

guix gc -d

find ~/ -name 'nohup.out' -exec rm {} \;
rm -rf ~/.local/share/Trash/files/*
find /tmp/ -type f -atime +10 -exec rm {} \; ||:

if command -V docker; then
  echo y | docker system prune -a
  docker rmi "$(docker images -a -q)" ||:
  docker rm "$(docker ps -a -f status=exited -q)" ||:
  docker stop "$(docker ps -a -q)" ||:
  docker rm "$(docker ps -a -q)" ||:
  echo y | docker volume prune
  echo y | docker container prune
fi

notmuch search --output=files --exclude=false tag:deleted | xargs -I{} rm "{}"
notmuch new

after="$(df -h .)"

set +x
echo 'Disk space before and after:'
echo "  before: $before"
echo "  after:  $after"