Using nix specialisations for vpn

I require the use of a vpn with a proxy server.
I tried the following conf:

  specialisation.vpn.configuration = {
    environment.variables = rec{
      http_proxy = "http://proxy.ip";
      https_proxy = http_proxy;
      no_proxy = "localhost,other.exeptions";
    };
    networking.networkmanager.dns = "default";
  };
  environment.systemPackages = with pkgs;[
    (writeScriptBin "connectVpn" ''
      set -euxo pipefail
      function normal(){
        /run/current-system/bin/switch-to-configuration test
      }
      trap normal EXIT
      /run/current-system/specialisation/vpn/bin/switch-to-configuration test
      #vpn connection cmd
    '')
  ];

With the intention of using sudo connectVpn to fully connect to my vpn.
However when I try to open a new terminal, the variables are not set appropriately. I’ve also tried networking.proxy, with little effect.
Why does it not set the appropriate variables?
How should I do it, considering that either I need to use the proxy when the vpn is active?

Unfortunately it doesn’t work like that: these variables are set in /etc/profile, which is probably loaded by the shell once, after you log in. So you may have to log out and back in to reload these variables.

I don’t think there’s a general way to live reload environment variables in a running program. If you’re using the fish shell, there are “universal” variables that actually work like that (shared and updated between all shell sessions), but you would still have to close and reopen the browser, for example.

If you’re only interested in the browser, you can implement live reloading using a PAC file. You could serve it using something like python -m http.server and point the browser to it.

In the end I’ve solved it by configuring split tunneling for the vpn, avoiding the need for the proxy. I didn’t even need to touch configuration.nix

Still added your link to read it later