# Set root of the gopath to where the shell.nix is located GOPATH="$(pwd)" while [ ! -e "$GOPATH/shell.nix" ] && [ "$GOPATH" != "/" ]; do GOPATH="$(realpath $GOPATH/..)" done [ -e "$GOPATH/shell.nix" ] || { echo "No shell.nix found in expected GOPATH. This is unexpected. GOPATH not set." 1>&2 exit 1 } export GOPATH="$GOPATH" mkdir -p $GOPATH/{bin,pkg,src} if [ ! -e "$GOPATH/.go-autopath" ]; then touch "$GOPATH/.go-autopath" echo "# Config file to configure whether or not to register GOPATH/bin in PATH automatically" >> "$GOPATH/.go-autopath" echo "# Generated by nixify" >> "$GOPATH/.go-autopath" [ -e "$GOPATH/.gitignore" ] && echo ".go-autopath" >> "$GOPATH/.gitignore" read -p "Automatically add GOPATH/bin to you PATH? (y/n)" -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]] ; then echo "NIXIFY_GO_AUTOPATH=true" >> "$GOPATH/.go-autopath" else echo "NIXIFY_GO_AUTOPATH=false" >> "$GOPATH/.go-autopath" fi fi if [ -e "$GOPATH/.go-autopath" ]; then NIXIFY_GO_AUTOPATH=false . "$GOPATH/.go-autopath" if [ "$NIXIFY_GO_AUTOPATH" = "true" ]; then export PATH="$GOPATH/bin:$PATH" fi fi