mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-11-21 23:11:28 +01:00
refactor(mihomo): link geodata from nixpkgs instead of seeding it by hand
`just mihomo-geo` copied geodata into the state dir so a cold start never fetched it. tmpfiles now links v2ray-rules-dat and the DB-IP lite mmdbs there, so geo-auto-update moves to the gateway config only. Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
1 parent
c8bbeb708d
commit
be592ae75c
7 files changed
+24
-42
No files matched your search
@@ -13,10 +13,11 @@ sudo systemctl restart mihomo.service # dashboard: http://127.0.0.1:90
|
||||
```
|
||||
|
||||
`~/.config/mihomo` holds `sources.yaml` and the generated `config.yaml`, which the service loads
|
||||
through systemd `LoadCredential`; the core's own state — geodata and cache — is in
|
||||
`/var/lib/private/mihomo` (`StateDirectory`, `DynamicUser`). The generator, `policy.yaml` and
|
||||
`gateway-config.nu` are run from here and never copied over. `just mihomo-gen` renders the config
|
||||
and validates it with the core the service runs.
|
||||
through systemd `LoadCredential`; the core's own state is in `/var/lib/private/mihomo`
|
||||
(`StateDirectory`, `DynamicUser`), where the module links geodata from nixpkgs (`v2ray-rules-dat`,
|
||||
`dbip-country-lite`, `dbip-asn-lite`), so it updates with nixpkgs, not at runtime. The generator,
|
||||
`policy.yaml` and `gateway-config.nu` are run from here and never copied over. `just mihomo-gen`
|
||||
renders the config and validates it with the core the service runs.
|
||||
|
||||
`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
|
||||
|
||||
@@ -69,6 +69,14 @@ in
|
||||
# and fail with "Failed to set up credentials: No such file or directory".
|
||||
systemd.services.mihomo.unitConfig.RequiresMountsFor = builtins.dirOf configFile;
|
||||
|
||||
# Geodata from nixpkgs: a cold start must not fetch it (its DNS is not up yet).
|
||||
systemd.tmpfiles.settings.mihomo-geodata = {
|
||||
"/var/lib/private/mihomo/GeoSite.dat"."L+".argument =
|
||||
"${pkgs.v2ray-rules-dat}/share/v2ray/geosite.dat";
|
||||
"/var/lib/private/mihomo/geoip.metadb"."L+".argument = pkgs.dbip-country-lite.mmdb;
|
||||
"/var/lib/private/mihomo/ASN.mmdb"."L+".argument = pkgs.dbip-asn-lite.mmdb;
|
||||
};
|
||||
|
||||
services.resolved.enable = lib.mkIf cfg.resolvedIntegration true;
|
||||
networking.networkmanager =
|
||||
lib.mkIf (cfg.resolvedIntegration && config.networking.networkmanager.enable)
|
||||
|
||||
@@ -36,6 +36,9 @@ def main [
|
||||
| insert external-ui "ui"
|
||||
| insert external-ui-url $UI_URL
|
||||
| update secret "GATEWAY-SECRET-PLACEHOLDER"
|
||||
# desktops take geodata from nixpkgs; the gateway updates its own
|
||||
| insert geo-auto-update true
|
||||
| insert geo-update-interval 24
|
||||
# The gateway uses nftables TProxy for LAN traffic; its desktop-style TUN
|
||||
# auto-route would capture the gateway's own DIRECT IPv6 dials again.
|
||||
| upsert tun.enable false
|
||||
|
||||
@@ -549,8 +549,6 @@ def main [
|
||||
"fake-ip-filter": (($priv_filters | append $policy_filters) | uniq)
|
||||
}
|
||||
"geodata-mode": false
|
||||
"geo-auto-update": true
|
||||
"geo-update-interval": 24
|
||||
"geox-url": {
|
||||
geoip: "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip.dat"
|
||||
geosite: "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geosite.dat"
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
# rules, the rules from `sources.yaml` and the rules imported from your
|
||||
# subscriptions, so this file is the tail that closes every config.
|
||||
#
|
||||
# GEOSITE categories come from meta-rules-dat, which the module keeps current
|
||||
# (`geo-auto-update`). `mihomo -t` validates the names: `taobao`, `alipay` and
|
||||
# `wechat` do not exist in it, hence the hand-written domains below.
|
||||
# GEOSITE categories come from meta-rules-dat on the gateway and nixpkgs'
|
||||
# v2ray-rules-dat on the desktops. `mihomo -t` validates the names: `taobao`,
|
||||
# `alipay` and `wechat` do not exist in it, hence the hand-written domains below.
|
||||
|
||||
# Region node groups. Each entry becomes two groups offered inside PROXY:
|
||||
# "<name> 自动" (url-test, lazy: only health-checked once selected) and
|
||||
|
||||
Reference in new issue
Block a user