nixos/scripts/rebuild.sh
Malte Tammena 73ffca6989 [flake] Extract devShell scripts
Also start using writeShellApplication.
2022-04-18 18:12:36 +02:00

49 lines
972 B
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" "." )
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[@]}"