add build script

This commit is contained in:
RoyDumblauskas committed 2026-09-27 02:06:13 -05:00
1 parent 3e32b8cdf7
commit e6b9ece932
1 file changed
+47
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail
# Configuration
ALIAS="nixos/custom/vm"
VM_NAME="vmname"
# Build the NixOS LXC metadata tarball
TARBALL_DIR="$(nix build \
".#nixosConfigurations.${VM_NAME}.config.system.build.metadata" \
--print-out-paths)"
# Find the tarball using find -type f
TARBALL="$(find "$TARBALL_DIR" -type f -name '*.tar.xz' -print -quit)"
if [[ -z "$TARBALL" ]]; then
echo "Error: Could not find a .tar.xz tarball in:"
echo " $TARBALL_DIR"
exit 1
fi
echo "Found metadata tarball:"
echo " $TARBALL"
# Build the QEMU disk image
QCOW2="$(nix build \
".#nixosConfigurations.${VM_NAME}.config.system.build.qemuImage" \
--print-out-paths)/nixos.qcow2"
if [[ ! -f "$QCOW2" ]]; then
echo "Error: QEMU image not found:"
echo " $QCOW2"
exit 1
fi
echo "Importing NixOS image into Incus..."
echo " Alias: $ALIAS"
echo " Tarball: $TARBALL"
echo " Image: $QCOW2"
incus image import \
--alias "$ALIAS" \
"$TARBALL" \
"$QCOW2"
echo "Successfully imported image as: $ALIAS"