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):
  /nix/store/1ndc5sjxaqfq5p1yfwq3f5si0bbpqxxy-ruby2.7.6-msgpack-1.5.1
  /nix/store/31gjnlqhlngixzfkjzc0cgscc035wbwb-neovim-unwrapped-0.7.2
  /nix/store/9lc10qqdnn20x2xsvlfx9czyjcwzqsv2-ruby-2.7.6
  /nix/store/a11wfpp26vfvqlgidgnrzll83csgmkcg-bundler-2.3.20
  /nix/store/azq4jllhg6myk0v1ih887zg5ahvwzkwq-ruby2.7.6-neovim-0.9.0
  /nix/store/csib1d0pca7rhkiczlwxs740z923dr05-tree-sitter-0.20.6
  /nix/store/dmawx3sgaxxlbky8rkgg7r2968dwarbz-luajit-2.1.0-2022-04-05
  /nix/store/gng46jz3380afwzjkk6djr6ba8wlh0ph-openssl-1.1.1q-dev
copying path '/nix/store/csib1d0pca7rhkiczlwxs740z923dr05-tree-sitter-0.20.6' from 'https://cache.nixos.org'...
copying path '/nix/store/dmawx3sgaxxlbky8rkgg7r2968dwarbz-luajit-2.1.0-2022-04-05' from 'https://cache.nixos.org'...
copying path '/nix/store/gng46jz3380afwzjkk6djr6ba8wlh0ph-openssl-1.1.1q-dev' from 'https://cache.nixos.org'...
downloading 'https://cache.nixos.org/nar/14q76a24fp13lcr5hwybbn2a8pkhkr2qwfwnlgkdbml30m6rpswz.nar.xz'...
downloading 'https://cache.nixos.org/nar/1sqdn6j9n6cd4947rcwcprxkqdzz0isrgyxcw3bm9bs7v9za42zp.nar.xz'...
downloading 'https://cache.nixos.org/nar/0qjzx040vc59qg69n713pn474sjrwblq9sg9b1r0zk6yivssxd2k.nar.xz'...
warning: error: unable to download 'https://cache.nixos.org/nar/14q76a24fp13lcr5hwybbn2a8pkhkr2qwfwnlgkdbml30m6rpswz.nar.xz': Timeout was reached (28); retrying in 299 ms

I’m pretty sure that the proxy is functioning.

$ echo $https_proxy
socks5://127.0.0.1:12345
$ time curl 'https://cache.nixos.org/nar/14q76a24fp13lcr5hwybbn2a8pkhkr2qwfwnlgkdbml30m6rpswz.nar.xz' -vo out.bin
* Uses proxy env variable https_proxy == 'socks5://127.0.0.1:13659'
  % 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)