CLion + Github Copilot fails to login

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”

Was anyone able to fix this error?


1 Like

The problem is that the Copilot plugin needs to be patched to work on NixOS.

One way to do this is using an open PR to add Jetbrains plugins to nixpkgs, see Jetbrains plugins by GenericNerdyUsername · Pull Request #191341 · NixOS/nixpkgs · GitHub

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=

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 :slight_smile:.

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 ''
            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)
            ###### 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
            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 = "${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 = "${version}.tar.gz";
        sha256 = "sha256-oNnnetSvu199aeI8+EzPEy7tbq1sOnzUQrM5JOaTFlY=";
      plugins = [final.jetbrains.copilot-plugin];

Hi @niknetniko ,

I’ve tried to use your config in NixOS overlays but I get following error:

└➤ sudo nixos-rebuild -I nixpkgs= switch --upgrade
unpacking channels...
building Nix...
building the system configuration...
error: attribute 'jdk' missing

       at /nix/store/66z15ggbdfqbb4mcg35hhlqpy0s6hdgi-nixos-22.05/nixos/pkgs/top-level/all-packages.nix:26851:11:

        26850|     vmopts = config.jetbrains.vmopts or null;
        26851|     jdk = jetbrains.jdk;
             |           ^
        26852|   }) // {

Do you have any idea on what I could miss? Here are the surrounding lines from all-packages.nix:

  jetbrains = (recurseIntoAttrs (callPackages ../applications/editors/jetbrains {
    vmopts = config.jetbrains.vmopts or null;
    jdk = jetbrains.jdk;
  }) // {
    jdk = callPackage ../development/compilers/jetbrains-jdk {  };

Ah, that’s my bad.

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.

(I’ve also updated my original post)

1 Like

So, were you able to build with this config?
There is a hash mismatch for “copilot-plugin-info”

Fixing it to use the correct hash results in a JSON parse error

Edit: Currently trying with specifying a version, install in progress

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!

Hi @niknetniko, thank you! I’ve added the overlay feat: add copilot plugin · ktor/nixos@35f4071 · GitHub and it builds succesfully. Had to remove locally installed plugin and restart the thing for it to work.

1 Like

Since this issue still exists, there is a new open PR: jetbrains: add plugin support by GenericNerdyUsername · Pull Request #223593 · NixOS/nixpkgs · GitHub