-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·92 lines (79 loc) · 1.99 KB
/
build.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
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
#! /usr/bin/env bash
# It has to be up here
set_host() {
read -p "Are you sure you want to set your host to $1? (y/n) : " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]];then
echo $1 > HOST
echo "Done"
else
exit 0
fi
}
USER=$(whoami)
if [ ! -e /home/$USER/nix/HOST ];then
echo "No host defined"
read -p "Enter the name of your host (defined in /outputs/nixos.nix) : " name
set_host $name
fi
HOST=$(cat /home/$USER/nix/HOST)
echo "Current host: $HOST"
nix_build() {
case $2 in
"offline")
echo "Building offline"
nix build $1 --option substitute false;;
*)
nix build $1;;
esac
}
nom_build() {
nom build $1
}
package_update() {
sudo nixos-rebuild switch --flake .#system.$HOST --upgrade
}
rebuild_home() {
nom_build ".#homeConfigurations.$HOST.activation-script" $1
if [ $? -eq 0 ]; then
result/activate
else
echo "Error building home config"
fi
}
rebuild_system() {
sudo nixos-rebuild switch --flake .#$HOST $1
}
install_fresh() {
echo "Are you sure?"
read -p "[y/N]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]];then
echo "Copying system scan"
cp -r /etc/nixos/hardware-configuration.nix ./hosts/$HOST/hardware.nix
echo "Building system..."
sudo nixos-rebuild switch --experimental-features 'nix-command flakes' --flake .#$HOST
echo "Building home..."
rebuild_home
echo "Done"
fi
}
update_flake() {
nix flake update
}
case $1 in
"home")
(cd /home/$USER/nix && rebuild_home $2);;
"system")
(cd /home/$USER/nix && rebuild_system $2);;
"fresh")
(cd /home/$USER/nix && install_fresh);;
"packages")
(cd /home/$USER/nix && package_update);;
"set")
(cd /home/$USER/nix && set_host $2);;
"flake")
(cd /home/$USER/nix && update_flake);;
*)
echo "Options are home, system, set, packages, flake and fresh (might work)"
esac