tangled
alpha
login
or
join now
tjh.dev
/
nixpkgs
0
fork
atom
nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
0
fork
atom
overview
issues
pulls
pipelines
httptoolkit-server: init at 1.19.0
TomaSajt
2 years ago
457e4096
0c4c9798
+212
2 changed files
expand all
collapse all
unified
split
pkgs
by-name
ht
httptoolkit-server
only-build-for-one-platform.patch
package.nix
+39
pkgs/by-name/ht/httptoolkit-server/only-build-for-one-platform.patch
reviewed
···
1
1
+
diff --git a/pack.ts b/pack.ts
2
2
+
index aba98cc..03ce86a 100644
3
3
+
--- a/pack.ts
4
4
+
+++ b/pack.ts
5
5
+
@@ -75,33 +75,7 @@ const packageApp = async () => {
6
6
+
delete pJson.scripts.prepack; // We don't want to rebuild - all built code will be in the packed content
7
7
+
await fs.writeJson(path.join(OUTPUT_DIR, 'package.json'), pJson);
8
8
+
9
9
+
- const buildScript = path.join(OUTPUT_DIR, 'build-release.sh');
10
10
+
-
11
11
+
- // Run build-release in this folder, for each platform. For each bundle, we copy in
12
12
+
- // only the relevant platform-specific NSS files.
13
13
+
- console.log('Building for Linux');
14
14
+
- await fs.mkdir(path.join(OUTPUT_DIR, 'nss'));
15
15
+
- await fs.copy(path.join(__dirname, 'nss', 'linux'), path.join(OUTPUT_DIR, 'nss', 'linux'));
16
16
+
- await spawn(buildScript, ['linux'], { cwd: OUTPUT_DIR, stdio: 'inherit' });
17
17
+
-
18
18
+
- console.log('Building for Darwin');
19
19
+
- await fs.remove(path.join(OUTPUT_DIR, 'nss', 'linux'));
20
20
+
- await fs.copy(path.join(__dirname, 'nss', 'darwin'), path.join(OUTPUT_DIR, 'nss', 'darwin'));
21
21
+
- await spawn(buildScript, ['darwin'], { cwd: OUTPUT_DIR, stdio: 'inherit' });
22
22
+
-
23
23
+
- console.log('Building for Win32');
24
24
+
- await fs.remove(path.join(OUTPUT_DIR, 'nss', 'darwin'));
25
25
+
- await fs.copy(path.join(__dirname, 'nss', 'win32'), path.join(OUTPUT_DIR, 'nss', 'win32'));
26
26
+
- await spawn(buildScript, ['win32'], { cwd: OUTPUT_DIR, stdio: 'inherit' });
27
27
+
-
28
28
+
- // Oclif builds a nodeless platform-agnostic bundle too (although in our case, nothing is
29
29
+
- // really platform agnostic). Not necessary, probably won't work - drop it.
30
30
+
- await fs.remove(path.join(
31
31
+
- OUTPUT_DIR,
32
32
+
- 'dist',
33
33
+
- `v${pJson.version}`,
34
34
+
- `httptoolkit-server-v${pJson.version}.tar.gz`
35
35
+
- ));
36
36
+
+ await spawn('npm', ['exec', '--', 'oclif-dev', 'pack', '--targets=linux-x64'], { cwd: OUTPUT_DIR, stdio: 'inherit' });
37
37
+
}
38
38
+
39
39
+
packageApp().catch(e => {
+173
pkgs/by-name/ht/httptoolkit-server/package.nix
reviewed
···
1
1
+
{
2
2
+
lib,
3
3
+
nodejs_20,
4
4
+
buildNpmPackage,
5
5
+
fetchFromGitHub,
6
6
+
writeShellScriptBin,
7
7
+
nss,
8
8
+
cmake,
9
9
+
pkg-config,
10
10
+
openssl,
11
11
+
libdatachannel,
12
12
+
}:
13
13
+
14
14
+
let
15
15
+
nodejs = nodejs_20;
16
16
+
buildNpmPackage' = buildNpmPackage.override { inherit nodejs; };
17
17
+
18
18
+
version = "1.19.0";
19
19
+
20
20
+
src = fetchFromGitHub {
21
21
+
owner = "httptoolkit";
22
22
+
repo = "httptoolkit-server";
23
23
+
rev = "refs/tags/v${version}";
24
24
+
hash = "sha256-S4Io4X5Hlvm/5HoKIQ/OTor9jZvMz6me5RyfZ8FwOdM=";
25
25
+
};
26
26
+
27
27
+
overridesNodeModules = buildNpmPackage' {
28
28
+
pname = "httptoolkit-server-overrides-node-modules";
29
29
+
inherit version src;
30
30
+
sourceRoot = "${src.name}/overrides/js";
31
31
+
32
32
+
npmDepsHash = "sha256-GRN6ua3FY1AE61bB7PM2wgbKPZI/zJeXa5HOOh/2N2Y=";
33
33
+
34
34
+
dontBuild = true;
35
35
+
36
36
+
installPhase = ''
37
37
+
mkdir -p $out
38
38
+
cp -r node_modules $out/node_modules
39
39
+
'';
40
40
+
};
41
41
+
42
42
+
nodeDatachannel = buildNpmPackage' {
43
43
+
pname = "node-datachannel";
44
44
+
version = "0.4.3";
45
45
+
46
46
+
src = fetchFromGitHub {
47
47
+
owner = "murat-dogan";
48
48
+
repo = "node-datachannel";
49
49
+
rev = "refs/tags/v${nodeDatachannel.version}";
50
50
+
hash = "sha256-BlfeocqSG+pqbK0onnCf0VKbQw8Qq4qMxhAcfGlFYR8=";
51
51
+
};
52
52
+
53
53
+
npmFlags = [ "--ignore-scripts" ];
54
54
+
55
55
+
makeCacheWritable = true;
56
56
+
57
57
+
npmDepsHash = "sha256-pgcOOjiuWKlpD+WJyPj/c9ZhDjYuEnybpLS/BPmzeFM=";
58
58
+
59
59
+
nativeBuildInputs = [
60
60
+
cmake
61
61
+
pkg-config
62
62
+
];
63
63
+
64
64
+
buildInputs = [
65
65
+
openssl
66
66
+
libdatachannel
67
67
+
];
68
68
+
69
69
+
dontUseCmakeConfigure = true;
70
70
+
71
71
+
env.NIX_CFLAGS_COMPILE = "-I${nodejs}/include/node";
72
72
+
env.CXXFLAGS = "-include stdexcept"; # for GCC13
73
73
+
74
74
+
preBuild = ''
75
75
+
# don't use static libs and don't use FetchContent
76
76
+
substituteInPlace CMakeLists.txt \
77
77
+
--replace-fail 'OPENSSL_USE_STATIC_LIBS TRUE' 'OPENSSL_USE_STATIC_LIBS FALSE' \
78
78
+
--replace-fail 'if(NOT libdatachannel)' 'if(false)' \
79
79
+
--replace-fail 'datachannel-static' 'datachannel'
80
80
+
81
81
+
# don't fetch node headers
82
82
+
substituteInPlace node_modules/cmake-js/lib/dist.js \
83
83
+
--replace-fail '!this.downloaded' 'false'
84
84
+
85
85
+
npm rebuild --verbose
86
86
+
'';
87
87
+
88
88
+
installPhase = ''
89
89
+
runHook preInstall
90
90
+
install -Dm755 build/Release/*.node -t $out/build/Release
91
91
+
runHook postInstall
92
92
+
'';
93
93
+
};
94
94
+
in
95
95
+
buildNpmPackage' {
96
96
+
pname = "httptoolkit-server";
97
97
+
inherit version src;
98
98
+
99
99
+
patches = [ ./only-build-for-one-platform.patch ];
100
100
+
101
101
+
npmDepsHash = "sha256-njSNdpo+CIfS9LTnshawJ7297tFc8ssjUqJcHk8kBZE=";
102
102
+
103
103
+
npmFlags = [ "--ignore-scripts" ];
104
104
+
105
105
+
makeCacheWritable = true;
106
106
+
107
107
+
nativeBuildInputs = [
108
108
+
# the build system uses the `git` executable to get the current revision
109
109
+
# we use a fake git to provide it with a fake revision
110
110
+
(writeShellScriptBin "git" "echo '???'")
111
111
+
];
112
112
+
113
113
+
postConfigure = ''
114
114
+
# make sure `oclif-dev' doesn't fetch `node` binary to bundle with the app
115
115
+
substituteInPlace node_modules/@oclif/dev-cli/lib/tarballs/node.js --replace-fail \
116
116
+
'async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) {' \
117
117
+
'async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) { return;'
118
118
+
119
119
+
# manually place our prebuilt `node-datachannel` binary into its place, since we used '--ignore-scripts'
120
120
+
ln -s ${nodeDatachannel}/build node_modules/node-datachannel/build
121
121
+
122
122
+
cp -r ${overridesNodeModules}/node_modules overrides/js/node_modules
123
123
+
124
124
+
# don't run `npm ci` in `overrides/js` since we already copied node_modules into the directory
125
125
+
substituteInPlace prepare.ts --replace-fail "'ci', '--production'" "'--version'"
126
126
+
127
127
+
patchShebangs *.sh
128
128
+
'';
129
129
+
130
130
+
preBuild = ''
131
131
+
npm run build:src
132
132
+
'';
133
133
+
134
134
+
npmBuildScript = "build:release";
135
135
+
136
136
+
installPhase = ''
137
137
+
runHook preInstall
138
138
+
139
139
+
# we don't actually use any of the generated tarballs, we just copy from the tmp directory, since that's easier
140
140
+
mkdir -p $out/share/httptoolkit-server
141
141
+
cp -r build/tmp/httptoolkit-server/* -r $out/share/httptoolkit-server
142
142
+
143
143
+
# remove unneeded executables
144
144
+
rm -r $out/share/httptoolkit-server/bin/httptoolkit-server*
145
145
+
146
146
+
# since `oclif-dev pack` ran `npm install` again, we need to place the prebuilt binary here again
147
147
+
ln -s ${nodeDatachannel}/build $out/share/httptoolkit-server/node_modules/node-datachannel/build
148
148
+
149
149
+
# disable updating functionality
150
150
+
substituteInPlace $out/share/httptoolkit-server/node_modules/@oclif/plugin-update/lib/commands/update.js \
151
151
+
--replace-fail "await this.skipUpdate()" "'cannot update nix based package'"
152
152
+
153
153
+
# the app determines if it's in production by checking if HTTPTOOLKIT_SERVER_BINPATH is set to anything
154
154
+
makeWrapper $out/share/httptoolkit-server/bin/run $out/bin/httptoolkit-server \
155
155
+
--set HTTPTOOLKIT_SERVER_BINPATH dummy \
156
156
+
--prefix PATH : ${lib.makeBinPath [ nss.tools ]}
157
157
+
158
158
+
runHook postInstall
159
159
+
'';
160
160
+
161
161
+
passthru = {
162
162
+
inherit nodeDatachannel;
163
163
+
};
164
164
+
165
165
+
meta = {
166
166
+
description = "Backend for HTTP Toolkit";
167
167
+
homepage = "https://httptoolkit.com/";
168
168
+
license = lib.licenses.agpl3Plus;
169
169
+
mainProgram = "httptoolkit-server";
170
170
+
maintainers = with lib.maintainers; [ tomasajt ];
171
171
+
platforms = lib.platforms.unix;
172
172
+
};
173
173
+
}