nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildNpmPackage,
4 stdenv,
5 chromium,
6 ffmpeg,
7 jq,
8 nodejs,
9 fetchFromGitHub,
10 linkFarm,
11 callPackage,
12 makeFontsConf,
13 makeWrapper,
14 runCommand,
15 cacert,
16}:
17let
18 inherit (stdenv.hostPlatform) system;
19
20 throwSystem = throw "Unsupported system: ${system}";
21 suffix =
22 {
23 x86_64-linux = "linux";
24 aarch64-linux = "linux-arm64";
25 x86_64-darwin = "mac";
26 aarch64-darwin = "mac-arm64";
27 }
28 .${system} or throwSystem;
29
30 version = "1.57.0";
31
32 src = fetchFromGitHub {
33 owner = "Microsoft";
34 repo = "playwright";
35 rev = "v${version}";
36 hash = "sha256-1g8XCToVKWOjLpWS6g60FpoIphg9Rn/nv10oRa7oyDA=";
37 };
38
39 babel-bundle = buildNpmPackage {
40 pname = "babel-bundle";
41 inherit version src;
42 sourceRoot = "${src.name}/packages/playwright/bundles/babel";
43 npmDepsHash = "sha256-ByCy4go8PM0ksDg+2DcJPyoKG7Z0uIqKM647ZQwYwAE=";
44 dontNpmBuild = true;
45 installPhase = ''
46 cp -r . "$out"
47 '';
48 };
49 expect-bundle = buildNpmPackage {
50 pname = "expect-bundle";
51 inherit version src;
52 sourceRoot = "${src.name}/packages/playwright/bundles/expect";
53 npmDepsHash = "sha256-wXy6pkHJusB/WLgNKIPnuY4mTjntOMbrFrQp0UjrqAw=";
54 dontNpmBuild = true;
55 installPhase = ''
56 cp -r . "$out"
57 '';
58 };
59 utils-bundle = buildNpmPackage {
60 pname = "utils-bundle";
61 inherit version src;
62 sourceRoot = "${src.name}/packages/playwright/bundles/utils";
63 npmDepsHash = "sha256-InwWYRk6eRF62qI6qpVaPceIetSr3kPIBK4LdfeoJdo=";
64 dontNpmBuild = true;
65 installPhase = ''
66 cp -r . "$out"
67 '';
68 };
69 utils-bundle-core = buildNpmPackage {
70 pname = "utils-bundle-core";
71 inherit version src;
72 sourceRoot = "${src.name}/packages/playwright-core/bundles/utils";
73 npmDepsHash = "sha256-lOwcHRpv7OKfdnwqHxvh+Gy5AE/Up3Vro4czedNiOpc=";
74 dontNpmBuild = true;
75 installPhase = ''
76 cp -r . "$out"
77 '';
78 };
79 zip-bundle = buildNpmPackage {
80 pname = "zip-bundle";
81 inherit version src;
82 sourceRoot = "${src.name}/packages/playwright-core/bundles/zip";
83 npmDepsHash = "sha256-c0UZ0Jg86icwJp3xarpXpxWjRYeIjz9wpWtJZDHkd8U=";
84 dontNpmBuild = true;
85 installPhase = ''
86 cp -r . "$out"
87 '';
88 };
89
90 playwright = buildNpmPackage {
91 pname = "playwright";
92 inherit version src;
93
94 sourceRoot = "${src.name}"; # update.sh depends on sourceRoot presence
95 npmDepsHash = "sha256-69v+H3EQuJadma8b/l9rA/yMFCCb7wWiBGN/LoJLJM8=";
96
97 nativeBuildInputs = [
98 cacert
99 jq
100 ];
101
102 ELECTRON_SKIP_BINARY_DOWNLOAD = true;
103
104 postPatch = ''
105 sed -i '/\/\/ Update test runner./,/^\s*$/{d}' utils/build/build.js
106 sed -i '/^\/\/ Update bundles\./,/^[[:space:]]*}$/d' utils/build/build.js
107 sed -i '/execSync/d' ./utils/generate_third_party_notice.js
108 chmod +w packages/playwright/bundles/babel
109 ln -s ${babel-bundle}/node_modules packages/playwright/bundles/babel/node_modules
110 chmod +w packages/playwright/bundles/expect
111 ln -s ${expect-bundle}/node_modules packages/playwright/bundles/expect/node_modules
112 chmod +w packages/playwright/bundles/utils
113 ln -s ${utils-bundle}/node_modules packages/playwright/bundles/utils/node_modules
114 chmod +w packages/playwright-core/bundles/utils
115 ln -s ${utils-bundle-core}/node_modules packages/playwright-core/bundles/utils/node_modules
116 chmod +w packages/playwright-core/bundles/zip
117 ln -s ${zip-bundle}/node_modules packages/playwright-core/bundles/zip/node_modules
118 '';
119
120 installPhase = ''
121 runHook preInstall
122
123 shopt -s extglob
124
125 mkdir -p "$out/lib/node_modules/playwright"
126 cp -r packages/playwright/!(bundles|src|node_modules|.*) "$out/lib/node_modules/playwright"
127
128 # for not supported platforms (such as NixOS) playwright assumes that it runs on ubuntu-20.04
129 # that forces it to use overridden webkit revision
130 # let's remove that override to make it use latest revision provided in Nixpkgs
131 # https://github.com/microsoft/playwright/blob/baeb065e9ea84502f347129a0b896a85d2a8dada/packages/playwright-core/src/server/utils/hostPlatform.ts#L111
132 jq '(.browsers[] | select(.name == "webkit") | .revisionOverrides) |= del(."ubuntu20.04-x64", ."ubuntu20.04-arm64")' \
133 packages/playwright-core/browsers.json > browser.json.tmp && mv browser.json.tmp packages/playwright-core/browsers.json
134 mkdir -p "$out/lib/node_modules/playwright-core"
135 cp -r packages/playwright-core/!(bundles|src|bin|.*) "$out/lib/node_modules/playwright-core"
136
137 mkdir -p "$out/lib/node_modules/@playwright/test"
138 cp -r packages/playwright-test/* "$out/lib/node_modules/@playwright/test"
139
140 runHook postInstall
141 '';
142
143 meta = {
144 description = "Framework for Web Testing and Automation";
145 homepage = "https://playwright.dev";
146 license = lib.licenses.asl20;
147 maintainers = with lib.maintainers; [
148 kalekseev
149 ];
150 inherit (nodejs.meta) platforms;
151 };
152 };
153
154 playwright-core = stdenv.mkDerivation (finalAttrs: {
155 pname = "playwright-core";
156 inherit (playwright) version src meta;
157
158 installPhase = ''
159 runHook preInstall
160
161 cp -r ${playwright}/lib/node_modules/playwright-core "$out"
162
163 runHook postInstall
164 '';
165
166 passthru = {
167 browsersJSON = (lib.importJSON ./browsers.json).browsers;
168 browsers = browsers { };
169 browsers-chromium = browsers {
170 withFirefox = false;
171 withWebkit = false;
172 withChromiumHeadlessShell = false;
173 };
174 inherit components;
175 };
176 });
177
178 playwright-test = stdenv.mkDerivation (finalAttrs: {
179 pname = "playwright-test";
180 inherit (playwright) version src;
181
182 nativeBuildInputs = [ makeWrapper ];
183 installPhase = ''
184 runHook preInstall
185
186 shopt -s extglob
187 mkdir -p $out/bin
188 cp -r ${playwright}/* $out
189
190 makeWrapper "${nodejs}/bin/node" "$out/bin/playwright" \
191 --add-flags "$out/lib/node_modules/@playwright/test/cli.js" \
192 --prefix NODE_PATH : ${placeholder "out"}/lib/node_modules \
193 --set-default PLAYWRIGHT_BROWSERS_PATH "${playwright-core.passthru.browsers}"
194
195 runHook postInstall
196 '';
197
198 meta = playwright.meta // {
199 mainProgram = "playwright";
200 };
201 });
202
203 components = {
204 chromium = callPackage ./chromium.nix {
205 inherit suffix system throwSystem;
206 inherit (playwright-core.passthru.browsersJSON.chromium) revision;
207 fontconfig_file = makeFontsConf {
208 fontDirectories = [ ];
209 };
210 };
211 chromium-headless-shell = callPackage ./chromium-headless-shell.nix {
212 inherit suffix system throwSystem;
213 inherit (playwright-core.passthru.browsersJSON.chromium) revision;
214 };
215 firefox = callPackage ./firefox.nix {
216 inherit suffix system throwSystem;
217 inherit (playwright-core.passthru.browsersJSON.firefox) revision;
218 };
219 webkit = callPackage ./webkit.nix {
220 inherit suffix system throwSystem;
221 inherit (playwright-core.passthru.browsersJSON.webkit) revision;
222 };
223 ffmpeg = callPackage ./ffmpeg.nix {
224 inherit suffix system throwSystem;
225 inherit (playwright-core.passthru.browsersJSON.ffmpeg) revision;
226 };
227 };
228
229 browsers = lib.makeOverridable (
230 {
231 withChromium ? true,
232 withFirefox ? true,
233 withWebkit ? true, # may require `export PLAYWRIGHT_HOST_PLATFORM_OVERRIDE="ubuntu-24.04"`
234 withFfmpeg ? true,
235 withChromiumHeadlessShell ? true,
236 fontconfig_file ? makeFontsConf {
237 fontDirectories = [ ];
238 },
239 }:
240 let
241 browsers =
242 lib.optionals withChromium [ "chromium" ]
243 ++ lib.optionals withChromiumHeadlessShell [ "chromium-headless-shell" ]
244 ++ lib.optionals withFirefox [ "firefox" ]
245 ++ lib.optionals withWebkit [ "webkit" ]
246 ++ lib.optionals withFfmpeg [ "ffmpeg" ];
247 in
248 linkFarm "playwright-browsers" (
249 lib.listToAttrs (
250 map (
251 name:
252 let
253 revName = if name == "chromium-headless-shell" then "chromium" else name;
254 value = playwright-core.passthru.browsersJSON.${revName};
255 in
256 lib.nameValuePair
257 # TODO check platform for revisionOverrides
258 "${lib.replaceStrings [ "-" ] [ "_" ] name}-${value.revision}"
259 components.${name}
260 ) browsers
261 )
262 )
263 );
264in
265{
266 playwright-core = playwright-core;
267 playwright-test = playwright-test;
268}