Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib
2, stdenv
3, chromium
4, ffmpeg
5, git
6, jq
7, nodejs
8, fetchFromGitHub
9, fetchurl
10, makeFontsConf
11, makeWrapper
12, runCommand
13, unzip
14}:
15let
16 inherit (stdenv.hostPlatform) system;
17
18 throwSystem = throw "Unsupported system: ${system}";
19
20 driver = stdenv.mkDerivation (finalAttrs:
21 let
22 suffix = {
23 x86_64-linux = "linux";
24 aarch64-linux = "linux-arm64";
25 x86_64-darwin = "mac";
26 aarch64-darwin = "mac-arm64";
27 }.${system} or throwSystem;
28 filename = "playwright-${finalAttrs.version}-${suffix}.zip";
29 in
30 {
31 pname = "playwright-driver";
32 version = "1.31.1";
33
34 src = fetchurl {
35 url = "https://playwright.azureedge.net/builds/driver/${filename}";
36 sha256 = {
37 x86_64-linux = "1wg49kfs8fflmx8g01bkckbjkghhwy7c44akckjf7dp4lbh1z8fd";
38 aarch64-linux = "0f09a0cxqxihy8lmbjzii80jkpf3n5xlvhjpgdkwmrr3wh0nnixj";
39 x86_64-darwin = "1zd0dz8jazymcpa1im5yzxb7rwl6wn4xz19lpz83bnpd1njq01b3";
40 aarch64-darwin = "0hcn80zm9aki8hzsf1cljzcmi4iaw7fascs8ajj0qcwqkkm4jnw0";
41 }.${system} or throwSystem;
42 };
43
44 sourceRoot = ".";
45
46 nativeBuildInputs = [ unzip ];
47
48 postPatch = ''
49 # Use Nix's NodeJS instead of the bundled one.
50 substituteInPlace playwright.sh --replace '"$SCRIPT_PATH/node"' '"${nodejs}/bin/node"'
51 rm node
52
53 # Hard-code the script path to $out directory to avoid a dependency on coreutils
54 substituteInPlace playwright.sh \
55 --replace 'SCRIPT_PATH="$(cd "$(dirname "$0")" ; pwd -P)"' "SCRIPT_PATH=$out"
56
57 patchShebangs playwright.sh package/bin/*.sh
58 '';
59
60 installPhase = ''
61 runHook preInstall
62
63 mkdir -p $out/bin
64 mv playwright.sh $out/bin/playwright
65 mv package $out/
66
67 runHook postInstall
68 '';
69
70 passthru = {
71 inherit filename;
72 browsers = {
73 x86_64-linux = browsers-linux { };
74 aarch64-linux = browsers-linux { };
75 x86_64-darwin = browsers-mac;
76 aarch64-darwin = browsers-mac;
77 }.${system} or throwSystem;
78 browsers-chromium = browsers-linux {};
79 };
80 });
81
82 browsers-mac = stdenv.mkDerivation {
83 pname = "playwright-browsers";
84 inherit (driver) version;
85
86 dontUnpack = true;
87
88 installPhase = ''
89 runHook preInstall
90
91 export PLAYWRIGHT_BROWSERS_PATH=$out
92 ${driver}/bin/playwright install
93 rm -r $out/.links
94
95 runHook postInstall
96 '';
97
98 meta.platforms = lib.platforms.darwin;
99 };
100
101 browsers-linux = { withChromium ? true }: let
102 fontconfig = makeFontsConf {
103 fontDirectories = [];
104 };
105 in
106 runCommand ("playwright-browsers"
107 + lib.optionalString withChromium "-chromium")
108 {
109 nativeBuildInputs = [
110 makeWrapper
111 jq
112 ];
113 } (''
114 BROWSERS_JSON=${driver}/package/browsers.json
115 '' + lib.optionalString withChromium ''
116 CHROMIUM_REVISION=$(jq -r '.browsers[] | select(.name == "chromium").revision' $BROWSERS_JSON)
117 mkdir -p $out/chromium-$CHROMIUM_REVISION/chrome-linux
118
119 # See here for the Chrome options:
120 # https://github.com/NixOS/nixpkgs/issues/136207#issuecomment-908637738
121 makeWrapper ${chromium}/bin/chromium $out/chromium-$CHROMIUM_REVISION/chrome-linux/chrome \
122 --set SSL_CERT_FILE /etc/ssl/certs/ca-bundle.crt \
123 --set FONTCONFIG_FILE ${fontconfig}
124 '' + ''
125 FFMPEG_REVISION=$(jq -r '.browsers[] | select(.name == "ffmpeg").revision' $BROWSERS_JSON)
126 mkdir -p $out/ffmpeg-$FFMPEG_REVISION
127 ln -s ${ffmpeg}/bin/ffmpeg $out/ffmpeg-$FFMPEG_REVISION/ffmpeg-linux
128 '');
129in
130 driver