added error handling to ephemeral.nix

This commit is contained in:
William 2025-10-15 20:07:51 -03:00
parent 4b5426885c
commit d655099d76

View file

@ -45,8 +45,13 @@ in
RemainAfterExit = true; RemainAfterExit = true;
}; };
script = '' script = ''
set -euo pipefail
mkdir /btrfs_tmp mkdir /btrfs_tmp
mount ${cfg.rootDevice} /btrfs_tmp if ! mount ${cfg.rootDevice} /btrfs_tmp; then
echo "ERROR: Failed to mount ${cfg.rootDevice}"
exit 1
fi
if [[ -e /btrfs_tmp/${cfg.rootSubvolume} ]]; then if [[ -e /btrfs_tmp/${cfg.rootSubvolume} ]]; then
mkdir -p /btrfs_tmp/old_roots mkdir -p /btrfs_tmp/old_roots
@ -66,7 +71,12 @@ in
delete_subvolume_recursively "$i" delete_subvolume_recursively "$i"
done done
btrfs subvolume create /btrfs_tmp/${cfg.rootSubvolume} if ! btrfs subvolume create /btrfs_tmp/${cfg.rootSubvolume}; then
echo "ERROR: Failed to create subvolume ${cfg.rootSubvolume}"
umount /btrfs_tmp
exit 1
fi
umount /btrfs_tmp umount /btrfs_tmp
''; '';
}; };