-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathredeploy.sh
executable file
·83 lines (69 loc) · 2.16 KB
/
redeploy.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
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p jq openssh nix
set -eu -o pipefail
NIXIOSK="$PWD"
if [ "$#" -gt 0 ] && { [ "$1" = "--help" ] || [ "$1" = "-h" ] ; }; then
echo Usage: "$0" retropi1.json retropi1.local
exit 1
fi
flake=
if [ "$#" -gt 0 ] && [ "$1" = --flake ]; then
shift
flake="${1-.#nixosConfiguration}"
if [ "$#" -gt 0 ]; then
shift
fi
fi
custom=./nixiosk.json
if [ -z "$flake" ]; then
if [ "$#" -gt 0 ]; then
custom="$1"
shift
fi
if ! [ -f "$custom" ]; then
echo No "$custom" provided. Consult README.org for a template to use.
exit 1
fi
fi
host=
if [ "$#" -gt 0 ]; then
if [ "${1:0:1}" != "-" ]; then
host="$1"
shift
fi
fi
if [ -z "$host" ]; then
host=
if [ -n "$flake" ]; then
host="$(nix eval --raw "$flake.config.nixiosk.hostName").local"
else
host="$(jq -r .hostName "$custom").local"
fi
echo "No host provided, assuming $host"
fi
if ! ssh "root@$host" true; then
echo "$host is not online. Verify you can reach it via ssh."
exit 1
fi
system=
if [ -n "$flake" ]; then
if [ -z "$(nix eval --raw "$flake.config.system.build.installBootLoader" 2>/dev/null)" ]; then
echo "$flake is does not have a boot loader. Suggestion: remove /boot/raspberrypi.nix from modules."
exit 1
fi
tmpdir="$(mktemp -d)"
cleanup() {
rm -rf "$tmpdir"
}
trap cleanup EXIT
nix --experimental-features 'nix-command flakes' build "$flake.config.system.build.redeploy" --out-link "$tmpdir/system" "$@" ${NIX_OPTIONS:-}
system=$(readlink -f $tmpdir/system)
else
drv=$(nix-instantiate --no-gc-warning \
--arg custom "builtins.fromJSON (builtins.readFile $(realpath "$custom"))" \
"$NIXIOSK/redeploy.nix" -A config.system.build.toplevel ${NIX_OPTIONS:-})
# nix build --keep-going "$system"
system=$(nix-build --keep-going --no-out-link "$system" "$@" ${NIX_OPTIONS:-})
fi
nix copy "$system" --to "ssh://root@$host"
ssh "root@$host" "nix-env -p /nix/var/nix/profiles/system --set $system && $system/bin/switch-to-configuration switch"