50 lines
983 B
Bash
50 lines
983 B
Bash
#!/bin/bash
|
|
|
|
function print_help() {
|
|
printf "Usage:"
|
|
printf " %s [ switch | boot | test | build | ... ] [ HOST ]\n" "$0"
|
|
exit 1
|
|
}
|
|
|
|
if [ -z "${1+x}" ]; then
|
|
print_help
|
|
fi
|
|
|
|
action=$1
|
|
|
|
case "$action" in
|
|
"switch" | "boot" | "test")
|
|
optSudo=sudo
|
|
;;
|
|
*)
|
|
optSudo=
|
|
;;
|
|
esac
|
|
|
|
ARGS=("$action")
|
|
|
|
if personal-cache --ping; then
|
|
ARGS+=("--option" "extra-substituters" "$(personal-cache --url)")
|
|
printf "Cache is up and running!\n"
|
|
else
|
|
printf "Cache is down!\n"
|
|
fi
|
|
|
|
if [ -n "${2+x}" ]; then
|
|
host=$2
|
|
ARGS+=("--build-host" "root@$host" "--target-host" "root@$host" "--flake" ".#${host}")
|
|
printf "Building on %s!\n" "$host"
|
|
else
|
|
ARGS+=("--flake" "." "--show-trace")
|
|
printf "Building on localhost!\n"
|
|
fi
|
|
|
|
today=$(date +%Y-%m-%d)
|
|
branch=$(git branch --show-current)
|
|
rev=$(git log -1 --format=%h)
|
|
dirty=$(git diff --quiet || echo '~')
|
|
commit=$(git log --oneline -n1 --format=%B)
|
|
export NIXOS_LABEL="$today-$branch-$rev$dirty $commit"
|
|
|
|
$optSudo nixos-rebuild "${ARGS[@]}"
|