Skip to content

Instantly share code, notes, and snippets.

@olragon
Created February 25, 2026 11:02
Show Gist options
  • Select an option

  • Save olragon/5deb05bba361dacc78fe07fa72fb046e to your computer and use it in GitHub Desktop.

Select an option

Save olragon/5deb05bba361dacc78fe07fa72fb046e to your computer and use it in GitHub Desktop.
Installing Colima (Docker) via MacPorts on macOS 10.13 High Sierra — 7 patches for QEMU 10.2.1 + Lima 2.0.3

Installing Colima via MacPorts on macOS 10.13 (High Sierra)

Machine: MacBookPro6,2 (mid-2010 15"), macOS 10.13.6 High Sierra, darwin 17.7.0 MacPorts: with clang-mp-17, python3.14, Go 1.24.8 Result: Colima 0.10.1 + Lima 2.0.3 + QEMU 10.2.1 — fully working Docker on macOS 10.13

The Problem

sudo port install colima fails because QEMU 10.2.1 and Lima 2.0.3 use macOS APIs that don't exist on 10.13. Seven custom patches are needed across QEMU and Lima Portfiles, plus a python3 symlink fix.

Prerequisites

# Ensure python3 symlink exists (QEMU configure needs it)
sudo port select --set python3 python314
sudo port select --set python python314

QEMU Patches (6 patches + 1 reinplace)

All patches go in: /opt/local/var/macports/sources/rsync.macports.org/macports/release/tarballs/ports/emulators/qemu/files/

Patch 1: patch-qemu-jit-write-protect.diff

Problem: pthread_jit_write_protect_np only exists on macOS 11+ (Apple Silicon JIT). File: include/qemu/osdep.h:845

--- include/qemu/osdep.h.orig
+++ include/qemu/osdep.h
@@ -839,7 +839,7 @@
  * Toggle write/execute on the pages marked MAP_JIT
  * for the current thread.
  */
-#ifdef __APPLE__
+#if defined(__APPLE__) && defined(__MAC_11_0) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_11_0
 static inline void qemu_thread_jit_execute(void)
 {
     pthread_jit_write_protect_np(true);

Patch 2: patch-qemu-uftrace-timespec.diff

Problem: timespec_get/TIME_UTC are C11 features not available on macOS 10.13 SDK. File: contrib/plugins/uftrace.c:130

--- contrib/plugins/uftrace.c.orig
+++ contrib/plugins/uftrace.c
@@ -127,8 +127,8 @@
 #else
     /* We need nanosecond precision for short lived functions. */
     struct timespec ts;
-    timespec_get(&ts, TIME_UTC);
-    uint64_t now_ns = ts.tv_sec * NANOSECONDS_PER_SECOND + ts.tv_nsec;
+    clock_gettime(CLOCK_REALTIME, &ts);
+    uint64_t now_ns = (uint64_t)ts.tv_sec * NANOSECONDS_PER_SECOND + ts.tv_nsec;
 #endif
     return now_ns;
 }

Patch 3: patch-qemu-iomainport.diff

Problem: IOMainPort introduced in macOS 12, replacing deprecated IOMasterPort. File: block/file-posix.c:4054

--- block/file-posix.c.orig
+++ block/file-posix.c
@@ -4051,9 +4051,9 @@
     char *mediaType = NULL;

-    kernResult = IOMainPort(MACH_PORT_NULL, &mainPort);
+    kernResult = IOMasterPort(MACH_PORT_NULL, &mainPort);
     if ( KERN_SUCCESS != kernResult ) {
-        printf("IOMainPort returned %d\n", kernResult);
+        printf("IOMasterPort returned %d\n", kernResult);
     }

Patch 4 (reinplace): kAudioObjectPropertyElementMain

Problem: Renamed from kAudioObjectPropertyElementMaster in macOS 12. File: audio/coreaudio.m (6 occurrences)

Add to QEMU Portfile post-patch block:

post-patch {
    reinplace "s|kAudioObjectPropertyElementMain|kAudioObjectPropertyElementMaster|g" \
        ${worksrcpath}/audio/coreaudio.m
}

Patch 5: patch-qemu-hvf-vcpu-run.diff

Problem: hv_vcpu_run_until/HV_DEADLINE_FOREVER added in macOS 11+ Hypervisor.framework. On 10.13, hv_vcpu_run (blocking, no timeout) is the equivalent. File: target/i386/hvf/hvf.c:995

--- target/i386/hvf/hvf.c.orig
+++ target/i386/hvf/hvf.c
@@ -992,7 +992,7 @@

         cpu_exec_start(cpu);

-        hv_return_t r = hv_vcpu_run_until(cpu->accel->fd, HV_DEADLINE_FOREVER);
+        hv_return_t r = hv_vcpu_run(cpu->accel->fd);
         assert_hvf_ok(r);

         cpu_exec_end(cpu);

Patch 6: patch-qemu-hvf-denied.diff

Problem: HV_DENIED constant added in macOS 11.0. File: include/sysemu/hvf_int.h (or equivalent header)

--- include/sysemu/hvf_int.h.orig
+++ include/sysemu/hvf_int.h
@@ -12,6 +12,11 @@

 #include <Hypervisor/Hypervisor.h>

+/* HV_DENIED was added in macOS 11.0 */
+#ifndef HV_DENIED
+#define HV_DENIED ((hv_return_t) 0xfae94007)
+#endif
+
 /* hvf_slot flags */
 #define HVF_SLOT_LOG (1 << 0)

QEMU Portfile changes

Add to the patchfiles line:

patchfiles-append   patch-qemu-jit-write-protect.diff \
                    patch-qemu-uftrace-timespec.diff \
                    patch-qemu-iomainport.diff \
                    patch-qemu-hvf-vcpu-run.diff \
                    patch-qemu-hvf-denied.diff

Lima Patch (1 patch)

Patch goes in: /opt/local/var/macports/sources/rsync.macports.org/macports/release/tarballs/ports/sysutils/lima/files/

Patch 7: patch-lima-guestagent-cgo.diff

Problem: Lima cross-compiles lima-guestagent.Linux-x86_64 (ELF binary for use inside VMs). Despite CGO_ENABLED=0, MacPorts' compiler wrapper CC causes Go to use external linking, which invokes macOS clang — it can't link Linux ELF objects. File: Makefile:401

--- Makefile.orig
+++ Makefile
@@ -398,7 +398,7 @@
 ENVS_$(LINUX_GUESTAGENT_PATH_COMMON)x86_64 = CGO_ENABLED=0 GOOS=linux GOARCH=amd64
 $(ALL_GUESTAGENTS_NOT_COMPRESSED): $(call dependencies_for_cmd,lima-guestagent) $$(call force_build_with_gunzip,$$@) | _output/share/lima
-	$(ENVS_$@) $(GO_BUILD) -o $@ ./cmd/lima-guestagent
+	$(ENVS_$@) CC= $(GO) build $(GO_BUILD_GCFLAGS) -ldflags="-s=$(GO_BUILD_LDFLAGS_S) -w=$(GO_BUILD_LDFLAGS_W) -X $(PACKAGE)/pkg/version.Version=$(VERSION) -linkmode=internal" $(GO_BUILD_FLAG_TAGS) -o $@ ./cmd/lima-guestagent
 	chmod 644 $@

Lima Portfile changes

Add to the patchfiles line:

patchfiles-append   patch-lima-guestagent-cgo.diff

Install

After applying all patches:

sudo port install colima

QEMU compiles 3584 source files from scratch (~20 min on 2010 MacBook Pro). Lima and Colima are Go-based and build faster.

Verify

colima start --runtime docker --cpu 2 --memory 2
docker run --rm hello-world

Versions tested

Component Version
macOS 10.13.6 High Sierra (darwin 17.7.0)
MacPorts with clang-mp-17
QEMU 10.2.1
Lima 2.0.3
Colima 0.10.1
Docker 29.2.1
Go 1.24.8

Summary

# Patch Problem macOS version needed
1 patch-qemu-jit-write-protect.diff pthread_jit_write_protect_np macOS 11+
2 patch-qemu-uftrace-timespec.diff timespec_get/TIME_UTC macOS 10.15+ (C11)
3 patch-qemu-iomainport.diff IOMainPort macOS 12+
4 Portfile reinplace kAudioObjectPropertyElementMain macOS 12+
5 patch-qemu-hvf-vcpu-run.diff hv_vcpu_run_until macOS 11+
6 patch-qemu-hvf-denied.diff HV_DENIED macOS 11+
7 patch-lima-guestagent-cgo.diff Go cross-compile linker MacPorts-specific

By @olragon with Claude Code (Anthropic) — February 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment