Skip to content

About

Pure-Rust fan-control driver for the Mac mini M4 Pro (minifand LaunchDaemon + minifan CLI)

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

MacMiniFanDriver

License: MIT Platform

A pure-Rust fan-control driver for Mac mini and Mac Studio (Apple silicon, AppleSMC). It does not run on GitHub runners, Intel Macs, or anything without an SMC fan. Loads as a macOS startup item (launchd LaunchDaemon), reads the hottest CPU/GPU temperature sensor, and drives the fan with a stepped curve:

Band Threshold Fan target
quiet below 60 °C min RPM
balanced ≥ 60 °C 45 % of range
boost ≥ 75 °C 70 % of range
full ≥ 90 °C 100 % of range
failsafe ≥ 100 °C 100 % of range (forced)

The 100 °C → full-speed rule is a hard invariant inside the control crate — config cannot weaken it.

Safety first. Every failure path (sensor loss, unlock failure, panic, SIGTERM) hands the fan back to Apple's own thermalmonitord. The SMC firmware retains independent thermal protection regardless of our state. Do not run alongside Macs Fan Control, TG Pro, or similar.

Verified on this machine: Mac mini M4 Pro (Mac16,11) · macOS 26.6.2 · 1 fan, range 1000–4900 RPM · mode key F0Md · Ftst absent.

Architecture

Open the control architecture diagram in a browser. Design narrative: docs/DESIGN.md.

launchd (startup item)
  └── minifand (root LaunchDaemon)
        ├── minifan-control  ← pure logic: curve, hysteresis, slew, failsafes
        └── minifan-smc      ← AppleSMC IOKit bindings (zero deps)
              └── AppleSMC.kext → SMC firmware (RTKit) → Fan F0 / sensors

minifan (CLI)  →  same libraries, for status / probe / simulate / set / auto

Quick start

Homebrew (recommended)

brew install rachitdev/tap/minifan
sudo brew services start minifan

That builds minifan (CLI) and minifand (daemon) from source on this Mac and loads a root LaunchDaemon. Apple silicon Mac mini / Studio only.

minifan status
sudo brew services stop minifan
sudo minifan auto                 # hand the fan back to Apple
brew uninstall minifan

Build & dry-run from source (no root, no writes)

cd MacMiniFanDriver
cargo build --release
./target/release/smc-probe          # fans + every temperature sensor
./target/release/minifan status     # hottest CPU/GPU + desired band
./target/release/minifan simulate   # synthetic load → band → RPM
./target/release/minifand --dry-run --once   # one full control cycle, no writes

Install as a startup item without Homebrew (requires admin)

Option A — DMG installer (unsigned PKG-in-DMG):

open dist/MacMiniFanDriver-0.1.0.dmg
# double-click MacMiniFanDriver-0.1.0.pkg
# unsigned build: Gatekeeper may warn → right-click → Open → Open

Rebuild after code changes with ./packaging/build-dmg.sh.

Option B — straight from source:

sudo ./packaging/install.sh

This builds release binaries, installs them to /usr/local/bin, drops the config at /usr/local/etc/minifan/config.toml, and loads com.minifan.daemon into launchd (RunAtLoad + KeepAlive — boots with the machine and restarts if it exits).

minifan status
tail -f /var/log/minifand.log
sudo ./packaging/uninstall.sh       # full removal; fan returned to Apple

Configuration

/usr/local/etc/minifan/config.toml (also see packaging/config.toml):

poll_interval_ms  = 1500
hysteresis_c      = 4.0      # downward only — no flapping at band edges
overtemp_c        = 100.0    # hard failsafe → 100 %
max_rpm_step      = 400      # acoustic slew limit (rpm per poll)
sensors           = "auto"   # or ["TCMz", "Tp2G", "Tg0k"]

[[step]]
name = "balanced"
threshold_c = 60.0
target_pct  = 45.0
# … boost @ 75 → 70 %, full @ 90 → 100 %

SIGHUP reloads the config without dropping control. Unknown keys are a hard error — a typoed config can never silently change thermal behaviour.

CLI reference

Command Privileges Purpose
minifan status none fans, sensors, hottest CPU/GPU, desired band, daemon state
minifan probe none full read-only discovery (same as smc-probe)
minifan simulate none replay a synthetic thermal trace through the curve
minifan config none validate and print the resolved configuration
minifan set <RPM> root acquire manual control and hold a fixed speed
minifan auto root return the fan to Apple auto control

Workspace layout

MacMiniFanDriver/
├── Cargo.toml                  # workspace
├── crates/
│   ├── smc/                    # AppleSMC IOKit bindings, codecs, unlock
│   ├── control/                # curve, hysteresis, slew, failsafes
│   ├── daemon/                 # minifand LaunchDaemon
│   └── cli/                    # minifan CLI
├── packaging/
│   ├── com.minifan.daemon.plist
│   ├── config.toml
│   ├── install.sh
│   ├── uninstall.sh
│   └── build-dmg.sh
└── docs/
    ├── DESIGN.md
    ├── TESTING.md
    └── architecture.html

Zero runtime crate dependencies. The only linkage is the macOS IOKit framework (system-provided).

How the unlock works

Apple Silicon generations differ:

  1. Try a direct write of the mode key (F0Md / F0md) to 1.
  2. If the firmware rejects it with 0x82 (system mode held by thermalmonitord) and the Ftst diagnostic key exists, write Ftst=1 and retry for up to 10 s — the documented M3/M4 path.
  3. On this Mac mini M4 Pro, Ftst is absent and the direct path is the one that matters. The unlock fallback is kept for other hardware.

Sleep/wake clears the unlock. The daemon's watchdog re-checks the mode key every poll and re-acquires transparently.

Safety contract

Failure Response
Sensor read fails 3× Revert fan to Apple control
Fan range unusable Revert
Mode / target write fails Revert; retry takeover every 30 s
Sleep/wake clears unlock Watchdog re-acquires
SIGTERM / SIGINT Revert, exit
Panic in the control loop catch_unwind → fresh-connection revert
Another fan controller installed Installer refuses to proceed

Support

If MacMiniFanDriver keeps your Mac mini cool and quiet, consider a small donation — it goes straight into test hardware and coffee ☕

GitHub Sponsors — one-time or monthly tiers ($5 / $10 / $20 or ₹ equivalents).

License

MIT. Protocol research credits in docs/DESIGN.md. Not affiliated with or endorsed by Apple Inc. Use at your own risk — monitor temperatures carefully, especially the first time you enable live writes.

About

Pure-Rust fan-control driver for the Mac mini M4 Pro (minifand LaunchDaemon + minifan CLI)

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages