From 1f84c9ece5001805b5034b21d25db8ab5a620f3e Mon Sep 17 00:00:00 2001 From: Guanran Wang Date: Sun, 8 Oct 2023 17:17:43 +0800 Subject: [PATCH 1/2] flake: fix imac-2017 machine path --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index b2d7d15..7ddaca1 100755 --- a/flake.nix +++ b/flake.nix @@ -48,7 +48,7 @@ specialArgs = { inherit inputs; }; modules = [ ./darwin # Entrypoint - ./machines/darwin/imac-2017.nix # Hardware-specific configurations + ./machines/darwin/imac-2017 # Hardware-specific configurations # Machine-specific configurations (does such stuff even exist on nix-darwin) ./users/guanranwang/darwin.nix # User-specific configurations ./flakes/darwin/home-manager.nix # Flakes From 3fd1a9cb5ae06428ee72c30fed224a7e89ea3ad1 Mon Sep 17 00:00:00 2001 From: Guanran Wang Date: Mon, 9 Oct 2023 14:52:33 +0800 Subject: [PATCH 2/2] darwin: clash-meta daemon with launchd --- darwin/networking/default.nix | 1 + darwin/networking/proxy.nix | 27 +++++++++++++++++++ darwin/packages/homebrew.nix | 2 +- .../guanranwang/home-manager/darwin/home.nix | 18 ++++++------- 4 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 darwin/networking/proxy.nix diff --git a/darwin/networking/default.nix b/darwin/networking/default.nix index 0bbacfc..c856686 100644 --- a/darwin/networking/default.nix +++ b/darwin/networking/default.nix @@ -3,5 +3,6 @@ { imports = [ ./dns.nix + ./proxy.nix ]; } \ No newline at end of file diff --git a/darwin/networking/proxy.nix b/darwin/networking/proxy.nix new file mode 100644 index 0000000..880958d --- /dev/null +++ b/darwin/networking/proxy.nix @@ -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; +} \ No newline at end of file diff --git a/darwin/packages/homebrew.nix b/darwin/packages/homebrew.nix index 3d062cf..f841549 100644 --- a/darwin/packages/homebrew.nix +++ b/darwin/packages/homebrew.nix @@ -15,7 +15,7 @@ "alt-tab" "altserver" "balenaetcher" - "clashx" + #"clashx" "opencore-patcher" #"element" diff --git a/users/guanranwang/home-manager/darwin/home.nix b/users/guanranwang/home-manager/darwin/home.nix index 79659f2..7b55718 100644 --- a/users/guanranwang/home-manager/darwin/home.nix +++ b/users/guanranwang/home-manager/darwin/home.nix @@ -5,9 +5,9 @@ username = "guanranwang"; homeDirectory = "/Users/guanranwang"; - # Workaround for spotlight indexing - # https://github.com/nix-community/home-manager/issues/1341#issuecomment-1705731962_ activation = { + # Workaround for spotlight indexing + # https://github.com/nix-community/home-manager/issues/1341#issuecomment-1705731962_ trampolineApps = let apps = pkgs.buildEnv { name = "home-manager-applications"; @@ -26,6 +26,13 @@ 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; [ @@ -63,13 +70,6 @@ nixd 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