1{
2 lib,
3 stdenv,
4 buildPackages,
5 copyDesktopItems,
6 fetchzip,
7 makeDesktopItem,
8 makeWrapper,
9 adwaita-icon-theme,
10 alsa-lib,
11 at-spi2-atk,
12 at-spi2-core,
13 atk,
14 cacert,
15 cairo,
16 cups,
17 curlWithGnuTls,
18 dbus,
19 e2fsprogs,
20 expat,
21 fontconfig,
22 freetype,
23 gdk-pixbuf,
24 git,
25 glib,
26 gtk3,
27 krb5,
28 libGL,
29 libX11,
30 libXScrnSaver,
31 libXcomposite,
32 libXcursor,
33 libXdamage,
34 libXext,
35 libXfixes,
36 libXi,
37 libXrandr,
38 libXrender,
39 libXtst,
40 libdrm,
41 libgbm,
42 libgnome-keyring,
43 libuuid,
44 libxcb,
45 libxkbcommon,
46 libxkbfile,
47 libxshmfence,
48 nspr,
49 nss,
50 openssl,
51 pango,
52 udev,
53 unzip,
54 zlib,
55}:
56
57let
58 pname = "gitkraken";
59 version = "11.2.1";
60
61 throwSystem = throw "Unsupported system: ${stdenv.hostPlatform.system}";
62
63 srcs = {
64 x86_64-linux = fetchzip {
65 url = "https://api.gitkraken.dev/releases/production/linux/x64/${version}/gitkraken-amd64.tar.gz";
66 hash = "sha256-nxYWcw8A/lIVyjiUJOmcjmTblbxiLSxMUjo7KnlAMzs=";
67 };
68
69 x86_64-darwin = fetchzip {
70 url = "https://api.gitkraken.dev/releases/production/darwin/x64/${version}/GitKraken-v${version}.zip";
71 hash = "sha256-7I3yAEarGGhFs/PvcqvoDx8MbJ/zEuNN/s0o357M1vc=";
72 };
73
74 aarch64-darwin = fetchzip {
75 url = "https://api.gitkraken.dev/releases/production/darwin/arm64/${version}/GitKraken-v${version}.zip";
76 hash = "sha256-pDPdi+cRMqhxu/84u6ojxteIi1VHfN3qy/NTruHVt8U=";
77 };
78 };
79
80 src = srcs.${stdenv.hostPlatform.system} or throwSystem;
81
82 meta = {
83 homepage = "https://www.gitkraken.com/git-client";
84 description = "Simplifying Git for any OS";
85 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
86 license = lib.licenses.unfree;
87 platforms = builtins.attrNames srcs;
88 maintainers = with lib.maintainers; [
89 nicolas-goudry
90 Rishik-Y
91 ];
92 mainProgram = "gitkraken";
93 };
94
95 passthru.updateScript = ./update.sh;
96
97 linux = stdenv.mkDerivation rec {
98 inherit
99 pname
100 version
101 src
102 meta
103 passthru
104 ;
105
106 dontBuild = true;
107 dontConfigure = true;
108
109 libPath = lib.makeLibraryPath [
110 stdenv.cc.cc
111 curlWithGnuTls
112 udev
113 libX11
114 libXext
115 libXcursor
116 libXi
117 libxcb
118 glib
119 libXScrnSaver
120 libxkbfile
121 libXtst
122 nss
123 nspr
124 cups
125 alsa-lib
126 expat
127 gdk-pixbuf
128 dbus
129 libXdamage
130 libXrandr
131 atk
132 pango
133 cairo
134 freetype
135 fontconfig
136 libXcomposite
137 libXfixes
138 libXrender
139 gtk3
140 libgnome-keyring
141 openssl
142 at-spi2-atk
143 at-spi2-core
144 libuuid
145 e2fsprogs
146 krb5
147 libdrm
148 libgbm
149 libxshmfence
150 libxkbcommon
151 libGL
152 zlib
153 ];
154
155 desktopItems = [
156 (makeDesktopItem {
157 name = "GitKraken Desktop";
158 exec = "gitkraken";
159 icon = "gitkraken";
160 desktopName = "GitKraken Desktop";
161 genericName = "Git Client";
162 categories = [ "Development" ];
163 comment = "Unleash your repo";
164 })
165 ];
166
167 nativeBuildInputs = [
168 copyDesktopItems
169 # override doesn't preserve splicing https://github.com/NixOS/nixpkgs/issues/132651
170 # Has to use `makeShellWrapper` from `buildPackages` even though `makeShellWrapper` from the inputs is spliced because `propagatedBuildInputs` would pick the wrong one because of a different offset.
171 (buildPackages.wrapGAppsHook3.override { makeWrapper = buildPackages.makeShellWrapper; })
172 ];
173 buildInputs = [
174 gtk3
175 adwaita-icon-theme
176 ];
177
178 # avoid double-wrapping
179 dontWrapGApps = true;
180
181 installPhase = ''
182 runHook preInstall
183
184 mkdir -p $out/share/${pname}/
185 cp -R $src/* $out/share/${pname}
186
187 mkdir -p $out/share/pixmaps
188 cp gitkraken.png $out/share/pixmaps/
189
190 runHook postInstall
191 '';
192
193 preFixup = ''
194 gappsWrapperArgs+=(--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}")
195 '';
196
197 postFixup = ''
198 pushd $out/share/${pname}
199 for file in gitkraken chrome-sandbox chrome_crashpad_handler; do
200 patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $file
201 done
202
203 for file in $(find . -type f \( -name \*.node -o -name gitkraken -o -name git -o -name git-\* -o -name scalar -o -name \*.so\* \) ); do
204 patchelf --set-rpath ${libPath}:$out/share/${pname} $file || true
205 done
206 popd
207
208 # SSL and permissions fix for bundled nodegit
209 pushd $out/share/${pname}/resources/app.asar.unpacked/node_modules/@axosoft/nodegit/build/Release
210 mv nodegit-ubuntu-18.node nodegit-ubuntu-18-ssl-1.1.1.node
211 mv nodegit-ubuntu-18-ssl-static.node nodegit-ubuntu-18.node
212 chmod 755 nodegit-ubuntu-18.node
213 popd
214
215 # Devendor bundled git
216 rm -rf $out/share/${pname}/resources/app.asar.unpacked/git
217 ln -s ${git} $out/share/${pname}/resources/app.asar.unpacked/git
218
219 # GitKraken expects the CA bundle to be located in the bundled git directory. Since we replace it with
220 # the one from nixpkgs, which doesn't provide a CA bundle, we need to explicitly set its location at runtime
221 makeWrapper $out/share/${pname}/gitkraken $out/bin/gitkraken \
222 --set GIT_SSL_CAINFO "${cacert}/etc/ssl/certs/ca-bundle.crt" \
223 "''${gappsWrapperArgs[@]}"
224 '';
225 };
226
227 darwin = stdenv.mkDerivation {
228 inherit
229 pname
230 version
231 src
232 meta
233 passthru
234 ;
235
236 nativeBuildInputs = [
237 unzip
238 makeWrapper
239 ];
240
241 installPhase = ''
242 runHook preInstall
243
244 mkdir -p $out/Applications/GitKraken.app $out/bin
245 cp -R . $out/Applications/GitKraken.app
246
247 makeWrapper $out/Applications/GitKraken.app/Contents/MacOS/GitKraken $out/bin/gitkraken
248
249 runHook postInstall
250 '';
251
252 dontFixup = true;
253 };
254in
255if stdenv.hostPlatform.isDarwin then darwin else linux