mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-01-11 20:40:24 +01:00
feat: update for darwin
This commit is contained in:
29
scripts/darwin_set_proxy.py
Normal file
29
scripts/darwin_set_proxy.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
import plistlib
|
||||
import shlex
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
NIX_DAEMON_PLIST = Path("/Library/LaunchDaemons/org.nixos.nix-daemon.plist")
|
||||
NIX_DAEMON_NAME = "org.nixos.nix-daemon"
|
||||
# http proxy provided by clash
|
||||
HTTP_PROXY = "http://127.0.0.1:7890"
|
||||
|
||||
pl = plistlib.loads(NIX_DAEMON_PLIST.read_bytes())
|
||||
|
||||
# set http proxy
|
||||
pl["EnvironmentVariables"]["HTTP_PROXY"] = HTTP_PROXY
|
||||
pl["EnvironmentVariables"]["HTTPS_PROXY"] = HTTP_PROXY
|
||||
|
||||
os.chmod(NIX_DAEMON_PLIST, 0o644)
|
||||
NIX_DAEMON_PLIST.write_bytes(plistlib.dumps(pl))
|
||||
os.chmod(NIX_DAEMON_PLIST, 0o444)
|
||||
|
||||
# reload the plist
|
||||
for cmd in (
|
||||
f"launchctl unload {NIX_DAEMON_NAME}",
|
||||
f"launchctl load {NIX_DAEMON_NAME}",
|
||||
):
|
||||
subprocess.run(shlex.split(cmd))
|
||||
|
||||
Reference in New Issue
Block a user