How to run nix-shell behind a corporate proxy

Hi all,

I have managed to install and have internet acccess over a corporate proxy with NixOS. But know I am facing issues when I try to run nix-shell.
When trying to create a shell env with nix-shell I am getting connection errors.

My shell.nix file:

{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {

shellHook = ''
export https_proxy=...
# and so on
'';

preShellHook = ''
export https_proxy=...
# and so on
'';
}

When running nix-shell:

env | grep -i proxy
# https_proxy=...
# and so on

nix-shell shell.nix
# resulting in a Couldn't connect to server (7) error;

https_proxy=... nix-shell shell.nix
# resulting in a Couldn't connect to server (7) error;

Do you have any ideas? I would really like to use NixOS also on my work machines.

I assume you are running the multi-user install with a daemon? If so then the daemon process needs to have the proxy vars set. According to [1] the installer is meant to do that, but maybe you could check and add the proxy env if necessary?

[1]
https://nixos.org/manual/nix/stable/installation/env-variables.html#proxy-environment-variables

1 Like

Yes! you were right thanks.
So what I did is I added env variables via

systemd.services.nix-daemon.environment = { http_proxy = "..."; }.

Is there are way to read systemd service variables from file because I am using agenix to manage my secrets at runtime?

1 Like

There is, check EnvironmentFile here systemd.exec

1 Like