mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-07-12 07:32:40 +02:00
feat: update darwin set proxy
This commit is contained in:
+21
-17
@@ -1,5 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
set proxy for nix-daemon to speed up downloads
|
Set proxy for nix-daemon to speed up downloads
|
||||||
|
You can safely ignore this file if you don't need a proxy.
|
||||||
|
|
||||||
https://github.com/NixOS/nix/issues/1472#issuecomment-1532955973
|
https://github.com/NixOS/nix/issues/1472#issuecomment-1532955973
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
@@ -7,31 +9,33 @@ import plistlib
|
|||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
NIX_DAEMON_PLIST = Path("/Library/LaunchDaemons/org.nixos.nix-daemon.plist")
|
NIX_DAEMON_PLIST = Path("/Library/LaunchDaemons/org.nixos.nix-daemon.plist")
|
||||||
NIX_DAEMON_NAME = "org.nixos.nix-daemon"
|
NIX_DAEMON_NAME = "org.nixos.nix-daemon"
|
||||||
# http proxy provided by clash
|
# http proxy provided by clash or other proxy tools
|
||||||
HTTP_PROXY = "http://127.0.0.1:7890"
|
HTTP_PROXY = "http://127.0.0.1:7890"
|
||||||
|
|
||||||
pl = plistlib.loads(NIX_DAEMON_PLIST.read_bytes())
|
pl = plistlib.loads(NIX_DAEMON_PLIST.read_bytes())
|
||||||
|
|
||||||
# set http proxy
|
# set http/https proxy
|
||||||
pl["EnvironmentVariables"]["HTTP_PROXY"] = HTTP_PROXY
|
# NOTE: curl only accept the lowercase of `http_proxy`!
|
||||||
pl["EnvironmentVariables"]["HTTPS_PROXY"] = HTTP_PROXY
|
# NOTE: https://curl.se/libcurl/c/libcurl-env.html
|
||||||
|
pl["EnvironmentVariables"]["http_proxy"] = HTTP_PROXY
|
||||||
|
pl["EnvironmentVariables"]["https_proxy"] = HTTP_PROXY
|
||||||
|
|
||||||
# remove http proxy
|
# remove http proxy
|
||||||
# pl["EnvironmentVariables"].pop("HTTP_PROXY", None)
|
# pl["EnvironmentVariables"].pop("http_proxy", None)
|
||||||
# pl["EnvironmentVariables"].pop("HTTPS_PROXY", None)
|
# pl["EnvironmentVariables"].pop("https_proxy", None)
|
||||||
|
|
||||||
os.chmod(NIX_DAEMON_PLIST, 0o644)
|
os.chmod(NIX_DAEMON_PLIST, 0o644)
|
||||||
NIX_DAEMON_PLIST.write_bytes(plistlib.dumps(pl))
|
NIX_DAEMON_PLIST.write_bytes(plistlib.dumps(pl))
|
||||||
os.chmod(NIX_DAEMON_PLIST, 0o444)
|
os.chmod(NIX_DAEMON_PLIST, 0o444)
|
||||||
|
|
||||||
# reload the plist
|
# reload the plist
|
||||||
for cmd in (
|
for cmd in (
|
||||||
f"launchctl unload {NIX_DAEMON_PLIST}",
|
f"launchctl unload {NIX_DAEMON_PLIST}",
|
||||||
f"launchctl load {NIX_DAEMON_PLIST}",
|
f"launchctl load {NIX_DAEMON_PLIST}",
|
||||||
):
|
):
|
||||||
print(cmd)
|
print(cmd)
|
||||||
subprocess.run(shlex.split(cmd), capture_output=False)
|
subprocess.run(shlex.split(cmd), capture_output=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user