Add qvm clean; make rebuild produce VM runner; default qvm run to shell
This commit is contained in:
parent
e766c8466d
commit
601b4ab15e
7 changed files with 395 additions and 249 deletions
|
|
@ -59,43 +59,45 @@ ensure_user_flake() {
|
|||
}
|
||||
|
||||
#
|
||||
# build_base_image - Build the base image using nix
|
||||
# build_vm - Build the VM runner using nix
|
||||
#
|
||||
build_base_image() {
|
||||
log_info "Building base image from flake..."
|
||||
log_info "Building VM from flake..."
|
||||
|
||||
# Build the qcow2 output from user's flake
|
||||
local build_result="$QVM_STATE_DIR/result"
|
||||
# Build the VM output from user's flake
|
||||
local build_result="$QVM_STATE_DIR/vm-result"
|
||||
|
||||
if ! nix build "$QVM_USER_FLAKE#qcow2" --out-link "$build_result"; then
|
||||
die "Failed to build base image. Check your flake configuration at: $QVM_USER_FLAKE/flake.nix"
|
||||
if ! nix build "$QVM_USER_FLAKE#vm" --out-link "$build_result"; then
|
||||
die "Failed to build VM. Check your flake configuration at: $QVM_USER_FLAKE/flake.nix"
|
||||
fi
|
||||
|
||||
# Verify the result contains nixos.qcow2
|
||||
local qcow2_path="$build_result/nixos.qcow2"
|
||||
if [[ ! -f "$qcow2_path" ]]; then
|
||||
die "Build succeeded but nixos.qcow2 not found at: $qcow2_path"
|
||||
# Verify the result contains the VM runner script
|
||||
local vm_runner="$build_result/bin/run-qvm-dev-vm"
|
||||
if [[ ! -f "$vm_runner" ]]; then
|
||||
# Try alternate name pattern
|
||||
vm_runner=$(find "$build_result/bin" -name "run-*-vm" -type f 2>/dev/null | head -1)
|
||||
if [[ -z "$vm_runner" || ! -f "$vm_runner" ]]; then
|
||||
die "Build succeeded but VM runner script not found in: $build_result/bin/"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Copy the qcow2 to base image location
|
||||
log_info "Copying image to: $QVM_BASE_IMAGE"
|
||||
# Remove existing image first (may be read-only from Nix store copy)
|
||||
rm -f "$QVM_BASE_IMAGE"
|
||||
cp -L "$qcow2_path" "$QVM_BASE_IMAGE"
|
||||
# Ensure the new image is writable for future rebuilds
|
||||
chmod 644 "$QVM_BASE_IMAGE"
|
||||
# Move the result symlink to data dir (keeps nix store reference)
|
||||
rm -f "$QVM_DATA_DIR/vm-result"
|
||||
mv "$build_result" "$QVM_DATA_DIR/vm-result"
|
||||
|
||||
# Remove the result symlink
|
||||
rm -f "$build_result"
|
||||
# Get the basename of the runner script and construct path in new location
|
||||
local runner_name
|
||||
runner_name=$(basename "$vm_runner")
|
||||
vm_runner="$QVM_DATA_DIR/vm-result/bin/$runner_name"
|
||||
|
||||
# Get image size for informational output
|
||||
local image_size
|
||||
image_size=$(du -h "$QVM_BASE_IMAGE" | cut -f1)
|
||||
# Create a symlink to the VM runner at our standard location
|
||||
log_info "Installing VM runner to: $QVM_VM_RUNNER"
|
||||
rm -f "$QVM_VM_RUNNER"
|
||||
ln -sf "$vm_runner" "$QVM_VM_RUNNER"
|
||||
|
||||
log_info "Base image built successfully"
|
||||
log_info "VM built successfully"
|
||||
echo ""
|
||||
echo "Base image: $QVM_BASE_IMAGE"
|
||||
echo "Image size: $image_size"
|
||||
echo "VM runner: $QVM_VM_RUNNER"
|
||||
}
|
||||
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue