-
Notifications
You must be signed in to change notification settings - Fork 0
/
nixos-rebuild.sh
executable file
·58 lines (53 loc) · 1.18 KB
/
nixos-rebuild.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
#!/usr/bin/env bash
set -eEuo pipefail
trap 'echo "Error when executing $BASH_COMMAND at line $LINENO!" >&2' ERR
cd "${BASH_SOURCE[0]%/*}"
info() { echo "[$(date -Iseconds)]" "$@" >&2; }
info STARTING
trap 'info FINISHED' EXIT
test -z "${DEBUG:-}" || set -x
pre_args=()
post_args=(
--print-build-logs --show-trace
# required for `nom` handling
--log-format internal-json -v
)
cmd="${1}"
shift 1
if [[ "${1:-}" == remote=* ]]; then
# remote="[email protected]@etra.netbird.cloud"
# remote="[email protected]"
# remote="etra.netbird.cloud"
# remote="kdn@etra"
# remote="etra"
remote="${1#remote=}"
shift 1
if [[ "${remote}" == *=* ]]; then
name="${remote%=*}"
remote="${remote#*=}"
fi
addr="${remote}"
if [[ "${addr}" == *@* ]]; then
user="${addr%@*}"
addr="${addr##*@}"
fi
if test -z "${name:-}"; then
name="${addr%%.*}"
fi
if test -n "${user:-}"; then
pre_args+=(
--target-host "${user}@${addr}"
)
else
pre_args+=(
--target-host "${addr}"
)
fi
pre_args+=(
--use-remote-sudo
)
post_args+=(
--flake ".#${name}"
)
fi
nixos-rebuild "${pre_args[@]}" "${cmd}" "${post_args[@]}" "${@}" |& nom --json