fix(deploy flash): validate device before building the image

This commit is contained in:
erik
2026-07-13 20:44:38 +02:00
parent bcd2e6ebf2
commit b989490333
+5 -2
View File
@@ -97,6 +97,11 @@ case "$cmd" in
image|flash)
config="${2:-}"; [ -n "$config" ] || die "usage: ./deploy $cmd <config> [<dev>]"
# Validate the device BEFORE building, so a bad `flash` fails fast.
if [ "$cmd" = flash ]; then
dev="${3:-}"; [ -n "$dev" ] || die "usage: ./deploy flash <config> <dev> (e.g. /dev/sdX)"
[ -b "$dev" ] || die "$dev is not a block device"
fi
echo ">> building SD image for .#$config (aarch64 needs qemu binfmt)"
nix build ".#nixosConfigurations.$config.config.system.build.sdImage" -o result-sd
@@ -104,8 +109,6 @@ case "$cmd" in
echo ">> image: $img"
[ "$cmd" = image ] && exit 0
dev="${3:-}"; [ -n "$dev" ] || die "usage: ./deploy flash <config> <dev> (e.g. /dev/sdX)"
[ -b "$dev" ] || die "$dev is not a block device"
echo ">> TARGET DEVICE — everything on it will be ERASED:"
lsblk -o NAME,SIZE,MODEL,TRAN,MOUNTPOINTS "$dev"
read -rp ">> type 'yes' to write $config to $dev: " ok