From b60a833fe45896ba3182dcee89e834b83d9a44b4 Mon Sep 17 00:00:00 2001 From: chase Date: Tue, 3 Jun 2025 18:09:44 -0400 Subject: [PATCH] Edited nixos rebuild script --- home/scripts/nixswitch.sh | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/home/scripts/nixswitch.sh b/home/scripts/nixswitch.sh index 10aeeee..12d1746 100755 --- a/home/scripts/nixswitch.sh +++ b/home/scripts/nixswitch.sh @@ -1,11 +1,33 @@ #!/usr/bin/env bash -cd ~/nixos-config +# +# NixOS rebuild script +# +# original by 0atman: https://gist.github.com/0atman/1a5133b842f929ba4c1e195ee67599d5 -sudo nixos-rebuild switch --flake . &>nixos-switch.log || (cat nixos-switch.log | grep --color error && exit 1) +set -e + +pushd ~/nixos-config + +if git diff --quiet; then + echo "No changes detected, exiting." + popd + exit 0 +fi + +alejandra . &>/dev/null \ + || ( alejandra . ; echo "formatting failed!" && exit 1) + +git diff -U0 + +echo "NixOS rebuilding..." + +sudo nixos-rebuild switch --flake . &>nixos-switch.log \ + || (cat nixos-switch.log | grep --color error && exit 1) current=$(nixos-rebuild list-generations | grep current) git commit -am "$current" -notify-send -e "NixOS Rebuilt OK!" --icon=software-update-available +popd +notify-send -e "NixOS Rebuilt OK!" --icon=software-update-available