nix-multi

VM Management Guide

This guide covers the cross-platform VM management features in nix-multi, supporting both macOS and Linux hosts.

Profile first: VM memory, CPU count, guest user, SSH endpoint, disk layout, GPU settings, and display resolution must come from your own profile. The values below that mention the maintainer’s hardware are examples only.

Quick Start

Build and Run VM

# Interactive VM manager (recommended)
./vm-manager.sh

# Direct commands
./vm-build.sh build      # Build VM for current architecture
./vm-build.sh run        # Build and run VM
./vm-build.sh clean      # Clean build artifacts

# Architecture-specific
./vm-build.sh x86_64 build   # For Intel/AMD systems
./vm-build.sh aarch64 build  # For ARM64/Apple Silicon

Test QEMU Configuration

# Test QEMU availability and configuration
./scripts/qemu-config.sh test x86_64

# Show platform-specific configuration
./scripts/qemu-config.sh config x86_64

# Generate QEMU options
./scripts/qemu-config.sh opts x86_64 8G 4 1920x1080

Platform-Specific Features

macOS Host

Acceleration: Uses Hypervisor Framework (HVF) for native virtualization Audio: CoreAudio integration for better sound quality Display: Cocoa-based display with OpenGL acceleration Networking: User-mode networking (no root required)

Supported VMs:

Example Configuration:

# x86_64 VM on macOS
QEMU_OPTS="-m 6G -smp 4 -accel hvf -device virtio-gpu-pci,xres=1920,yres=1080 -audiodev coreaudio,id=audio0 -device intel-hda -device hda-duplex,audiodev=audio0"

Linux Host

Acceleration: KVM for near-native performance Audio: PipeWire/PulseAudio integration Display: GTK with OpenGL acceleration GPU Passthrough: Optional; configure it for your GPU and IOMMU groups

Supported VMs:

Example Configuration:

# x86_64 VM on Linux with KVM
QEMU_OPTS="-m 8G -smp 4 -enable-kvm -device virtio-gpu-pci,xres=1920,yres=1080 -display gtk,gl=on -audiodev pipewire,id=audio0"

VM Configuration

Default VM Settings

VM Guest Features

Customizing VM Settings

Use the QEMU configuration helper to generate custom options:

# Custom memory, CPU, and resolution
./scripts/qemu-config.sh opts x86_64 16G 8 1920x1080

# Show current platform configuration
./scripts/qemu-config.sh config

Troubleshooting

Common Issues

VM doesn’t start:

  1. Check QEMU installation: ./scripts/qemu-config.sh test
  2. Verify acceleration support (HVF on macOS, KVM on Linux)
  3. Ensure sufficient disk space for VM images

Poor performance:

  1. Verify hardware acceleration is enabled
  2. Increase memory allocation if available
  3. Check if other VMs are running

Audio issues:

  1. Verify audio driver detection
  2. Check host audio system (CoreAudio/PipeWire)
  3. Restart VM with audio debugging

Network connectivity:

  1. SSH: ssh -p "$VM_SSH_PORT" "$VM_SSH_USER@$VM_SSH_HOST"
  2. Check firewall settings on host
  3. Verify QEMU user networking is working

Platform-Specific Troubleshooting

macOS

HVF not available:

# Check HVF support
sysctl kern.hv_support

Permission issues:

Linux

KVM not available:

# Check KVM availability
ls /dev/kvm
lsmod | grep kvm

GPU passthrough issues:

# Test GPU passthrough configuration
./scripts/rtx3080-setup.sh

Advanced Usage

Custom QEMU Options

Override default options by setting QEMU_OPTS:

# Custom QEMU configuration
export QEMU_OPTS="-m 16G -smp 8 -device virtio-gpu-pci,xres=1920,yres=1080"
./result/bin/run-nixos-vm

Multiple VMs

Build different architectures:

# Build both architectures
./vm-build.sh x86_64 build
./vm-build.sh aarch64 build

# Run specific architecture
./vm-build.sh x86_64 run
./vm-build.sh aarch64 run

VM Image Management

# List VM images
ls -la ~/VMs/

# Convert VM formats
qemu-img convert input.qcow2 output.vmdk

# Compress VM images
qemu-img convert -c -O qcow2 input.qcow2 compressed.qcow2

Integration with Host Systems

macOS Integration

Linux Integration

Performance Optimization

Host System

Guest System

Network Performance

Security Considerations