mytools/nswitch

31 lines
882 B
Bash
Executable file

#!/usr/bin/env bash
# from https://github.com/0atman/noboilerplate/blob/main/scripts/38-nixos.md#dont-use-nix-env
# docstring=quick edit (or ling xD) for nixos config
set -E -o pipefail
shopt -s failglob
export LC_ALL=C.UTF8
cd ~/Projects/NixOS/ || exit 1
nvim
printf ">>> auto formating ..."
nix fmt . &> /dev/null
printf " DONE!\n"
[ -z "$(git diff -U0)" ] && echo ">>> no changes, exiting ..." && "$SHELL" && exit 0
git diff -U0 # "*.nix" # as a seperate command so we get nice colors and pager
printf ">>> Do you want to rebuild NixOS? [y/N]\n"
printf "<<< " && read -r YESNO
if ! [[ "${YESNO,,}" == "y" ]]; then
printf ">>> Exiting ...\n"
exit 1
fi
printf ">>> Rebuilding NixOS\n"
sudo nixos-rebuild switch | tee nixos-switch.log || (
grep --color error nixos-switch.log && false)
gen=$(nixos-rebuild list-generations | grep current)
git commit -am "$gen"
"$SHELL"