-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.sh
executable file
·117 lines (107 loc) · 2.64 KB
/
make.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
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
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
mode="$1"
shift
case "$mode" in
"build")
systemName="$1"
shift
tmp="$(mktemp -u)"
nix-build --no-link \
--allow-unsafe-native-code-during-evaluation \
"$DOTFILES_DIR" \
-A system \
--argstr systemName "$systemName" \
-o "$tmp/result" \
--keep-going $* >&2
trap "rm '$tmp/result'" EXIT
drv="$(readlink "$tmp/result")"
echo "$drv"
;;
"vm")
systemName="$1"
shift
tmp="$(mktemp -d)"
trap "rm '$tmp/result'" EXIT
pushd $tmp
nix-build --no-link \
--allow-unsafe-native-code-during-evaluation \
"$DOTFILES_DIR" \
--argstr systemName "$systemName" \
-o "result" \
--keep-going \
-A vm $* >&2
command "./result/bin/run-$systemName-vm"
popd
;;
"disk-image")
systemName="$1"
shift
tmp="$(mktemp -d)"
trap "rm '$tmp/result'" EXIT
pushd $tmp
nix-build --no-link \
--allow-unsafe-native-code-during-evaluation \
"$DOTFILES_DIR" \
--argstr systemName "$systemName" \
-o "result" \
--keep-going \
-A diskImage $* >&2
;;
"firmware")
systemName="$1"
shift
if [ "$systemName" != "rpi3" ]; then
echo "can only update firmware for rpi3"
exit 1
fi
tmp="$(mktemp -d)"
trap "rm '$tmp/result'" EXIT
pushd $tmp
nix-build --no-link \
--allow-unsafe-native-code-during-evaluation \
"$DOTFILES_DIR" \
--argstr systemName "$systemName" \
-o "result" \
--keep-going \
-A firmware $* >&2
echo "About to update firmware. Proceed?"
select answer in "Yes" "No"; do
if [ "$answer" != "Yes" ]; then
exit
fi
break
done
if [ ! -d /mnt ]; then
sudo mkdir /mnt
fi
sudo -- "$BASH" -c "mount /dev/disk/by-label/FIRMWARE /mnt; \
rm /mnt/*; \
cp result/* /mnt; \
echo 'Updated FIRMWARE:'; \
ls /mnt; \
umount /mnt
"
echo "Firmware updated. Reboot to apply changes."
;;
"update")
niv update
;;
"switch")
systemName="$1"
shift
drv="$(./make.sh build $systemName)"
sudo nix-env -p /nix/var/nix/profiles/system --set "$drv"
NIXOS_INSTALL_BOOTLOADER=1 sudo --preserve-env=NIXOS_INSTALL_BOOTLOADER "$drv/bin/switch-to-configuration" switch
;;
"clean")
sudo nix-collect-garbage --delete-older-than 7d
nix-collect-garbage --delete-older-than 7d # clean user drv as well
nix store optimise --extra-experimental-features nix-command
;;
*)
exit 1
esac