From d5fdecd89485483b1954360b8234f4fafa90c626 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Fri, 11 Jul 2025 19:59:35 -0700 Subject: [PATCH 1/2] jetbrains-plugins: fix copilot plugin Previous derivation started failing with: > expr: syntax error: unexpected argument '41911289' I'm not really sure I understand the fix but someone shared their overlay on the issue that many cited as having worked. fixes #400317 --- .../jetbrains/plugins/specialPlugins.nix | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/pkgs/applications/editors/jetbrains/plugins/specialPlugins.nix b/pkgs/applications/editors/jetbrains/plugins/specialPlugins.nix index ccfd90b68b8c..5387a0efac02 100644 --- a/pkgs/applications/editors/jetbrains/plugins/specialPlugins.nix +++ b/pkgs/applications/editors/jetbrains/plugins/specialPlugins.nix @@ -55,30 +55,36 @@ } .${stdenv.hostPlatform.uname.processor} or "" }/copilot-language-server' - orig_size=$(stat --printf=%s $agent) - patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $agent - patchelf --set-rpath ${ - lib.makeLibraryPath [ - glibc - gcc-unwrapped - ] - } $agent - chmod +x $agent - new_size=$(stat --printf=%s $agent) - var_skip=20 - var_select=22 - shift_by=$(($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 + + # Helper: find the offset of the payload by matching gzip magic bytes + find_payload_offset() { + grep -aobUam1 -f <(printf '\x1f\x8b\x08\x00') "$agent" | cut -d: -f1 + } + + # Helper: find the offset of the prelude by searching for function string start + find_prelude_offset() { + local prelude_string='(function(process, require, console, EXECPATH_FD, PAYLOAD_POSITION, PAYLOAD_SIZE) {' + grep -obUa -- "$prelude_string" "$agent" | cut -d: -f1 + } + + before_payload_position="$(find_payload_offset)" + before_prelude_position="$(find_prelude_offset)" + + patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $agent + patchelf --set-rpath ${ + lib.makeLibraryPath [ + glibc + gcc-unwrapped + ] + } $agent + chmod +x $agent + + after_payload_position="$(find_payload_offset)" + after_prelude_position="$(find_prelude_offset)" + + # There are hardcoded positions in the binary, then it replaces the placeholders by himself + sed -i -e "s/$before_payload_position/$after_payload_position/g" "$agent" + sed -i -e "s/$before_prelude_position/$after_prelude_position/g" "$agent" ''; }; "22407" = { From a0a6c89156421a0353c111542256fb0734affdb7 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Wed, 30 Jul 2025 08:08:01 -0700 Subject: [PATCH 2/2] Augment to support x86 and arm64 Co-authored-by: Samuele Facenda --- .../jetbrains/plugins/specialPlugins.nix | 61 ++++++++++++------- .../editors/jetbrains/plugins/tests.nix | 1 - 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/pkgs/applications/editors/jetbrains/plugins/specialPlugins.nix b/pkgs/applications/editors/jetbrains/plugins/specialPlugins.nix index 5387a0efac02..dfbd81a540a0 100644 --- a/pkgs/applications/editors/jetbrains/plugins/specialPlugins.nix +++ b/pkgs/applications/editors/jetbrains/plugins/specialPlugins.nix @@ -55,36 +55,55 @@ } .${stdenv.hostPlatform.uname.processor} or "" }/copilot-language-server' + orig_size=$(stat --printf=%s $agent) - # Helper: find the offset of the payload by matching gzip magic bytes - find_payload_offset() { - grep -aobUam1 -f <(printf '\x1f\x8b\x08\x00') "$agent" | cut -d: -f1 - } + find_payload_offset() { + grep -aobUam1 -f <(printf '\x1f\x8b\x08\x00') "$agent" | cut -d: -f1 + } - # Helper: find the offset of the prelude by searching for function string start - find_prelude_offset() { - local prelude_string='(function(process, require, console, EXECPATH_FD, PAYLOAD_POSITION, PAYLOAD_SIZE) {' - grep -obUa -- "$prelude_string" "$agent" | cut -d: -f1 - } + # Helper: find the offset of the prelude by searching for function string start + find_prelude_offset() { + local prelude_string='(function(process, require, console, EXECPATH_FD, PAYLOAD_POSITION, PAYLOAD_SIZE) {' + grep -obUa -- "$prelude_string" "$agent" | cut -d: -f1 + } - before_payload_position="$(find_payload_offset)" - before_prelude_position="$(find_prelude_offset)" + before_payload_position="$(find_payload_offset)" + before_prelude_position="$(find_prelude_offset)" - patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $agent - patchelf --set-rpath ${ - lib.makeLibraryPath [ - glibc - gcc-unwrapped - ] - } $agent - chmod +x $agent + patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $agent + patchelf --set-rpath ${ + lib.makeLibraryPath [ + glibc + gcc-unwrapped + ] + } $agent + chmod +x $agent + new_size=$(stat --printf=%s $agent) + var_skip=20 + var_select=22 + shift_by=$(($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 + } - after_payload_position="$(find_payload_offset)" - after_prelude_position="$(find_prelude_offset)" + after_payload_position="$(find_payload_offset)" + after_prelude_position="$(find_prelude_offset)" + if [ "${stdenv.hostPlatform.system}" == "aarch64-linux" ] + then + fix_offset PAYLOAD_POSITION + fix_offset PRELUDE_POSITION + else # There are hardcoded positions in the binary, then it replaces the placeholders by himself sed -i -e "s/$before_payload_position/$after_payload_position/g" "$agent" sed -i -e "s/$before_prelude_position/$after_prelude_position/g" "$agent" + fi ''; }; "22407" = { diff --git a/pkgs/applications/editors/jetbrains/plugins/tests.nix b/pkgs/applications/editors/jetbrains/plugins/tests.nix index bb182e599cac..8ebfc4194fc2 100644 --- a/pkgs/applications/editors/jetbrains/plugins/tests.nix +++ b/pkgs/applications/editors/jetbrains/plugins/tests.nix @@ -11,7 +11,6 @@ let # Known broken plugins, PLEASE remove entries here whenever possible. broken-plugins = [ - "github-copilot" # GitHub Copilot: https://github.com/NixOS/nixpkgs/issues/400317 ]; ides =