mytools/nswitch

24 lines
625 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
nix fmt . &>/dev/null
git diff -U0 *.nix
echo "Do you want to rebuild NixOS? [y/N]"
read -r YESNO
if ! [[ "${YESNO,,}" == "y" ]]; then
echo "Exiting ..."
exit 1
fi
echo "Rebuilding NixOS"
sudo nixos-rebuild switch &>nixos-switch.log || (
cat nixos-switch.log | grep --color error && false)
gen=$(nixos-rebuild list-generations | grep current)
git commit -am "$gen"