NixOS installation failing behind proxy (nix-shell can't resolve hosts)

I’m struggling to install NixOS behind a proxy. I’ve tried several approaches, but I keep hitting a wall where the Nix package manager can’t reach the binary caches.

My Setup:

  • Connection: Phone connected via Ethernet running a local proxy server.
  • Installer: NixOS Minimal Installer.
  • Environment Variables: I have set HTTP_PROXY, HTTPS_PROXY, and ALL_PROXY (both uppercase and lowercase).

The Problem:

Connectivity seems to work for standard tools, but fails for Nix:

  • Works: curl -I "https://cache.nixos.org" and curl -I "https://tarballs.nixos.org" both return a successful response.
  • Fails: ping cache.nixos.org.
  • Fails: nix-shell -p cowsay results in: failed to download, can't resolve hosts: cache.nixos.org, tarball.nixos.org.

The Specific Constraint:

In my region, nixos.org is accessible, but cache.nixos.org and tarballs.nixos.org are blocked/unaccessible without the proxy.

Does anyone have a reliable way to pass proxy settings to the daemon during the initial installation? Any help would be greatly appreciated!

What region? Just curious.

I am living in Iran.

Could be a fastly issue. Maybe you can try the TUNA mirror:

1 Like

Thanks. I’ll give it a shot but I don’t think it’ll work. The problem is that Nix is unable to detect my proxy. When I wanted to install Arch Linux, I just had to set the related environment variables and it just worked, but Nix isn’t working.

Since Nix allows non-root access to packages, it uses a daemon to do the most of the work. Therefore you may want to set the proxy on the systemd service instead.

Use sudo systemctl edit --runtime nix-daemon.service and write something like this, setting the exact variables you want to set:

[Service]
Environment="https_proxy=..." "http_proxy=..."

Then sudo systemctl restart nix-daemon.service.

After installation, you may want to set this up permanently with options under networking.proxy. However note that they will only apply after the first nixos-rebuild switch, since the configuration switch happens after building.

2 Likes

This solves my problem. Thanks!