flake/nixos/profiles/common/opt-in/mihomo/default.nix

64 lines
2.2 KiB
Nix
Raw Normal View History

{
lib,
pkgs,
config,
...
}: {
2024-03-22 07:09:07 +00:00
services.mihomo = {
enable = true;
configFile = config.sops.templates."clash.yaml".path;
webui = pkgs.metacubexd;
};
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"
];
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
### sops-nix
2024-03-22 07:09:07 +00:00
sops.secrets = builtins.mapAttrs (_name: value: value // {restartUnits = ["mihomo.service"];}) {
2023-12-31 12:23:24 +00:00
"clash/secret" = {};
"clash/proxies/lightsail" = {};
2024-02-12 06:03:03 +00:00
"clash/proxy-providers/efcloud" = {};
"clash/proxy-providers/flyairport" = {};
"clash/proxy-providers/spcloud" = {};
};
# why not substituteAll? see https://github.com/NixOS/nixpkgs/issues/237216
sops.templates."clash.yaml".file = let
convert = url: "https://sub.maoxiongnet.com/sub?target=clash&list=true&url=${url}";
substituteV2 = {src, ...} @ args: let
args' = builtins.removeAttrs args ["src"];
in
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)
"clash/secret"
"clash/proxies/lightsail"
"clash/proxy-providers/efcloud"
"clash/proxy-providers/flyairport"
"clash/proxy-providers/spcloud"
;
# Free servers that I dont really care about
pawdroid = convert "https://cdn.jsdelivr.net/gh/Pawdroid/Free-servers@main/sub";
ermaozi = convert "https://cdn.jsdelivr.net/gh/ermaozi/get_subscribe@main/subscribe/v2ray.txt";
jsnzkpg = convert "https://cdn.jsdelivr.net/gh/Jsnzkpg/Jsnzkpg@Jsnzkpg/Jsnzkpg";
};
}