darwin: clash-meta daemon with launchd

This commit is contained in:
Guanran Wang 2023-10-09 14:52:33 +08:00
parent 1f84c9ece5
commit 3fd1a9cb5a
Signed by: nyancat
SSH key fingerprint: SHA256:8oWGKciPALWut/6WA27oFKofX+6Wtc0gQnsefXLQx/8
4 changed files with 38 additions and 10 deletions

View file

@ -3,5 +3,6 @@
{ {
imports = [ imports = [
./dns.nix ./dns.nix
./proxy.nix
]; ];
} }

View file

@ -0,0 +1,27 @@
{ pkgs, ... }:
# README!!:
# I HAVE NO IDEA HOW LAUNCHD DAEMON WORKS
# USE AT YOUR OWN RISK
# it just works™
#
# Remember to manually copy `config.yaml` to `/etc/clash-meta`
# I have no idea how to get sops-nix working on darwin...
#
{
#environment.systemPackages = with pkgs; [ clash-meta ];
# do i even need to add it to environment.systemPackages...
launchd.daemons."clash-meta" = {
command = "${pkgs.clash-meta}/bin/clash-meta -d /etc/clash-meta";
};
environment.variables = {
"https_proxy" = "http://127.0.0.1:7890";
"http_proxy" = "http://127.0.0.1:7890";
"socks_proxy" = "socks5://127.0.0.1:7890";
"all_proxy" = "socks5://127.0.0.1:7890";
};
environment.etc."clash-meta/metacubexd".source = ../../users/guanranwang/home-manager/common/dotfiles/config/clash/metacubexd;
}

View file

@ -15,7 +15,7 @@
"alt-tab" "alt-tab"
"altserver" "altserver"
"balenaetcher" "balenaetcher"
"clashx" #"clashx"
"opencore-patcher" "opencore-patcher"
#"element" #"element"

View file

@ -5,9 +5,9 @@
username = "guanranwang"; username = "guanranwang";
homeDirectory = "/Users/guanranwang"; homeDirectory = "/Users/guanranwang";
# Workaround for spotlight indexing
# https://github.com/nix-community/home-manager/issues/1341#issuecomment-1705731962_
activation = { activation = {
# Workaround for spotlight indexing
# https://github.com/nix-community/home-manager/issues/1341#issuecomment-1705731962_
trampolineApps = let trampolineApps = let
apps = pkgs.buildEnv { apps = pkgs.buildEnv {
name = "home-manager-applications"; name = "home-manager-applications";
@ -26,6 +26,13 @@
done done
) )
''; '';
setSystemProxy = let networksetup = /usr/sbin/networksetup;
in lib.hm.dag.entryAfter ["writeBoundary"] ''
${networksetup} -setwebproxystate "Wi-fi" on
${networksetup} -setwebproxy "Wi-fi" 127.0.0.1 7890
${networksetup} -setwebproxystate "Ethernet" on
${networksetup} -setwebproxy "Ethernet" 127.0.0.1 7890
'';
}; };
packages = with pkgs; [ packages = with pkgs; [
@ -63,13 +70,6 @@
nixd nixd
nil nil
]; ];
sessionVariables = {
"https_proxy" = "http://127.0.0.1:7890";
"http_proxy" = "http://127.0.0.1:7890";
"socks_proxy" = "socks5://127.0.0.1:7890";
"all_proxy" = "socks5://127.0.0.1:7890";
};
}; };
# macOS don't have fontconfig # macOS don't have fontconfig