16 buildNpmPackage' = buildNpmPackage.override { inherit nodejs; };
20 src = fetchFromGitHub {
21 owner = "httptoolkit";
22 repo = "httptoolkit-server";
23 rev = "refs/tags/v${version}";
24 hash = "sha256-S4Io4X5Hlvm/5HoKIQ/OTor9jZvMz6me5RyfZ8FwOdM=";
27 overridesNodeModules = buildNpmPackage' {
28 pname = "httptoolkit-server-overrides-node-modules";
30 sourceRoot = "${src.name}/overrides/js";
32 npmDepsHash = "sha256-GRN6ua3FY1AE61bB7PM2wgbKPZI/zJeXa5HOOh/2N2Y=";
38 cp -r node_modules $out/node_modules
42 nodeDatachannel = buildNpmPackage' {
43 pname = "node-datachannel";
46 src = fetchFromGitHub {
47 owner = "murat-dogan";
48 repo = "node-datachannel";
49 rev = "refs/tags/v${nodeDatachannel.version}";
50 hash = "sha256-BlfeocqSG+pqbK0onnCf0VKbQw8Qq4qMxhAcfGlFYR8=";
53 npmFlags = [ "--ignore-scripts" ];
55 makeCacheWritable = true;
57 npmDepsHash = "sha256-pgcOOjiuWKlpD+WJyPj/c9ZhDjYuEnybpLS/BPmzeFM=";
69 dontUseCmakeConfigure = true;
71 env.NIX_CFLAGS_COMPILE = "-I${nodejs}/include/node";
72 env.CXXFLAGS = "-include stdexcept"; # for GCC13
75 # don't use static libs and don't use FetchContent
76 substituteInPlace CMakeLists.txt \
77 --replace-fail 'OPENSSL_USE_STATIC_LIBS TRUE' 'OPENSSL_USE_STATIC_LIBS FALSE' \
78 --replace-fail 'if(NOT libdatachannel)' 'if(false)' \
79 --replace-fail 'datachannel-static' 'datachannel'
81 # don't fetch node headers
82 substituteInPlace node_modules/cmake-js/lib/dist.js \
83 --replace-fail '!this.downloaded' 'false'
90 install -Dm755 build/Release/*.node -t $out/build/Release
96 pname = "httptoolkit-server";
99 patches = [ ./only-build-for-one-platform.patch ];
101 npmDepsHash = "sha256-njSNdpo+CIfS9LTnshawJ7297tFc8ssjUqJcHk8kBZE=";
103 npmFlags = [ "--ignore-scripts" ];
105 makeCacheWritable = true;
107 nativeBuildInputs = [
108 # the build system uses the `git` executable to get the current revision
109 # we use a fake git to provide it with a fake revision
110 (writeShellScriptBin "git" "echo '???'")
114 # make sure `oclif-dev' doesn't fetch `node` binary to bundle with the app
115 substituteInPlace node_modules/@oclif/dev-cli/lib/tarballs/node.js --replace-fail \
116 'async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) {' \
117 'async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) { return;'
119 # manually place our prebuilt `node-datachannel` binary into its place, since we used '--ignore-scripts'
120 ln -s ${nodeDatachannel}/build node_modules/node-datachannel/build
122 cp -r ${overridesNodeModules}/node_modules overrides/js/node_modules
124 # don't run `npm ci` in `overrides/js` since we already copied node_modules into the directory
125 substituteInPlace prepare.ts --replace-fail "'ci', '--production'" "'--version'"
134 npmBuildScript = "build:release";
139 # we don't actually use any of the generated tarballs, we just copy from the tmp directory, since that's easier
140 mkdir -p $out/share/httptoolkit-server
141 cp -r build/tmp/httptoolkit-server/* -r $out/share/httptoolkit-server
143 # remove unneeded executables
144 rm -r $out/share/httptoolkit-server/bin/httptoolkit-server*
146 # since `oclif-dev pack` ran `npm install` again, we need to place the prebuilt binary here again
147 ln -s ${nodeDatachannel}/build $out/share/httptoolkit-server/node_modules/node-datachannel/build
149 # disable updating functionality
150 substituteInPlace $out/share/httptoolkit-server/node_modules/@oclif/plugin-update/lib/commands/update.js \
151 --replace-fail "await this.skipUpdate()" "'cannot update nix based package'"
153 # the app determines if it's in production by checking if HTTPTOOLKIT_SERVER_BINPATH is set to anything
154 makeWrapper $out/share/httptoolkit-server/bin/run $out/bin/httptoolkit-server \
155 --set HTTPTOOLKIT_SERVER_BINPATH dummy \
156 --prefix PATH : ${lib.makeBinPath [ nss.tools ]}
162 inherit nodeDatachannel;
166 description = "Backend for HTTP Toolkit";
167 homepage = "https://httptoolkit.com/";
168 license = lib.licenses.agpl3Plus;
169 mainProgram = "httptoolkit-server";
170 maintainers = with lib.maintainers; [ tomasajt ];
171 platforms = lib.platforms.unix;