Hello. I’m trying to get Copilot working with CLion.
I was able to install CLion just fine and install the Copilot plugin.
It now requires me to login through GitHub. It fails with “Failed to initiate the GitHub login process. Please try again.”
The more precise error is “#c.g.c.l.a.AgentGitHubService - error retrieving device code”
That person’s config is… sophisticated. This is impressive
Anyway, I don’t know how I didn’t find this PR before. Is there an easy way to merge it?
Edit: looks like I can use nixos-rebuild -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/pull/191341/head.tar.gz
Below is the overlay I use to add the copilot plugin to Intellij Ultimate and Clion (given that the plugin PR is available in your nixpkgs, which you figured out already). This overlays also pins the versions of the IDEs, but that’s not required of course.
It might be useful to people, as my config is more “traditional”. Of course, all credits to actually get the plugin working still go to Rien .
final: prev: {
jetbrains = prev.jetbrains // {
# Get info from site...
copilot-plugin-info = prev.jetbrains.plugins.getUrl {
id = "17718";
hash = "sha256-GF2ypX+ZYVL8r6A/qhykrM2hwDnSv3v5pfLFsLBEt4I=";
};
# Actually build the plugin
copilot-plugin = prev.jetbrains.plugins.urlToDrv (final.jetbrains.copilot-plugin-info
// {
hash = "sha256-117CHiwMOlEoiZBRk7hT3INncargoeYCuewpCeQ4nz8=";
extra = {
inputs = [prev.patchelf prev.glibc prev.gcc-unwrapped];
commands = let
libPath = prev.lib.makeLibraryPath [prev.glibc prev.gcc-unwrapped];
in ''
agent="copilot-agent/bin/copilot-agent-linux"
orig_size=$(stat --printf=%s $agent)
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $agent
patchelf --set-rpath ${libPath} $agent
chmod +x $agent
new_size=$(stat --printf=%s $agent)
# https://github.com/NixOS/nixpkgs/pull/48193/files#diff-329ce6280c48eac47275b02077a2fc62R25
###### zeit-pkg fixing starts here.
# we're replacing plaintext js code that looks like
# PAYLOAD_POSITION = '1234 ' | 0
# [...]
# PRELUDE_POSITION = '1234 ' | 0
# ^-----20-chars-----^^------22-chars------^
# ^-- grep points here
#
# var_* are as described above
# shift_by seems to be safe so long as all patchelf adjustments occur
# before any locations pointed to by hardcoded offsets
var_skip=20
var_select=22
shift_by=$(expr $new_size - $orig_size)
function fix_offset {
# $1 = name of variable to adjust
location=$(grep -obUam1 "$1" $agent | cut -d: -f1)
location=$(expr $location + $var_skip)
value=$(dd if=$agent iflag=count_bytes,skip_bytes skip=$location \
bs=1 count=$var_select status=none)
value=$(expr $shift_by + $value)
echo -n $value | dd of=$agent bs=1 seek=$location conv=notrunc
}
fix_offset PAYLOAD_POSITION
fix_offset PRELUDE_POSITION
'';
};
});
# Control the version of Intellij ourselves and add the plugin.
idea-ultimate = prev.jetbrains.idea-ultimate.overrideAttrs (old: rec {
version = "2022.2.2";
src = prev.fetchurl {
url = "https://download.jetbrains.com/idea/ideaIU-${version}-no-jbr.tar.gz";
sha256 = "zBmi7Pyzmf9KxpWikEUN3krXu0sEjgsCLTZr/XWV+4s=";
};
plugins = [final.jetbrains.copilot-plugin];
});
clion = prev.jetbrains.clion.overrideAttrs (old: rec {
version = "2022.2.1";
src = prev.fetchurl {
url = "https://download.jetbrains.com/cpp/CLion-${version}.tar.gz";
sha256 = "sha256-oNnnetSvu199aeI8+EzPEy7tbq1sOnzUQrM5JOaTFlY=";
};
plugins = [final.jetbrains.copilot-plugin];
});
};
}
You need to replace the second line (jetbrains = {) by jetbrains = prev.jetbrains // { and it should work.
The problem with the original line is that the whole jetbrains group in nixpkgs is overridden, resulting in the jdk package missing.
Yeah I haven’t pinned a version yet, so this happens each time the plugin is updated.
If I remember correctly, a fix that worked for me for the JSON issue is to replace the second hash (in copilot-plugin) by the empty string when the first hash is changed. This will error with a hash mismatch, but will give you the correct hash for copilot-plugin.
Alright, your overlay appears to work in a brand new VM.
It doesn’t work on my laptop. And the new nixpkgs version causes some issues. But I can probably find a way around that
Thank you!