2023-12-25 07:23:54 +00:00
|
|
|
{
|
2024-06-16 02:59:27 +00:00
|
|
|
lib,
|
2023-12-25 07:23:54 +00:00
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: {
|
2024-03-22 07:09:07 +00:00
|
|
|
services.mihomo = {
|
2023-12-25 07:23:54 +00:00
|
|
|
enable = true;
|
|
|
|
configFile = config.sops.templates."clash.yaml".path;
|
2024-06-11 21:33:24 +00:00
|
|
|
webui = pkgs.metacubexd;
|
2023-12-25 07:23:54 +00:00
|
|
|
};
|
|
|
|
|
2024-03-22 07:09:07 +00:00
|
|
|
systemd.services.mihomo.serviceConfig.ExecStartPre = [
|
|
|
|
"${pkgs.coreutils}/bin/ln -sf ${pkgs.v2ray-geoip}/share/v2ray/geoip.dat /var/lib/private/mihomo/GeoIP.dat"
|
|
|
|
"${pkgs.coreutils}/bin/ln -sf ${pkgs.v2ray-domain-list-community}/share/v2ray/geosite.dat /var/lib/private/mihomo/GeoSite.dat"
|
2024-01-26 19:46:06 +00:00
|
|
|
];
|
|
|
|
|
2023-12-31 12:23:24 +00:00
|
|
|
### System proxy settings
|
|
|
|
networking.proxy.default = "http://127.0.0.1:7890/";
|
2024-03-22 07:09:07 +00:00
|
|
|
environment.shellAliases = let
|
|
|
|
inherit (config.networking) proxy;
|
|
|
|
in {
|
|
|
|
"setproxy" = "export http_proxy=${proxy.httpProxy} https_proxy=${proxy.httpsProxy} all_proxy=${proxy.allProxy} ftp_proxy=${proxy.ftpProxy} rsync_proxy=${proxy.rsyncProxy}";
|
|
|
|
"unsetproxy" = "set -e http_proxy https_proxy all_proxy ftp_proxy rsync_proxy";
|
|
|
|
};
|
2023-12-31 12:23:24 +00:00
|
|
|
|
2023-12-25 07:23:54 +00:00
|
|
|
### sops-nix
|
2024-07-21 10:09:21 +00:00
|
|
|
sops.secrets = lib.mapAttrs (_name: value:
|
2024-07-09 23:12:02 +00:00
|
|
|
value
|
|
|
|
// {
|
|
|
|
restartUnits = ["mihomo.service"];
|
|
|
|
sopsFile = ./secrets.yaml;
|
|
|
|
}) {
|
2023-12-31 12:23:24 +00:00
|
|
|
"clash/secret" = {};
|
2024-04-22 20:40:41 +00:00
|
|
|
"clash/proxies/lightsail" = {};
|
2024-02-12 06:03:03 +00:00
|
|
|
"clash/proxy-providers/efcloud" = {};
|
2024-06-16 02:59:27 +00:00
|
|
|
"clash/proxy-providers/flyairport" = {};
|
2023-12-25 07:23:54 +00:00
|
|
|
"clash/proxy-providers/spcloud" = {};
|
|
|
|
};
|
|
|
|
|
2024-06-16 02:59:27 +00:00
|
|
|
# why not substituteAll? see https://github.com/NixOS/nixpkgs/issues/237216
|
2024-06-16 03:30:38 +00:00
|
|
|
sops.templates."clash.yaml".file = let
|
|
|
|
substituteV2 = {src, ...} @ args: let
|
2024-07-21 10:09:21 +00:00
|
|
|
args' = lib.removeAttrs args ["src"];
|
2024-06-16 02:59:27 +00:00
|
|
|
in
|
2024-06-16 03:30:38 +00:00
|
|
|
pkgs.substitute {
|
|
|
|
inherit src;
|
|
|
|
substitutions = lib.flatten (lib.mapAttrsToList (n: v: ["--subst-var-by" n v]) args');
|
|
|
|
};
|
|
|
|
in
|
|
|
|
substituteV2 {
|
|
|
|
src = ./config.yaml;
|
|
|
|
inherit
|
|
|
|
(config.sops.placeholder)
|
2024-06-16 02:59:27 +00:00
|
|
|
"clash/secret"
|
|
|
|
"clash/proxies/lightsail"
|
|
|
|
"clash/proxy-providers/efcloud"
|
|
|
|
"clash/proxy-providers/flyairport"
|
|
|
|
"clash/proxy-providers/spcloud"
|
2024-06-16 03:30:38 +00:00
|
|
|
;
|
|
|
|
};
|
2023-12-25 07:23:54 +00:00
|
|
|
}
|