-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgc.sh
executable file
·46 lines (33 loc) · 1010 Bytes
/
gc.sh
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
#!/bin/sh
# Copyright (c) 2025 tsrk. <[email protected]>
# This file is licensed under the MIT license
# See the LICENSE file in the repository root for more info.
# SPDX-License-Identifier: MIT
# This script runs nix garbage collection commands and store optimisation
sudo_() {
if [ "$UID" -eq 0 ]; then
"$@"
else
sudo "$@"
fi
}
nom_() {
if command -v nom &>/dev/null; then
nom "$@"
else
nix run nixpkgs#nix-output-monitor -- "$@"
fi
}
echo "==> Running GC on 'user' store paths"
nix-collect-garbage \
--delete-older-than 15d \
-v --log-format internal-json |& nom_ --json
echo "==> Running GC on 'root' store paths"
sudo_ true
sudo_ nix-collect-garbage \
-v --log-format internal-json |& nom_ --json
echo "==> Cleaning up boot entries"
sudo_ true
sudo_ /run/current-system/bin/switch-to-configuration boot
echo "==> Running Nix store optimisation with hard-links"
nix store optimise -v -L --log-format internal-json |& nom_ --json