mytools/nswitch
2024-12-13 20:04:00 +01:00

28 lines
721 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/
nvim
printf ">>> auto formating ..."
nix fmt . &> /dev/null
printf " DONE!\n"
git diff -U0 # "*.nix"
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"