Created
November 3, 2016 16:17
-
-
Save edwtjo/a565ac600f263dbcdd97f446d9b711bf to your computer and use it in GitHub Desktop.
Dynamic NixOS Proxy Switcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
orig=`echo $NIX_PATH | sed -e "s,.*nixos-config=\(.*\)\.nix,\1.nix,"` | |
export NIX_REMOTE="" | |
buildAndSwitch() { | |
sudo -E nix-build \ | |
-A system '<nixpkgs/nixos>' \ | |
--option use-binary-caches false | |
sudo -E nixos-rebuild switch --option use-binary-caches false | |
} | |
unsetProxy() { | |
export http_proxy="" | |
export NIX_CURL_FLAGS="" | |
sudo sed --follow-symlinks -i -e "/networking.proxy.default/d" $orig | |
} | |
setProxy () { | |
export http_proxy="$1" | |
export NIX_CURL_FLAGS="-x $http_proxy" | |
sudo sed --follow-symlinks -i -e "\$i\ \ networking\.proxy\.default \= \""$1"\"\;" $orig | |
} | |
case $1 in | |
l | list ) | |
nixos-option networking.proxy.default | |
;; | |
p | proxy ) | |
shift | |
case $1 in | |
http://* ) | |
echo "Setting proxy to: $1" | |
setProxy $1 | |
buildAndSwitch | |
;; | |
* ) | |
echo "Unsetting proxy" | |
unsetProxy | |
buildAndSwitch | |
;; | |
esac | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment