flake/switch.sh
2025-03-05 09:48:12 +01:00

24 lines
639 B
Bash

#!/usr/bin/env bash
set -euo pipefail
bold=$(tput bold)
reset=$(tput sgr0)
script_path=$(readlink -f "${BASH_SOURCE[0]}")
flake=$(dirname "$script_path")
echo "${bold}Building configuration...$reset"
configuration=$(sudo nixos-rebuild dry-activate --flake "$flake" --keep-going "$@")
echo "$configuration"
nix run "$flake#nixosConfigurations.$(hostname).pkgs.nvd" -- diff /run/current-system "$configuration"
read -n1 -rp "${bold}Activate new configuration? [y/N]$reset " answer
echo
if [[ $answer =~ ^[Yy]$ ]]; then
sudo "$configuration/bin/switch-to-configuration" switch
else
echo "${bold}Not activating :($reset"
exit 1
fi