Files
nix-config/modules/nixos/desktop/networking/mihomo
ryan4yin | 二花 50a4182898 feat(mihomo): show hostname in metacubexd page title (#383)
metacubexd hardcodes its tab title in the SPA, so dashboards on
different hosts are indistinguishable. Patch the static <title> and
re-apply the hostname from config.js, since Nuxt's useHead resets
document.title on every route change.
2026-10-05 10:05:12 +08:00
..

Mihomo

Native mihomo core + metacubexd dashboard, replacing the Clash Verge GUI. Enable per host with modules.networking.mihomo.enable = true (ai, shoukei).

Usage

cp sources.example.yaml ~/.config/mihomo/sources.yaml && chmod 600 ~/.config/mihomo/sources.yaml
$EDITOR ~/.config/mihomo/sources.yaml           # fill in: secret, private_domains, providers
nu generate.nu                                  # -> ~/.config/mihomo/config.yaml, mode 0600
mihomo -t -f ~/.config/mihomo/config.yaml       # validate before restarting
sudo systemctl restart mihomo.service           # dashboard: http://127.0.0.1:9090/ui

sources.yaml holds everything private (subscription URLs, secret, private domains) and stays out of the repo and the Nix store; the module loads config.yaml via LoadCredential. Generate the config before enabling the module, or the service will not start.

Files

File Role
default.nix the service: services.mihomo + TUN + metacubexd
policy.yaml portable routing policy: ads, CN services, local ranges, tail
generate.nu renders config.yaml from sources.yaml + policy.yaml
sources.example.yaml schema for sources.yaml

Rule order: private_domains, your rules, imported rules, then policy.yaml, ending in MATCH.

Why generate

proxy-provider imports proxies only — a subscription's rules and groups are dropped by the core. The portable policy is therefore written once in policy.yaml as GEOSITE categories. Provider-bound policy is opt-in: rules_from: (a decoded snapshot) or file: carry groups, rules and rule-providers over. The generator drops and reports malformed rules, misplaced MATCH and orphaned targets instead of writing a config the core rejects.

Gotchas

  • ipv6: false: nodes without IPv6 egress + AAAA = routing black hole (WeChat/JD/Taobao images); mihomo's IPv6 fake-ip also hung ssh/git locally for ~2 minutes, so it stays off.
  • private_domains: each entry becomes a DIRECT rule + a fake-ip-filter entry.
  • WeChat/QQ media go over bare CDN IPs, hence multimedia.nt.qq.com.cn in fake-ip-filter. If media still stalls: tun_exclude_process: [wechat, WeChatAppEx, qq] (Linux names; the fix that won clash-verge-rev#1762).
  • find-process-mode: off unless PROCESS-* rules or tun_exclude_process need it.
  • Rule payloads are bare domains: DOMAIN-SUFFIX,https://qlogo.cn is invalid.
  • On a systemd-resolved host, sing-tun normally points resolved at the TUN DNS with resolvectl. The nixpkgs DynamicUser sandbox cannot make those privileged D-Bus changes, so resolved's own upstream queries bypass dns-hijack any:53 and leave via the NIC. Tie a resolver takeover to the service lifetime (resolvectl dns/revert in ExecStartPost/ExecStopPost, see hosts/idols-ai/default.nix), prefixed with + to run outside the unit sandbox. Never set link DNS statically to mihomo: a dead mihomo would take DNS down with it, and resolved does not fall back.

References