nixos/rebuild.sh

34 lines
722 B
Bash
Raw Normal View History

2024-03-01 15:22:49 +01:00
#!/usr/bin/env bash
# A rebuild script that commits on a successful build
set -e
# cd to your config dir
pushd ~/dotfiles/nixos/
# Edit your config
$EDITOR
2024-03-01 15:22:49 +01:00
# Autoformat your nix files
alejandra . #&>/dev/null
2024-03-01 15:22:49 +01:00
# Shows your changes
git diff -U0 *.nix
echo "NixOS Rebuilding..."
# Rebuild, output simplified errors, log trackebacks
sudo nixos-rebuild switch &>nixos-switch.log || (cat nixos-switch.log | grep --color error && false)
# Get current generation metadata
current=$(nixos-rebuild list-generations | grep current)
# Commit all changes with the gereation metadata
git commit -am "$current"
# Back to where you were
popd
# Notify all OK!
notify-send -e "NixOS Rebuilt OK!" --icon=software-update-available