聲明:禁止轉載~

nimble是nim語言的包管理器
由于github被墻的原因,導致在使用nimble安裝庫的時候通常會失敗無法安裝.
命令行程序似乎并不理會我的v2rayN開啟的系統代理,開了它并不走系統瀏覽器的代理,沒有效果。
所以需要自己另外設置針對CMD\nimble\git的網絡代理。

有三種設置代理的方法:

方法1:適用于windows
參考 http://www.rzrgm.cn/DarkMaster/p/7852893.html
給cmd設置代理:通過執行命令,臨時設置環境變量

set http_proxy=http://127.0.0.1:1189  
set https_proxy=http://127.0.0.1:1189

方法2:適合于多平臺
根據方法1 以及閱讀nimble的源代碼,可以通過設置一個http_proxy環境變量指定代理.

nimble源代碼見:https://github.com/nim-lang/nimble/blob/master/src/nimblepkg/options.nim#L679

proc getProxy*(options: Options): Proxy =
  ## Returns ``nil`` if no proxy is specified.
  var url = ""
  if ($options.config.httpProxy).len > 0:
    url = $options.config.httpProxy
  else:
    try:
      if existsEnv("http_proxy"):
        url = getEnv("http_proxy")
      elif existsEnv("https_proxy"):
        url = getEnv("https_proxy")
      elif existsEnv("HTTP_PROXY"):
        url = getEnv("HTTP_PROXY")
      elif existsEnv("HTTPS_PROXY"):
        url = getEnv("HTTPS_PROXY")
    except ValueError:
      display("Warning:", "Unable to parse proxy from environment: " &
          getCurrentExceptionMsg(), Warning, HighPriority)

另外根據nimble源碼,也可創建nimble.ini來指定代理設置.


方法3:適用于多平臺
由于nimble是通過調用git從github下載庫相關文件的,所以可以給git設置代理.

git config --global http.https://github.com.proxy http://127.0.1:50808

參考:
Configure Git to use a proxy
https://gist.github.com/evantoli/f8c23a37eb3558ab8765

nimble的文檔中有關于nimble.ini的相關說明:
https://github.com/nim-lang/nimble
2022年05月09日14點24分23秒