-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintellij.nix
113 lines (108 loc) · 4.38 KB
/
intellij.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{ stdenv, config, lib, pkgs, custompkgs, ... }:
let
cfg = config.custom.intellij;
in {
options.custom.intellij = {
enable = lib.mkOption {
default = false;
example = true;
};
};
config = lib.mkIf cfg.enable {
home-manager.users.${config.custom.user} = let
overrideWithGApps = (pkg: pkg.overrideAttrs (oldAttrs: {nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.wrapGAppsHook ];}));
devSDKs = with pkgs; {
rustc = symlinkJoin { name = rustc.pname; paths = [ rustc cargo gcc ]; };
rust-src = rust.packages.stable.rustPlatform.rustLibSrc;
java11 = jdk11;
java17 = jdk17;
ruby_3_0 = ruby_3_0;
ruby_3_1 = ruby_3_1;
openjfx = openjfx;
scenebuilder = scenebuilder;
python = python3;
node = nodejs;
yarn = yarn;
vuecli = nodePackages."@vue/cli";
c = clang_14;
make = gnumake;
valgrind = valgrind;
};
extraPath = lib.makeBinPath (builtins.attrValues devSDKs);
# Copilot
addCopilot = (editor:
with pkgs.jetbrains.plugins;
let
info = (getUrl { id = "17718"; hash = "sha256-lOAVJx+xxz4gBJ4Cchq+02ArdmwMWOuGh+afU6LavNQ="; });
libPath = lib.makeLibraryPath [pkgs.glibc pkgs.gcc-unwrapped];
copilot-plugin = (urlToDrv {
name = "GitHub Copilot";
url = info.url;
hash = "sha256-117CHiwMOlEoiZBRk7hT3INncargoeYCuewpCeQ4nz8=";
extra = {
inputs = [ pkgs.patchelf pkgs.glibc pkgs.gcc-unwrapped ];
commands = ''
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
'';
};
});
in addPlugins editor [ copilot-plugin ]);
idea-with-copilot = addCopilot pkgs.jetbrains.idea-ultimate;
clion-with-copilot = addCopilot pkgs.jetbrains.clion;
intellij = pkgs.runCommand "intellij"
{ nativeBuildInputs = [ pkgs.makeWrapper ]; }
''
mkdir -p $out/bin
makeWrapper ${idea-with-copilot}/bin/idea-ultimate \
$out/bin/intellij \
--prefix PATH : ${extraPath}
'';
clion = pkgs.runCommand "clion"
{ nativeBuildInputs = [ pkgs.makeWrapper ]; }
''
mkdir -p $out/bin
makeWrapper ${clion-with-copilot}/bin/clion \
$out/bin/clion \
--set NIX_CC ${devSDKs.c}/bin/cc \
--prefix PATH : ${extraPath}
'';
in { ... }: {
home.packages = [ intellij clion ];
home.file.".local/dev".source = let
mkEntry = name: value: { inherit name; path = value; };
entries = lib.mapAttrsToList mkEntry devSDKs;
in pkgs.linkFarm "local-dev" entries;
};
};
}