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