nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 fetchurl,
4 stdenv,
5 testers,
6 texinfo,
7}:
8
9stdenv.mkDerivation (finalAttrs: {
10 pname = "quickjs";
11 version = "2025-09-13-2";
12
13 src = fetchurl {
14 url = "https://bellard.org/quickjs/quickjs-${finalAttrs.version}.tar.xz";
15 hash = "sha256-mWxrUBj8lVrU0GQm0OnLcTaFoAyCWqXAQYvVP334sLQ=";
16 };
17
18 outputs = [
19 "out"
20 "info"
21 ];
22
23 nativeBuildInputs = [
24 texinfo
25 ];
26
27 makeFlags = [
28 "CC=${stdenv.cc.targetPrefix}cc"
29 "AR=${stdenv.cc.targetPrefix}ar"
30 "PREFIX=$(out)"
31 ];
32
33 doInstallCheck = true;
34
35 enableParallelBuilding = true;
36
37 strictDeps = true;
38
39 postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
40 substituteInPlace Makefile \
41 --replace "CONFIG_LTO=y" ""
42 '';
43
44 postBuild = ''
45 make doc/version.texi
46 pushd doc
47 makeinfo *texi
48 popd
49 '';
50
51 postInstall = ''
52 pushd doc
53 install -Dm644 -t ''${!outputInfo}/share/info *info
54 popd
55 '';
56
57 installCheckPhase = lib.concatStringsSep "\n" [
58 ''
59 runHook preInstallCheck
60 ''
61
62 ''
63 PATH="$out/bin:$PATH"
64 ''
65 # Programs exit with code 1 when testing help, so grep for a string
66 ''
67 set +o pipefail
68 qjs --help 2>&1 | grep "QuickJS version"
69 set -o pipefail
70 ''
71
72 ''
73 temp=$(mktemp).js
74 echo "console.log('Output from compiled program');" > "$temp"
75 set -o verbose
76 out=$(mktemp) && qjsc -o "$out" "$temp" && "$out" | grep -q "Output from compiled program"
77 out=$(mktemp) && qjsc -flto -o "$out" "$temp" && "$out" | grep -q "Output from compiled program"
78 ''
79
80 ''
81 runHook postInstallCheck
82 ''
83 ];
84
85 passthru.tests = {
86 version = testers.testVersion {
87 package = finalAttrs.finalPackage;
88 command = "qjs --help || true";
89 };
90 };
91
92 meta = {
93 homepage = "https://bellard.org/quickjs/";
94 description = "Small and embeddable Javascript engine";
95 longDescription = ''
96 QuickJS is a small and embeddable Javascript engine. It supports the
97 ES2023 specification including modules, asynchronous generators, proxies
98 and BigInt.
99
100 Main Features:
101
102 - Small and easily embeddable: just a few C files, no external
103 dependency, 210 KiB of x86 code for a simple hello world program.
104 - Fast interpreter with very low startup time: runs the 76000 tests of
105 the ECMAScript Test Suite in less than 2 minutes on a single core of a
106 desktop PC. The complete life cycle of a runtime instance completes in
107 less than 300 microseconds.
108 - Almost complete ES2023 support including modules, asynchronous
109 generators and full Annex B support (legacy web compatibility).
110 - Passes nearly 100% of the ECMAScript Test Suite tests when selecting
111 the ES2023 features. A summary is available at Test262 Report.
112 - Can compile Javascript sources to executables with no external dependency.
113 - Garbage collection using reference counting (to reduce memory usage and
114 have deterministic behavior) with cycle removal.
115 - Command line interpreter with contextual colorization implemented in
116 Javascript.
117 - Small built-in standard library with C library wrappers.
118
119 '';
120 license = lib.licenses.mit;
121 maintainers = [ ];
122 mainProgram = "qjs";
123 platforms = lib.platforms.all;
124 # Pending upstream fix: https://github.com/bellard/quickjs/pull/483
125 knownVulnerabilities = [
126 "CVE-2026-1144"
127 "CVE-2026-1145"
128 ];
129 };
130})