Putting Apple's Virtualization framework under a Flutter app
I maintain WSL Manager , a Flutter desktop app from 2021 that saves you from typing wsl.exe flags. Version 2 runs the same app on Apple silicon, where it manages native Linux and macOS VMs through Apple's Virtualization framework. This post is about what that took. Almost none of it was in the Flutter part. Install on macOS with brew install --cask wsl-manager . The macOS side is still beta. The…
The WSL Manager is a Flutter desktop application released in 2021, aiming to simplify the process of managing WSL (Windows Subsystem for Linux) environments. Version 2 of the app extends its capabilities to run on Apple silicon devices, offering management of both native Linux and macOS virtual machines through Apple's Virtualization framework. This article delves into the technical aspects of implementing this feature.
The macOS version of WSL Manager relies heavily on a Swift helper called vmctl, which runs independently from the Flutter application. vmctl is a command-line interface (CLI) that communicates with the Flutter app through JSON output. The app maintains separate directories for each VM, containing configuration files, disk images, EFI variables, cloud-init seed images, and log files. A common backend interface and capabilities record allow the Flutter codebase to support both WSL and Apple VMs.
To keep the virtual machine running after a command finishes, vmctl starts a detached copy of itself (named vmctl__run) and waits for a five-second timeout, allowing for error handling if the configuration is broken. The VM remains headless, with its process ending once the command returns. A headless NSApplication handles termination signals, such as SIGTERM for a graceful shutdown and SIGUSR1 for opening the VM's graphical interface.
Each VM is equipped with a virtio graphics device from the start, even if the VM is headless. The cloud-init process writes to the root password hash, preventing it from locking the account. The cloud-init document is merged with the user-data during the setup process. The host network interface is integrated into the VM, with the IP address determined by parsing macOS's DHCP lease information.
To connect to the VM's console, vmctl uses a Unix socket and executes the SSH command as a child process, ensuring a responsive serial console experience. The serial log aids in troubleshooting boot failures, and the app handles various edge cases, such as qemu-img dependencies, ext4 file system limitations, and UI integration for managing distros and VMs.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.