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,
osConfig,
pkgs,
lib,
...
@ -52,15 +53,23 @@
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
inherit (osConfig.networking) knownNetworkServices;
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
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
'';
lib.hm.dag.entryAfter ["writeBoundary"]
(lib.concatMapStrings (x: ''
${networksetup} -setwebproxystate "${x}" on
${networksetup} -setwebproxy "${x}" ${proxy}
'')
knownNetworkServices);
};
packages = with pkgs; [