配置nix-cache代理服务器

# 需要加速的地址
channel 地址 https://releases.nixos.org 目录最后一个文件路径用于下载最新的源代码
cache二进制地址 地址 https://cache.nixos.org/ 用于下载最新的二进制文件

# 参考文章

FAQ/Private Cache Proxy
https://nixos.wiki/wiki/FAQ/Private_Cache_Proxy


How to make a local NixOS cache server
https://dataswamp.org/~solene/2022-06-02-nixos-local-cache.html
  • caddy服务端代理

cache.leng2011.icu:80 {
   reverse_proxy /* https://cache.nixos.org {
      header_up Host cache.nixos.org
      header_up X-Real-IP {remote}
      header_up X-Forwarded-For {remote}
      header_up X-Forwarded-Port {server_port}
      header_up X-Forwarded-Proto "http"
   }
}

nginx代理和nix-channel代理

server {
    listen 80;
    server_name cache.leng2011.icu;

    location / {
       proxy_pass https://cache.nixos.org;
       proxy_set_header Host "cache.nixos.org";
   }
}
  • 使用

sudo nixos-rebuild switch --option substituters http://cache.leng2011.icu
nix.binaryCaches = [ "http://cache.leng2011.icu" ];

code ~/.config/nix/nix.conf

require-sigs = false
experimental-features = nix-command flakes
substituters = http://cache.leng2011.icu https://cache.nixos.org
binary-caches = http://cache.leng2011.icu
  • kangle代理

<request action='vhs' >
        <table name='BEGIN'>
                <chain  action='continue'  name='prixy_cachenix'>
                        <acl_host  split='|'>cache.leng2011.icu</acl_host>
                        <mark_add_header   attr='Host' val='cache.nixos.org'></mark_add_header>
                        <mark_host   host='cache.nixos.org' port='80' proxy='1' rewrite='1' life_time='0'></mark_host>
                </chain>
        </table>
</request>

3.6版本
<request action='vhs' >
  <table name='BEGIN'>
    <chain action='continue' name='prixy_cachenix'>
      <acl_host split='|'>cache.test.net</acl_host>
      <mark_add_header attr='Host' val='cache.nixos.org'></mark_add_header>
      <mark_host host='cache.nixos.org' port='80' proxy='1' rewrite='1' life_time='0'></mark_host>
    </chain>
  </table>
</request>