-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnixhandle
executable file
·183 lines (170 loc) · 3.23 KB
/
nixhandle
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env bash
platform="$(uname)"
switch() {
case $os in
m)
darwin-rebuild switch --flake .
figlet "Switched" | lolcat
nixgit
;;
n)
nixos-rebuild --use-remote-sudo --impure switch
figlet "Switched" | lolcat
nixgit
;;
l)
echo "Work in Progress"
exit 1
;;
*)
echo "uhhh...."
exit 1
;;
esac
}
update() {
case $os in
m)
nix flake update --flake .
darwin-rebuild switch --flake .
figlet "Updooted" | lolcat
git add .
nixgit
;;
n)
sudo nix flake update
nixos-rebuild --use-remote-sudo --impure boot
figlet "Updooted" | lolcat
git add .
nixgit
;;
l)
echo "Work in Progress"
exit 1
;;
*)
echo "uhhhh....."
exit 1
;;
esac
}
nixgit() {
if [ -d .git ];then
echo "Do you want to make a commit? [y/N]: "
read git
if [[ $git = y ]] || [[ $git = Y ]];then
echo "What to label for commit?: "
read commit
git commit -m "$commit"
elif [[ $git = e ]] || [[ $git = exit ]];then
figlet "Complete" | lolcat
exit 1
else
if [[ $1 = g ]] || [[ $1 = "git" ]];then
echo "This was a huge waste of time!"
exit 1
else
clean
fi
fi
echo "Do you want to push the commit? [y/N]: "
read push
if [[ $push == y ]] || [[ $push == Y ]];then
git push
figlet "Commit Pushed"
if [[ $1 != g ]] && [[ $1 != git ]]; then
clean
else
figlet "Commit Pushed" | lolcat
exit 1
fi
elif [[ $push = e ]] || [[ $push = exit ]];then
figlet "Complete!" | lolcat
else
if [[ $1 = g ]] || [[ $1 = git ]];then
echo "This was a huge waste of time"
exit 1
else
clean
fi
fi
else
echo "No Git Repo Found!"
clean
fi
}
clean() {
echo "Want to clean the old generations and old files? [y/N]: "
read clean
if [[ $clean == y ]] || [[ $clean == Y ]];then
sudo nix-env --profile /nix/var/nix/profiles/system --delete-generations old
echo "Cleaning Files"
sudo nix store gc
sudo nix-collect-garbage
sudo nix store optimise
figlet "Cleanup Complete" | lolcat
exit 1
elif [[ $clean = e ]] || [[ $clean = exit ]];then
figlet "Complete" | lolcat
exit 1
else
case $1 in
g | git)
figlet "Commit Made" | lolcat
exit 1
;;
u | update)
figlet "Updated" | lolcat
exit 1
;;
s | switch)
figlet "Switched" | lolcat
exit 1
;;
*)
echo "uhhhh"
exit 1
;;
esac
fi
}
case $platform in
Darwin)
cd $HOME/.config/nixos
os="m"
;;
Linux)
source /etc/os-release
if [[ $ID == nixos ]]; then
cd /etc/nixos
os="n"
else
cd $HOME/.config/nixos
os="l"
fi
;;
*)
echo "Wtf are you doing?"
exit 1
;;
esac
if [[ -d .git ]];then
git add .
fi
case $1 in
g | git)
nixgit $1
;;
u | update)
update
;;
s | switch)
switch
;;
c | clean)
clean $1
;;
*)
echo "No arguments, provided! g for Git, u for Update, s for Switch"
exit 1
esac