dotfiles/scripts/working/rebuild.sh

23 lines
932 B
Bash
Executable file

#!/usr/bin/env bash
cd $DOTFILES_DIR
git config core.pager cat
echo "Rebuilding..."
current=$(nixos-rebuild list-generations | grep True | awk '{print $4,"generation",$1,"kernel version",$5,"at",$3,$2}')
if [[ $* =~ u ]]; then
rm $DOTFILES_DIR/flake.lock
nix-channel --update
nix flake update
fi
git add . && git diff HEAD --minimal && git commit -am "$current rebuilding"
if [[ $* =~ v ]]; then
sudo nixos-rebuild switch --impure --flake $DOTFILES_DIR#$HOSTNAME
else
sudo nixos-rebuild switch --impure --flake $DOTFILES_DIR#$HOSTNAME &> nixos-switch.log || (cat nixos-switch.log | grep --color error && notify-send -e "NixOS Rebuild Failed!" --icon=software-update-available && exit 1) && notify-send -e "NixOS Rebuilt OK!" --icon=software-update-available
fi
if [[ $* =~ p ]]; then
sync-dotfiles
fi
if [[ $* =~ r ]]; then
notify-send -e "NixOS Rebuild complete, rebooting in 30" && sleep 30
reboot
fi