WIP
This commit is contained in:
1 parent
13e407847f
commit
374428658a
80 files changed
+2517
-1058
No files matched your search
@@ -0,0 +1,73 @@
|
||||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
rootCfg = config.selfhosted.mihomo;
|
||||
subUrl = config.sops.placeholder."mihomo/subscription_url";
|
||||
secret = config.sops.placeholder."mihomo/secret";
|
||||
in
|
||||
{
|
||||
config = mkIf rootCfg.enable {
|
||||
sops.templates."mihomo.yaml".content = ''
|
||||
mixed-port: 7890
|
||||
allow-lan: true
|
||||
bind-address: "*"
|
||||
mode: rule
|
||||
log-level: info
|
||||
ipv6: false
|
||||
external-controller: 0.0.0.0:9090
|
||||
secret: "${secret}"
|
||||
|
||||
dns:
|
||||
enable: true
|
||||
listen: 0.0.0.0:1053
|
||||
nameserver:
|
||||
- 8.8.8.8
|
||||
- 1.1.1.1
|
||||
|
||||
proxy-providers:
|
||||
sub:
|
||||
type: http
|
||||
url: "${subUrl}"
|
||||
interval: 3600
|
||||
path: ./providers/sub.yaml
|
||||
header:
|
||||
User-Agent:
|
||||
- "ClashMeta/1.19.30"
|
||||
x-hwid:
|
||||
- "homelab-mihomo"
|
||||
x-device-os:
|
||||
- "Linux"
|
||||
x-ver-os:
|
||||
- "NixOS"
|
||||
x-device-model:
|
||||
- "homelab"
|
||||
health-check:
|
||||
enable: true
|
||||
url: https://www.gstatic.com/generate_204
|
||||
interval: 300
|
||||
|
||||
proxy-groups:
|
||||
- name: PROXY
|
||||
type: select
|
||||
use:
|
||||
- sub
|
||||
proxies:
|
||||
- DIRECT
|
||||
|
||||
- name: AUTO
|
||||
type: url-test
|
||||
use:
|
||||
- sub
|
||||
url: https://www.gstatic.com/generate_204
|
||||
interval: 300
|
||||
|
||||
rules:
|
||||
- DOMAIN-SUFFIX,nixos.org,PROXY
|
||||
- DOMAIN-SUFFIX,cache.nixos.org,PROXY
|
||||
- DOMAIN-SUFFIX,channels.nixos.org,PROXY
|
||||
- DOMAIN-SUFFIX,github.com,PROXY
|
||||
- DOMAIN-SUFFIX,githubusercontent.com,PROXY
|
||||
- MATCH,DIRECT
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
common = config.selfhosted.common;
|
||||
rootCfg = config.selfhosted.mihomo;
|
||||
cfg = rootCfg.core;
|
||||
hostDataPath = "${common.dataDir}/mihomo";
|
||||
in
|
||||
{
|
||||
imports = [ ./config.nix ];
|
||||
|
||||
options.selfhosted.mihomo.core = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
hostMixedPort = mkOption {
|
||||
type = types.port;
|
||||
};
|
||||
hostApiPort = mkOption {
|
||||
type = types.port;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf rootCfg.enable {
|
||||
virtualisation.oci-containers.containers.${cfg.name} = {
|
||||
image = "docker.io/metacubex/mihomo:v1.19.30";
|
||||
ports = [
|
||||
"127.0.0.1:${toString cfg.hostMixedPort}:7890"
|
||||
"0.0.0.0:${toString cfg.hostApiPort}:9090"
|
||||
];
|
||||
volumes = [
|
||||
"${hostDataPath}:/root/.config/mihomo"
|
||||
];
|
||||
log-driver = "journald";
|
||||
extraOptions = [
|
||||
"--network=${common.network.name}"
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services."${common.backend}-${cfg.name}" = {
|
||||
serviceConfig = {
|
||||
Restart = lib.mkOverride 90 "always";
|
||||
};
|
||||
wantedBy = [ "${common.backend}-${rootCfg.targetName}.target" ];
|
||||
partOf = [ "${common.backend}-${rootCfg.targetName}.target" ];
|
||||
preStart = ''
|
||||
mkdir -p ${hostDataPath}/providers
|
||||
cp -f ${config.sops.templates."mihomo.yaml".path} ${hostDataPath}/config.yaml
|
||||
chmod 644 ${hostDataPath}/config.yaml
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user