Skip to content

Commit

Permalink
feat: add copilot plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ktor committed Oct 7, 2022
1 parent 4d37978 commit 35f4071
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions overlays/idea/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
final: prev: {
jetbrains = prev.jetbrains // {
# Get info from site...
copilot-plugin-info = final.jetbrains.plugins.getUrl {
id = "17718";
hash = "sha256-Cjt/FMLVKR9RGmnM4pZLxgTuw+STbOkRO91HIEoacZ0=";
};
# Actually build the plugin
copilot-plugin = final.jetbrains.plugins.urlToDrv (final.jetbrains.copilot-plugin-info // {
hash = "sha256-XuQWI+kbck1BqnTvMfK6o85u9spksBkPhfcmFzs4VvI=";
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
'';
};
});
jdk = prev.jetbrains.jdk.overrideAttrs (oldAttrs: rec {
version = "17.0.4.1-linux-x64-b629.2";
src = prev.fetchurl {
Expand Down Expand Up @@ -76,6 +124,7 @@ final: prev: {
url = "https://download.jetbrains.com/idea/ideaIU-${version}-no-jbr.tar.gz";
sha256 = "dFTX4Lj049jYBd3mRdKLhCEBvXeuqLKRJYgMWS5rjIU=";
};
plugins = [final.jetbrains.copilot-plugin];
});
};
}

0 comments on commit 35f4071

Please sign in to comment.