dotfiles/deploy

58 lines
1.2 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
usage="Usage: $(basename $0) [OPTIONS]
Options:
-f, --fresh Remove old content in the nixstore (good for debugging)
-b, --bootloader Reinstall the bootloader
-h, --help Show this message (^_^)"
# delete all cached entries
# to make the system from scratch
collect_garbage () {
sudo nix-collect-garbage --delete-old
}
rebuild_flake () {
# make sure all changes are visible to nixos
git add . --verbose
if [ "$1" = "reinstall-bootloader" ]; then
sudo nixos-rebuild switch --flake . --install-bootloader
else
sudo nixos-rebuild switch --flake .
#nixos-rebuild build --flake .# --cores 8 -j 1
fi
}
# check which flags were given
flag_fresh=false
flag_bootloader=false
for flag in "$@"; do
case "$flag" in
-f|--fresh)
flag_fresh=true ;;
-b|--bootloader)
flag_bootloader=true ;;
-h|--help)
echo "$usage"
exit 0 ;;
*)
echo "[!] Unknown flag \"$flag\""
exit 1 ;;
esac
done
# delete cached items in nixstore
if [ "$flag_fresh" = true ]; then
collect-garbage
exit 0
fi
# nixos-rebuild switch ...
if [ "$flag_bootloader" = true ]; then
collect-garbage
rebuild_flake "reinstall-bootloader"
else
rebuild_flake
fi