i installed my system with a proxy to access network (configured
networing.proxy.default in the configuration.nix file).
Right now I am using a network without a proxy. Then I commented the
networing.proxy.default line and run
nixos-rebuild switch
however the rebuild tries to access some remote url ... with the previous proxy
configuration.
how to turn on / off the proxy (manually unset the *_proxy env variable is not
working)?
The module sets environment variables and those are updated after a successful nixos-rebuild switch. On top of that the user has to logout and login back again for the new variables to take effect.
If the proxy is enabled but log longer available it can affect the nixos-rebuild because those environment variables are taken into account by nix. To work around that you can unset http_proxy and the other proxy variables outputted by env | grep proxy in the terminal before running nixos-rebuild switch.
To work around that you can unset http_proxy and the other proxy variables
outputted by env | grep proxy in the terminal before running nixos-rebuild
switch.
I tried to unset every result of env|grep proxy. Still nixos-rebuild
switch returns âcouldnât resolve proxy nameâ. Thanks for any help on
this
Youâre right, the proxy env vars are actually set on the nix-daemon directly instead of being forwarded by the client:
Typically with systemd itâs possible to override existing units but not on NixOS:
$ sudo systemctl edit nix-daemon
Failed to create temporary file for "/etc/systemd/system/nix-daemon.service.d/override.conf": Read-only file system
This is because /etc/systemd/system points into the /nix/store which is mounted read-only for everyone except the nix-daemon. You also canât edit the unit itself because of the same reason.
Now I am running a bit out of ideas.
ESCAPE HATCH. DONâT PRESS THE RED BUTTON.
As a last recourse, you can re-mount the /nix/store read-write and edit the unit. This is obviously really bad as the store becomes no longer consistent.
$ sudo mount -o remount,rw /nix/store
# Look for the file and remove the lines:
$ sudo systemstd cat nix-daemon
$ sudo mount -o remount,ro /nix/store
$ sudo systemctl stop nix-daemon.socket nix-daemon
$ sudo systemctl start nix-daemon
Try running the nixos-rebuild. Since the nix-daemon is socket-actived it will only start after nix-build has been invoked. If it doesnât work you can also check what environment variables the daemon has like that:
thanks for your help. I change proxy configuration several times a day.
I am not confident such complicated a solution is appropriate in this case.
In such a situation I just instlled a local proxy, installed multiple configuration files for it, used the local proxy as the proxy in most programs and restarted the proxy with a proper upstream as needed.