darwin/setSystemProxy: ./home -> ./darwin

- Also turns out nix-darwin hardcodes list of activation scripts. :(

  see: https://github.com/LnL7/nix-darwin/blob/master/modules/system/activation-scripts.nix
This commit is contained in:
Guanran Wang 2024-02-26 21:15:48 +08:00
parent c98e5a5c53
commit 61b9bc5e37
Signed by: nyancat
SSH key fingerprint: SHA256:8oWGKciPALWut/6WA27oFKofX+6Wtc0gQnsefXLQx/8
2 changed files with 15 additions and 18 deletions

View file

@ -119,5 +119,20 @@ in {
# Install the proxy environment variables # Install the proxy environment variables
environment.variables = cfg.proxy.envVars; environment.variables = cfg.proxy.envVars;
launchd.daemons."nix-daemon".environment = cfg.proxy.envVars; launchd.daemons."nix-daemon".environment = cfg.proxy.envVars;
# Set macOS's system level proxy setting
system.activationScripts."extraActivation".text = let
inherit (cfg) knownNetworkServices;
networksetup = /usr/sbin/networksetup;
# naive but works(tm)
# "http://127.0.0.1:1234/" -> "127.0.0.1 1234"
proxy = builtins.replaceStrings ["http://" ":" "/"] ["" " " ""] cfg.proxy.httpProxy;
in
lib.concatMapStrings (x: ''
${networksetup} -setwebproxystate "${x}" on
${networksetup} -setwebproxy "${x}" ${proxy}
'')
knownNetworkServices;
}; };
} }

View file

@ -1,6 +1,5 @@
{ {
config, config,
osConfig,
pkgs, pkgs,
lib, lib,
... ...
@ -53,23 +52,6 @@
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
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"]
(lib.concatMapStrings (x: ''
${networksetup} -setwebproxystate "${x}" on
${networksetup} -setwebproxy "${x}" ${proxy}
'')
knownNetworkServices);
}; };
packages = with pkgs; [ packages = with pkgs; [