nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

httptoolkit-server: init at 1.19.0

TomaSajt 457e4096 0c4c9798

+212
+39
pkgs/by-name/ht/httptoolkit-server/only-build-for-one-platform.patch
··· 1 + diff --git a/pack.ts b/pack.ts 2 + index aba98cc..03ce86a 100644 3 + --- a/pack.ts 4 + +++ b/pack.ts 5 + @@ -75,33 +75,7 @@ const packageApp = async () => { 6 + delete pJson.scripts.prepack; // We don't want to rebuild - all built code will be in the packed content 7 + await fs.writeJson(path.join(OUTPUT_DIR, 'package.json'), pJson); 8 + 9 + - const buildScript = path.join(OUTPUT_DIR, 'build-release.sh'); 10 + - 11 + - // Run build-release in this folder, for each platform. For each bundle, we copy in 12 + - // only the relevant platform-specific NSS files. 13 + - console.log('Building for Linux'); 14 + - await fs.mkdir(path.join(OUTPUT_DIR, 'nss')); 15 + - await fs.copy(path.join(__dirname, 'nss', 'linux'), path.join(OUTPUT_DIR, 'nss', 'linux')); 16 + - await spawn(buildScript, ['linux'], { cwd: OUTPUT_DIR, stdio: 'inherit' }); 17 + - 18 + - console.log('Building for Darwin'); 19 + - await fs.remove(path.join(OUTPUT_DIR, 'nss', 'linux')); 20 + - await fs.copy(path.join(__dirname, 'nss', 'darwin'), path.join(OUTPUT_DIR, 'nss', 'darwin')); 21 + - await spawn(buildScript, ['darwin'], { cwd: OUTPUT_DIR, stdio: 'inherit' }); 22 + - 23 + - console.log('Building for Win32'); 24 + - await fs.remove(path.join(OUTPUT_DIR, 'nss', 'darwin')); 25 + - await fs.copy(path.join(__dirname, 'nss', 'win32'), path.join(OUTPUT_DIR, 'nss', 'win32')); 26 + - await spawn(buildScript, ['win32'], { cwd: OUTPUT_DIR, stdio: 'inherit' }); 27 + - 28 + - // Oclif builds a nodeless platform-agnostic bundle too (although in our case, nothing is 29 + - // really platform agnostic). Not necessary, probably won't work - drop it. 30 + - await fs.remove(path.join( 31 + - OUTPUT_DIR, 32 + - 'dist', 33 + - `v${pJson.version}`, 34 + - `httptoolkit-server-v${pJson.version}.tar.gz` 35 + - )); 36 + + await spawn('npm', ['exec', '--', 'oclif-dev', 'pack', '--targets=linux-x64'], { cwd: OUTPUT_DIR, stdio: 'inherit' }); 37 + } 38 + 39 + packageApp().catch(e => {
+173
pkgs/by-name/ht/httptoolkit-server/package.nix
··· 1 + { 2 + lib, 3 + nodejs_20, 4 + buildNpmPackage, 5 + fetchFromGitHub, 6 + writeShellScriptBin, 7 + nss, 8 + cmake, 9 + pkg-config, 10 + openssl, 11 + libdatachannel, 12 + }: 13 + 14 + let 15 + nodejs = nodejs_20; 16 + buildNpmPackage' = buildNpmPackage.override { inherit nodejs; }; 17 + 18 + version = "1.19.0"; 19 + 20 + src = fetchFromGitHub { 21 + owner = "httptoolkit"; 22 + repo = "httptoolkit-server"; 23 + rev = "refs/tags/v${version}"; 24 + hash = "sha256-S4Io4X5Hlvm/5HoKIQ/OTor9jZvMz6me5RyfZ8FwOdM="; 25 + }; 26 + 27 + overridesNodeModules = buildNpmPackage' { 28 + pname = "httptoolkit-server-overrides-node-modules"; 29 + inherit version src; 30 + sourceRoot = "${src.name}/overrides/js"; 31 + 32 + npmDepsHash = "sha256-GRN6ua3FY1AE61bB7PM2wgbKPZI/zJeXa5HOOh/2N2Y="; 33 + 34 + dontBuild = true; 35 + 36 + installPhase = '' 37 + mkdir -p $out 38 + cp -r node_modules $out/node_modules 39 + ''; 40 + }; 41 + 42 + nodeDatachannel = buildNpmPackage' { 43 + pname = "node-datachannel"; 44 + version = "0.4.3"; 45 + 46 + src = fetchFromGitHub { 47 + owner = "murat-dogan"; 48 + repo = "node-datachannel"; 49 + rev = "refs/tags/v${nodeDatachannel.version}"; 50 + hash = "sha256-BlfeocqSG+pqbK0onnCf0VKbQw8Qq4qMxhAcfGlFYR8="; 51 + }; 52 + 53 + npmFlags = [ "--ignore-scripts" ]; 54 + 55 + makeCacheWritable = true; 56 + 57 + npmDepsHash = "sha256-pgcOOjiuWKlpD+WJyPj/c9ZhDjYuEnybpLS/BPmzeFM="; 58 + 59 + nativeBuildInputs = [ 60 + cmake 61 + pkg-config 62 + ]; 63 + 64 + buildInputs = [ 65 + openssl 66 + libdatachannel 67 + ]; 68 + 69 + dontUseCmakeConfigure = true; 70 + 71 + env.NIX_CFLAGS_COMPILE = "-I${nodejs}/include/node"; 72 + env.CXXFLAGS = "-include stdexcept"; # for GCC13 73 + 74 + preBuild = '' 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' 80 + 81 + # don't fetch node headers 82 + substituteInPlace node_modules/cmake-js/lib/dist.js \ 83 + --replace-fail '!this.downloaded' 'false' 84 + 85 + npm rebuild --verbose 86 + ''; 87 + 88 + installPhase = '' 89 + runHook preInstall 90 + install -Dm755 build/Release/*.node -t $out/build/Release 91 + runHook postInstall 92 + ''; 93 + }; 94 + in 95 + buildNpmPackage' { 96 + pname = "httptoolkit-server"; 97 + inherit version src; 98 + 99 + patches = [ ./only-build-for-one-platform.patch ]; 100 + 101 + npmDepsHash = "sha256-njSNdpo+CIfS9LTnshawJ7297tFc8ssjUqJcHk8kBZE="; 102 + 103 + npmFlags = [ "--ignore-scripts" ]; 104 + 105 + makeCacheWritable = true; 106 + 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 '???'") 111 + ]; 112 + 113 + postConfigure = '' 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;' 118 + 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 121 + 122 + cp -r ${overridesNodeModules}/node_modules overrides/js/node_modules 123 + 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'" 126 + 127 + patchShebangs *.sh 128 + ''; 129 + 130 + preBuild = '' 131 + npm run build:src 132 + ''; 133 + 134 + npmBuildScript = "build:release"; 135 + 136 + installPhase = '' 137 + runHook preInstall 138 + 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 142 + 143 + # remove unneeded executables 144 + rm -r $out/share/httptoolkit-server/bin/httptoolkit-server* 145 + 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 148 + 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'" 152 + 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 ]} 157 + 158 + runHook postInstall 159 + ''; 160 + 161 + passthru = { 162 + inherit nodeDatachannel; 163 + }; 164 + 165 + meta = { 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; 172 + }; 173 + }