1{
2 lib,
3 stdenv,
4 buildNpmPackage,
5 fetchFromGitHub,
6 makeWrapper,
7 makeDesktopItem,
8 copyDesktopItems,
9 electron_37,
10 httptoolkit-server,
11}:
12
13let
14 electron = electron_37;
15in
16buildNpmPackage rec {
17 pname = "httptoolkit";
18 version = "1.22.1";
19
20 src = fetchFromGitHub {
21 owner = "httptoolkit";
22 repo = "httptoolkit-desktop";
23 tag = "v${version}";
24 hash = "sha256-6iiXOBVtPLdW9MWUcu2Hggm7uPHudASebRPQ34JJTMQ=";
25 };
26
27 patches = [
28 # generated via running: `npm update node-abi`
29 ./bump-node-abi.patch
30 ];
31
32 npmDepsHash = "sha256-WtnL9Gf1zGWnIjMifh0l3fwaeur+iI1l/Vwta+X6EAM=";
33
34 makeCacheWritable = true;
35
36 env = {
37 ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
38 # disable code signing on Darwin
39 CSC_IDENTITY_AUTO_DISCOVERY = "false";
40 };
41
42 nativeBuildInputs = [
43 makeWrapper
44 ]
45 ++ lib.optionals stdenv.hostPlatform.isLinux [ copyDesktopItems ];
46
47 npmBuildScript = "build:src";
48
49 postBuild = ''
50 substituteInPlace package.json --replace-fail \
51 '"forceCodeSigning": true' \
52 '"forceCodeSigning": false'
53
54 cp -rL ${electron.dist} electron-dist
55 chmod -R u+w electron-dist
56
57 npm exec electron-builder -- \
58 --dir \
59 -c.electronDist=electron-dist \
60 -c.electronVersion=${electron.version}
61 '';
62
63 installPhase = ''
64 runHook preInstall
65
66 ${lib.optionalString stdenv.hostPlatform.isLinux ''
67 mkdir -p $out/share/httptoolkit
68 cp -r dist/*-unpacked/{locales,resources{,.pak}} $out/share/httptoolkit
69
70 ln -s ${httptoolkit-server} $out/share/httptoolkit/resources/httptoolkit-server
71
72 install -Dm644 src/icons/icon.svg $out/share/icons/hicolor/scalable/apps/httptoolkit.svg
73
74 makeWrapper ${lib.getExe electron} $out/bin/httptoolkit \
75 --add-flags $out/share/httptoolkit/resources/app.asar \
76 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \
77 --inherit-argv0
78 ''}
79
80 ${lib.optionalString stdenv.hostPlatform.isDarwin ''
81 mkdir -p $out/Applications
82 cp -r dist/mac*/"HTTP Toolkit.app" $out/Applications
83
84 ln -s ${httptoolkit-server} "$out/Applications/HTTP Toolkit.app/Contents/Resources/httptoolkit-server"
85
86 makeWrapper "$out/Applications/HTTP Toolkit.app/Contents/MacOS/HTTP Toolkit" $out/bin/httptoolkit
87 ''}
88
89 runHook postInstall
90 '';
91
92 desktopItems = [
93 (makeDesktopItem {
94 name = "httptoolkit";
95 desktopName = "HTTP Toolkit";
96 exec = "httptoolkit %U";
97 terminal = false;
98 icon = "httptoolkit";
99 startupWMClass = "HTTP Toolkit";
100 comment = meta.description;
101 categories = [ "Development" ];
102 startupNotify = true;
103 })
104 ];
105
106 meta = {
107 description = "HTTP(S) debugging, development & testing tool";
108 homepage = "https://httptoolkit.com/";
109 license = lib.licenses.agpl3Plus;
110 mainProgram = "httptoolkit";
111 maintainers = with lib.maintainers; [ tomasajt ];
112 platforms = electron.meta.platforms;
113 };
114}