Skip to content

Instantly share code, notes, and snippets.

@tunnckoCore
Forked from JonhSHEPARD/install-copilot.sh
Created December 19, 2022 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tunnckoCore/81d030c0978c1cca050dca6136d0a722 to your computer and use it in GitHub Desktop.
Save tunnckoCore/81d030c0978c1cca050dca6136d0a722 to your computer and use it in GitHub Desktop.
Github Copilot on NixOS
#!/bin/sh
if [ "$EUID" -ne 0 ]
then echo "This script must be run as root"
exit
fi
if [ "$#" -ne 1 ]; then
echo "Usage: ./$0 <path-to-ide"
exit 1
fi
BASE="$1"
COPILOT_BIN="$BASE/github-copilot-intellij/copilot-agent/bin"
if [ ! -d "$COPILOT_BIN" ]; then
echo "Copilot plugin data not found, check the specified path"
exit 2
fi
STORE_PATH="/nix/store"
LIB_PATH="/lib64"
echo "Searching for necessary libs..."
LIB_LD=$(find "$STORE_PATH" -name "*ld-linux-x86-64.so.2" \
| grep "\-glibc\-" \
| head -n 1)
if [ -z "$LIB_LD" ]; then
echo "Cannot find 'ld-linux-x86-64.so.2' in nix/store"
exit 3
else
echo "Found ld-linux at $LIB_LD"
fi
LIB_STDCPP=$(find "$STORE_PATH" -name "libstdc++.so.6" \
| grep "\-gcc\-" \
| head -n 1)
if [ -z "$LIB_STDCPP" ]; then
echo "Cannot find 'libstdc++.so.6' in nix/store"
exit 4
else
echo "Found libstdc++ at $LIB_STDCPP"
fi
if [ ! -d "$LIB_PATH" ]; then
echo "Creating '$LIB_PATH' folder to store libraries"
mkdir -p "$LIB_PATH"
fi
echo "Linking '$LIB_LD' in $LIB_PATH"
ln -nsf "$LIB_LD" "$LIB_PATH/ld-linux-x86-64.so.2"
echo "Linking '$LIB_STDCPP' in $LIB_PATH"
ln -nsf "$LIB_STDCPP" "$LIB_PATH/libstdc++.so.6"
cd "$COPILOT_BIN"
echo "Moving copilot agent to setup the wrapper"
mv "copilot-agent-linux" "copilot-agent-linux-bin"
echo "Creating the wrapper"
echo "#!/bin/sh
export LD_LIBRARY_PATH=\"$LIB_PATH\"
exec ./copilot-agent-linux-bin" > copilot-agent-linux
chmod +x copilot-agent-linux
echo "Everything done !"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment