Improve rebuild script

This commit is contained in:
2026-01-26 17:14:53 +00:00
parent e3b28f3bfc
commit 4102f034e6

View File

@@ -63,21 +63,24 @@
(pkgs.writeShellScriptBin "rebuild" '' (pkgs.writeShellScriptBin "rebuild" ''
#! /bin/bash #! /bin/bash
set -e set -e
pushd ~/dotfiles
# ANSI color codes
GRAY='\e[90m'
ORANGE='\e[38;5;214m'
RESET='\e[0m'
pushd ~/dotfiles > /dev/null
git diff -U0 *.nix git diff -U0 *.nix
echo "NixOS Rebuilding..." echo -e "''${ORANGE}NixOS Rebuilding...''${RESET}"
if ! sudo nixos-rebuild switch --flake ./nixos#TrudePC &> ~/.nixos-rebuild.log; then if ! sudo nixos-rebuild switch --flake ./nixos#TrudePC &> ~/.nixos-rebuild.log; then
cat ~/.nixos-rebuild.log | grep --color error cat ~/.nixos-rebuild.log | grep --color error
exit 1 exit 1
fi fi
echo "Activating home-manager..." echo -e "''${ORANGE}Activating home-manager...''${RESET}"
~/.local/state/home-manager/gcroots/current-home/activate echo -e "''${GRAY}$(~/.local/state/home-manager/gcroots/current-home/activate)''${RESET}"
gen=$(nixos-rebuild list-generations | grep current) echo -e "''${ORANGE}Cleaning up old generations...''${RESET}"
echo "Pushing changes..." echo -e "''${GRAY}$(sudo nix-collect-garbage --delete-older-than 15d 2>&1)''${RESET}"
git commit -am "$gen" popd > /dev/null
git push
sudo nix-collect-garbage --delete-older-than 15d
popd
'') '')
]; ];