|
1 | | -{ fetchurl |
2 | | -, fetchzip |
3 | | -, lib |
4 | | -, stdenv |
5 | | -, callPackage |
6 | | -, autoPatchelfHook |
7 | | -, glib |
| 1 | +{ |
| 2 | + fetchurl, |
| 3 | + fetchzip, |
| 4 | + lib, |
| 5 | + stdenv, |
| 6 | + callPackage, |
| 7 | + autoPatchelfHook, |
| 8 | + glib, |
| 9 | + darwin, |
8 | 10 | }: |
9 | 11 |
|
10 | 12 | let |
11 | 13 | pluginsJson = builtins.fromJSON (builtins.readFile ./plugins.json); |
12 | 14 | specialPluginsInfo = callPackage ./specialPlugins.nix { }; |
13 | | - fetchPluginSrc = url: hash: |
| 15 | + fetchPluginSrc = |
| 16 | + url: hash: |
14 | 17 | let |
15 | 18 | isJar = lib.hasSuffix ".jar" url; |
16 | 19 | fetcher = if isJar then fetchurl else fetchzip; |
|
22 | 25 | files = builtins.mapAttrs (key: value: fetchPluginSrc key value) pluginsJson.files; |
23 | 26 | ids = builtins.attrNames pluginsJson.plugins; |
24 | 27 |
|
25 | | - mkPlugin = id: file: |
26 | | - if !specialPluginsInfo ? "${id}" |
27 | | - then files."${file}" |
| 28 | + mkPlugin = |
| 29 | + id: file: |
| 30 | + if !specialPluginsInfo ? "${id}" then |
| 31 | + files."${file}" |
28 | 32 | else |
29 | | - stdenv.mkDerivation ({ |
30 | | - name = "jetbrains-plugin-${id}"; |
31 | | - installPhase = '' |
32 | | - runHook preInstall |
33 | | - mkdir -p $out && cp -r . $out |
34 | | - runHook postInstall |
35 | | - ''; |
36 | | - src = files."${file}"; |
37 | | - } // specialPluginsInfo."${id}"); |
38 | | - |
39 | | - selectFile = id: ide: build: |
| 33 | + stdenv.mkDerivation ( |
| 34 | + { |
| 35 | + name = "jetbrains-plugin-${id}"; |
| 36 | + installPhase = '' |
| 37 | + runHook preInstall |
| 38 | + mkdir -p $out && cp -r . $out |
| 39 | + runHook postInstall |
| 40 | + ''; |
| 41 | + src = files."${file}"; |
| 42 | + } |
| 43 | + // specialPluginsInfo."${id}" |
| 44 | + ); |
| 45 | + |
| 46 | + selectFile = |
| 47 | + id: ide: build: |
40 | 48 | if !builtins.elem ide pluginsJson.plugins."${id}".compatible then |
41 | 49 | throw "Plugin with id ${id} does not support IDE ${ide}" |
42 | 50 | else if !pluginsJson.plugins."${id}".builds ? "${build}" then |
|
46 | 54 | else |
47 | 55 | pluginsJson.plugins."${id}".builds."${build}"; |
48 | 56 |
|
49 | | - byId = builtins.listToAttrs |
50 | | - (map |
51 | | - (id: { |
52 | | - name = id; |
53 | | - value = ide: build: mkPlugin id (selectFile id ide build); |
54 | | - }) |
55 | | - ids); |
56 | | - |
57 | | - byName = builtins.listToAttrs |
58 | | - (map |
59 | | - (id: { |
60 | | - name = pluginsJson.plugins."${id}".name; |
61 | | - value = byId."${id}"; |
62 | | - }) |
63 | | - ids); |
64 | | - |
65 | | - |
66 | | -in { |
| 57 | + byId = builtins.listToAttrs ( |
| 58 | + map (id: { |
| 59 | + name = id; |
| 60 | + value = ide: build: mkPlugin id (selectFile id ide build); |
| 61 | + }) ids |
| 62 | + ); |
| 63 | + |
| 64 | + byName = builtins.listToAttrs ( |
| 65 | + map (id: { |
| 66 | + name = pluginsJson.plugins."${id}".name; |
| 67 | + value = byId."${id}"; |
| 68 | + }) ids |
| 69 | + ); |
| 70 | +in |
| 71 | +{ |
67 | 72 | # Only use if you know what youre doing |
68 | 73 | raw = { inherit files byId byName; }; |
69 | 74 |
|
70 | | - tests = callPackage ./tests.nix {}; |
| 75 | + tests = callPackage ./tests.nix { }; |
71 | 76 |
|
72 | | - addPlugins = ide: unprocessedPlugins: |
| 77 | + addPlugins = |
| 78 | + ide: unprocessedPlugins: |
73 | 79 | let |
74 | | - |
75 | | - processPlugin = plugin: |
76 | | - if lib.isDerivation plugin then plugin else |
77 | | - if byId ? "${plugin}" then byId."${plugin}" ide.pname ide.buildNumber else |
78 | | - if byName ? "${plugin}" then byName."${plugin}" ide.pname ide.buildNumber else |
79 | | - throw "Could not resolve plugin ${plugin}"; |
| 80 | + processPlugin = |
| 81 | + plugin: |
| 82 | + if lib.isDerivation plugin then |
| 83 | + plugin |
| 84 | + else if byId ? "${plugin}" then |
| 85 | + byId."${plugin}" ide.pname ide.buildNumber |
| 86 | + else if byName ? "${plugin}" then |
| 87 | + byName."${plugin}" ide.pname ide.buildNumber |
| 88 | + else |
| 89 | + throw "Could not resolve plugin ${plugin}"; |
80 | 90 |
|
81 | 91 | plugins = map processPlugin unprocessedPlugins; |
82 | | - |
83 | 92 | in |
84 | 93 | stdenv.mkDerivation rec { |
85 | 94 | pname = meta.mainProgram + "-with-plugins"; |
86 | 95 | version = ide.version; |
87 | 96 | src = ide; |
88 | 97 | dontInstall = true; |
89 | | - dontFixup = true; |
| 98 | + dontStrip = true; |
90 | 99 | passthru.plugins = plugins ++ (ide.plugins or [ ]); |
91 | 100 | newPlugins = plugins; |
92 | 101 | disallowedReferences = [ ide ]; |
93 | | - nativeBuildInputs = (lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook) ++ (ide.nativeBuildInputs or [ ]); |
| 102 | + nativeBuildInputs = |
| 103 | + (lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook) |
| 104 | + # The buildPhase hook rewrites the binary, which invaliates the code |
| 105 | + # signature. Add the fixup hook to sign the output. |
| 106 | + ++ (lib.optional stdenv.hostPlatform.isDarwin darwin.autoSignDarwinBinariesHook) |
| 107 | + ++ (ide.nativeBuildInputs or [ ]); |
94 | 108 | buildInputs = lib.unique ((ide.buildInputs or [ ]) ++ [ glib ]); |
95 | 109 |
|
96 | 110 | inherit (ide) meta; |
97 | 111 |
|
98 | 112 | buildPhase = |
99 | | - let |
100 | | - rootDir = if stdenv.hostPlatform.isDarwin then "Applications/${ide.product}.app/Contents" else meta.mainProgram; |
101 | | - in |
102 | | - '' |
103 | | - cp -r ${ide} $out |
104 | | - chmod +w -R $out |
105 | | - rm -f $out/${rootDir}/plugins/plugin-classpath.txt |
106 | | - IFS=' ' read -ra pluginArray <<< "$newPlugins" |
107 | | - for plugin in "''${pluginArray[@]}" |
108 | | - do |
109 | | - pluginfiles=$(ls $plugin); |
110 | | - if [ $(echo $pluginfiles | wc -l) -eq 1 ] && echo $pluginfiles | grep -E "\.jar" 1> /dev/null; then |
111 | | - # if the plugin contains a single jar file, link it directly into the plugins folder |
112 | | - ln -s "$plugin/$(echo $pluginfiles | head -1)" $out/${rootDir}/plugins/ |
113 | | - else |
114 | | - # otherwise link the plugin directory itself |
115 | | - ln -s "$plugin" -t $out/${rootDir}/plugins/ |
116 | | - fi |
117 | | - done |
118 | | - sed "s|${ide.outPath}|$out|" \ |
119 | | - -i $(realpath $out/bin/${meta.mainProgram}) |
120 | | -
|
121 | | - if test -f "$out/bin/${meta.mainProgram}-remote-dev-server"; then |
122 | | - sed "s|${ide.outPath}|$out|" \ |
123 | | - -i $(realpath $out/bin/${meta.mainProgram}-remote-dev-server) |
124 | | - fi |
125 | | -
|
126 | | - '' + lib.optionalString stdenv.hostPlatform.isLinux '' |
127 | | - autoPatchelf $out |
128 | | - ''; |
| 113 | + let |
| 114 | + appDir = lib.optionalString stdenv.hostPlatform.isDarwin "Applications/${lib.escapeShellArg ide.product}.app"; |
| 115 | + rootDir = if stdenv.hostPlatform.isDarwin then "${appDir}/Contents" else meta.mainProgram; |
| 116 | + in |
| 117 | + '' |
| 118 | + cp -r ${ide} $out |
| 119 | + chmod +w -R $out |
| 120 | + rm -f $out/${rootDir}/plugins/plugin-classpath.txt |
| 121 | +
|
| 122 | + ( |
| 123 | + shopt -s nullglob |
| 124 | +
|
| 125 | + IFS=' ' read -ra pluginArray <<< "$newPlugins" |
| 126 | + for plugin in "''${pluginArray[@]}"; do |
| 127 | + pluginfiles=($plugin) |
| 128 | + if [[ "$plugin" == *.jar ]]; then |
| 129 | + # if the plugin contains a single jar file, link it directly into the plugins folder |
| 130 | + ln -s "$plugin" $out/${rootDir}/plugins/ |
| 131 | + else |
| 132 | + # otherwise link the plugin directory itself |
| 133 | + ln -s "$plugin" -t $out/${rootDir}/plugins/ |
| 134 | + fi |
| 135 | + done |
| 136 | +
|
| 137 | + for exe in $out/bin/${meta.mainProgram}*; do |
| 138 | + if [[ -x "$exe" ]]; then |
| 139 | + substituteInPlace $(realpath "$exe") --replace-warn '${ide.outPath}' $out |
| 140 | + fi |
| 141 | + done |
| 142 | + ) |
| 143 | + ''; |
129 | 144 | }; |
130 | 145 | } |
0 commit comments