Use nix behind proxy

I’m using nix-darwin on my mac. It works quite well, presuming a perfect internet connection. Otherwise it suffocates itself, as it seems to ignore proxy configurations. In particular, it ignores https_proxy.

$ nix-shell -vp neovim
these 8 paths will be fetched (11.76 MiB download, 59.46 MiB unpacked):
copying path '/nix/store/csib1d0pca7rhkiczlwxs740z923dr05-tree-sitter-0.20.6' from ''...
copying path '/nix/store/dmawx3sgaxxlbky8rkgg7r2968dwarbz-luajit-2.1.0-2022-04-05' from ''...
copying path '/nix/store/gng46jz3380afwzjkk6djr6ba8wlh0ph-openssl-1.1.1q-dev' from ''...
downloading ''...
downloading ''...
downloading ''...
warning: error: unable to download '': Timeout was reached (28); retrying in 299 ms

I’m pretty sure that the proxy is functioning.

$ echo $https_proxy
$ time curl '' -vo out.bin
* Uses proxy env variable https_proxy == 'socks5://'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  391k  100  391k    0     0   118k      0  0:00:03  0:00:03 --:--:--  119k
curl  -o out.bin  0.02s user 0.02s system 1% cpu 3.298 total

Has anyone ever managed to make nix work over a proxy?

Seems like it needs to be configured in the systemd service. Have you tried something like roaming laptop: network proxy configuration · Issue #27535 · NixOS/nixpkgs · GitHub ? You might also want the persisted version in /etc as described in Environment Variables

(On NixOs you have a configuration variable made just for that that is added to the service here nixpkgs/nix-daemon.nix at cc11eea79decd441d8413d97b3c539df4ed24333 · NixOS/nixpkgs · GitHub)