-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
executable file
·107 lines (90 loc) · 1.98 KB
/
run
File metadata and controls
executable file
·107 lines (90 loc) · 1.98 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env sh
set -eu
# set -x
set -o pipefail
usage()
{
echo ""
echo "Usage: $0 <option: rebuild-switch|rebuild-boot|collect-garbage|delete-generations> [machine: thorfinn|kuujo] "
echo ""
}
total_args=$#
# validate min args
if (( $total_args < 1 )); then
echo "Expected atleast 1 argument(s), got $total_args"
usage
exit 1
fi
# validate exact args count
validate_exact_args()
{
if (( $total_args != $1 )); then
echo "Expected exactly $1 argument(s), got $total_args"
usage
exit 1
fi
}
run()
{
printf "Running: \033[32m%s\033[0m" "$1"
printf "\n"
script -q -c "$1" /dev/null
}
# rebuild-switch
rebuild_switch()
{
run "sudo nixos-rebuild switch --flake ./hosts#$1"
exit 0
}
rebuild_boot()
{
run "sudo nixos-rebuild boot --flake ./hosts#$1 --show-trace -L -v"
exit 0
}
option="$1"
case $option in
"rebuild-switch")
# validate machine
validate_exact_args 2
machine=$2
case $machine in
"thorfinn" | "kuujo")
rebuild_switch "$machine"
;;
*)
echo "Invalid machine: $machine"
usage
exit 1
esac
;;
"rebuild-boot")
# validate machine
validate_exact_args 2
machine=$2
case $machine in
"thorfinn" | "kuujo")
rebuild_boot "$machine"
;;
*)
echo "Invalid machine: $machine"
usage
exit 1
esac
;;
"collect-garbage")
validate_exact_args 1
run "nix-collect-garbage -d"
run "sudo nix-collect-garbage -d"
exit 0
;;
"delete-generations")
validate_exact_args 1
run "sudo nix profile wipe-history --older-than 7d --profile /nix/var/nix/profiles/system"
exit 0
;;
*)
echo "Invalid option: $option"
usage
exit 1
;;
esac