Skip to the content.

Nix

Use the proxy as the binary cache (substituter). The examples use the upstream name nix; replace it with the name your operator gave the upstream (what you need).

   
Upstream type nix
Package source https://proxy.example.com/v1/nix
Clients nix
Tested Nix 2.35: in CI on every push and in the client lab.

Configure

In nix.conf (/etc/nix/nix.conf, or ~/.config/nix/nix.conf for a trusted user):

substituters = https://proxy.example.com/v1/nix
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
require-sigs = true

substituters replaces cache.nixos.org (use extra-substituters to add instead). trusted-public-keys stays the upstream cache’s key: the proxy serves each signed narinfo as it is, apart from the unsigned NAR location, so Nix keeps verifying every path against the cache’s own signature.

The same as command-line options, as the CI test passes them: --option substituters https://proxy.example.com/v1/nix.

Authenticate

Only when the proxy has access control switched on. The proxy takes your proxy token as the password of HTTP Basic authentication, with any user name. Nix reads it from a netrc file named in nix.conf:

netrc-file = /etc/nix/netrc

/etc/nix/netrc (mode 600; with a Nix daemon, readable by the daemon):

machine proxy.example.com
  login pullthrough
  password <token>

Nix fetches with curl, which looks the entry up by host name alone: when the proxy’s address has a port (https://proxy.example.com:8443), the machine line still names only the host. An entry with the port is never used.

Trust a private CA

In nix.conf:

ssl-cert-file = /etc/ssl/corp-ca.pem

Check that it works

nix-store --realise /nix/store/n5glp21rsz314qssw9fbvfswgy3kc68f-hello-2.12.1

Nix prints copying path '…' from 'https://proxy.example.com/v1/nix'... for every path it substitutes. nix config show substituters prints the setting in effect.

Good to know

On the proxy

upstreams:
  nix:
    type: nix
    url: https://cache.nixos.org
    settings:
      trustedPublicKeys: "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="

The proxy verifies each narinfo signature against trustedPublicKeys and each NAR against its content address before serving it. Details: backends: nix.