darwin/desktop/setSystemProxy: refactor

This commit is contained in:
Guanran Wang 2024-02-26 19:37:43 +08:00
parent 0fb05c61c7
commit c98e5a5c53
Signed by: nyancat
SSH key fingerprint: SHA256:8oWGKciPALWut/6WA27oFKofX+6Wtc0gQnsefXLQx/8

View file

@ -1,5 +1,6 @@
{ {
config, config,
osConfig,
pkgs, pkgs,
lib, lib,
... ...
@ -52,15 +53,23 @@
done done
) )
''; '';
# I should've putted it in /darwin/modules/networking/proxy.nix,
# but I am too stupid to figure out how nix-darwin works...
setSystemProxy = let setSystemProxy = let
inherit (osConfig.networking) knownNetworkServices;
networksetup = /usr/sbin/networksetup; networksetup = /usr/sbin/networksetup;
# naive but works(tm)
# "http://127.0.0.1:1234/" -> "127.0.0.1 1234"
proxy = builtins.replaceStrings ["http://" ":" "/"] ["" " " ""] osConfig.networking.proxy.httpProxy;
in in
lib.hm.dag.entryAfter ["writeBoundary"] '' lib.hm.dag.entryAfter ["writeBoundary"]
${networksetup} -setwebproxystate "Wi-fi" on (lib.concatMapStrings (x: ''
${networksetup} -setwebproxy "Wi-fi" 127.0.0.1 7890 ${networksetup} -setwebproxystate "${x}" on
${networksetup} -setwebproxystate "Ethernet" on ${networksetup} -setwebproxy "${x}" ${proxy}
${networksetup} -setwebproxy "Ethernet" 127.0.0.1 7890 '')
''; knownNetworkServices);
}; };
packages = with pkgs; [ packages = with pkgs; [