2024-06-10 02:11:04 +02:00
|
|
|
# Handle arguments
|
|
|
|
self="$1"
|
|
|
|
verb="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [ "$verb" != "build" ] && [ "$verb" != "test" ] && [ "$verb" != "boot" ] && [ "$verb" != "switch" ] && [ "$verb" != "confirm" ]
|
|
|
|
then
|
|
|
|
echo "Action should be one of: build, test, boot, switch, confirm"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Build, looking nice
|
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
# sudo so the eval cache is shared with nixos-rebuild
|
|
|
|
sudo nom build "$self#nixosConfigurations.$HOSTNAME.config.system.build.toplevel" -o "$tmpdir/toplevel" "$@"
|
2024-06-26 02:16:50 +02:00
|
|
|
toplevel="$(readlink -f "$tmpdir/toplevel")"
|
2024-06-10 02:11:04 +02:00
|
|
|
rm -rf "$tmpdir"
|
|
|
|
|
|
|
|
# Show diff
|
2024-06-26 02:16:50 +02:00
|
|
|
nvd diff "$(readlink -f /nix/var/nix/profiles/system)" "$toplevel"
|
2024-06-10 02:11:04 +02:00
|
|
|
|
|
|
|
# Figure out specialisation
|
2024-06-17 17:01:05 +02:00
|
|
|
specialisationArgs=()
|
2024-06-26 02:16:50 +02:00
|
|
|
currentSystem="$(readlink -f /run/current-system)"
|
2024-06-10 02:11:04 +02:00
|
|
|
while read -r specialisation
|
|
|
|
do
|
2024-06-26 02:16:50 +02:00
|
|
|
if [ "$(readlink -f "/nix/var/nix/profiles/system/specialisation/$specialisation")" = "$currentSystem" ]
|
2024-06-10 02:11:04 +02:00
|
|
|
then
|
|
|
|
specialisationArgs=("--specialisation" "$specialisation")
|
|
|
|
fi
|
|
|
|
done <<< "$(ls /nix/var/nix/profiles/system/specialisation)"
|
|
|
|
|
|
|
|
# Apply
|
2024-06-23 23:57:03 +02:00
|
|
|
confirm="n"
|
2024-06-10 02:11:04 +02:00
|
|
|
if [ "$verb" = "confirm" ]
|
|
|
|
then
|
|
|
|
echo "Apply configuration? [y/N]"
|
|
|
|
read -r confirm
|
|
|
|
fi
|
|
|
|
if [ "$verb" = "test" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
|
|
|
|
then
|
2024-06-26 02:16:50 +02:00
|
|
|
"$toplevel/bin/update-password-store"
|
2024-06-10 02:11:04 +02:00
|
|
|
sudo nixos-rebuild --flake "$self#$HOSTNAME" test "${specialisationArgs[@]}" "$@"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set as boot
|
|
|
|
if [ "$verb" = "confirm" ]
|
|
|
|
then
|
|
|
|
echo "Set configuration as boot? [y/N]"
|
|
|
|
read -r confirm
|
|
|
|
fi
|
|
|
|
if [ "$verb" = "boot" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
|
|
|
|
then
|
|
|
|
sudo nixos-rebuild --flake "$self#$HOSTNAME" boot "$@"
|
|
|
|
fi
|