update script
This commit is contained in:
1 parent
e6b9ece932
commit
7b20e3e5d7
1 file changed
+33
-19
@@ -1,47 +1,61 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Configuration
|
# Usage:
|
||||||
ALIAS="nixos/custom/vm"
|
# ./build-image.sh <alias> [vmname]
|
||||||
VM_NAME="vmname"
|
#
|
||||||
|
# Examples:
|
||||||
|
# ./build-image.sh nixos/custom/vm
|
||||||
|
# ./build-image.sh nixos/custom/my-vm my-vm
|
||||||
|
|
||||||
|
if [[ $# -lt 1 || $# -gt 2 ]]; then
|
||||||
|
echo "Usage: $0 <alias> [vmname]"
|
||||||
|
echo
|
||||||
|
echo " alias Required Incus image alias"
|
||||||
|
echo " vmname NixOS configuration name (default: vm)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ALIAS="$1"
|
||||||
|
VMNAME="${2:-vm}"
|
||||||
|
|
||||||
# Build the NixOS LXC metadata tarball
|
# Build the NixOS LXC metadata tarball
|
||||||
TARBALL_DIR="$(nix build \
|
TARBALL_DIR="$(nix build \
|
||||||
".#nixosConfigurations.${VM_NAME}.config.system.build.metadata" \
|
".#nixosConfigurations.${VMNAME}.config.system.build.metadata" \
|
||||||
--print-out-paths)"
|
--print-out-paths)"
|
||||||
|
|
||||||
# Find the tarball using find -type f
|
# Find the tarball
|
||||||
TARBALL="$(find "$TARBALL_DIR" -type f -name '*.tar.xz' -print -quit)"
|
TARBALL="$(find "$TARBALL_DIR" -type f -name '*.tar.xz' -print -quit)"
|
||||||
|
|
||||||
if [[ -z "$TARBALL" ]]; then
|
if [[ -z "$TARBALL" ]]; then
|
||||||
echo "Error: Could not find a .tar.xz tarball in:"
|
echo "Could not find a .tar.xz tarball in: $TARBALL_DIR"
|
||||||
echo " $TARBALL_DIR"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Found metadata tarball:"
|
echo "Metadata tarball: $TARBALL"
|
||||||
echo " $TARBALL"
|
|
||||||
|
|
||||||
# Build the QEMU disk image
|
# Build the QEMU disk image
|
||||||
QCOW2="$(nix build \
|
QCOW2_DIR="$(nix build \
|
||||||
".#nixosConfigurations.${VM_NAME}.config.system.build.qemuImage" \
|
".#nixosConfigurations.${VMNAME}.config.system.build.qemuImage" \
|
||||||
--print-out-paths)/nixos.qcow2"
|
--print-out-paths)"
|
||||||
|
|
||||||
|
QCOW2="$QCOW2_DIR/nixos.qcow2"
|
||||||
|
|
||||||
if [[ ! -f "$QCOW2" ]]; then
|
if [[ ! -f "$QCOW2" ]]; then
|
||||||
echo "Error: QEMU image not found:"
|
echo "QEMU image not found: $QCOW2"
|
||||||
echo " $QCOW2"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Importing NixOS image into Incus..."
|
echo "Found QEMU image: $QCOW2"
|
||||||
echo " Alias: $ALIAS"
|
|
||||||
echo " Tarball: $TARBALL"
|
echo
|
||||||
echo " Image: $QCOW2"
|
echo "Importing image into Incus..."
|
||||||
|
|
||||||
incus image import \
|
incus image import \
|
||||||
--alias "$ALIAS" \
|
--alias "$ALIAS" \
|
||||||
"$TARBALL" \
|
"$TARBALL" \
|
||||||
"$QCOW2"
|
"$QCOW2"
|
||||||
|
|
||||||
echo "Successfully imported image as: $ALIAS"
|
echo
|
||||||
|
echo "Successfully imported image: $ALIAS"
|
||||||
|
|
||||||
Reference in new issue
Block a user