playwright: download browsers for darwin (#349469)

This commit is contained in:
Matthieu Coudron
2025-01-23 14:18:29 +01:00
committed by GitHub
8 changed files with 223 additions and 155 deletions
@@ -22,7 +22,7 @@ in
buildPythonPackage rec {
pname = "playwright";
# run ./pkgs/development/python-modules/playwright/update.sh to update
version = "1.47.0";
version = "1.48.0";
pyproject = true;
disabled = pythonOlder "3.7";
@@ -30,7 +30,7 @@ buildPythonPackage rec {
owner = "microsoft";
repo = "playwright-python";
tag = "v${version}";
hash = "sha256-C/spH54hhLI0Egs2jjTjQ5BH1pIw1syrfSyUvVQRoKM=";
hash = "sha256-ZWVySGehR5r6s0y6qCZuFI8SobYbjWP+A6Rgfug2JEE=";
};
patches = [
@@ -1,5 +1,5 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl gnused common-updater-scripts jq prefetch-npm-deps unzip
#!nix-shell -i bash -p curl gnused common-updater-scripts jq prefetch-npm-deps unzip nix-prefetch
set -euo pipefail
root="$(dirname "$(readlink -f "$0")")"
@@ -30,18 +30,38 @@ replace_sha() {
}
prefetch_browser() {
nix store prefetch-file --json --hash-type sha256 --unpack "$1" | jq -r .hash
# nix-prefetch is used to obtain sha with `stripRoot = false`
# doesn't work on macOS https://github.com/msteen/nix-prefetch/issues/53
nix-prefetch -q "{ stdenv, fetchzip }: stdenv.mkDerivation rec { name=\"browser\"; src = fetchzip { url = \"$1\"; stripRoot = $2; }; }"
}
update_browser() {
name="$1"
suffix="$2"
arm64_suffix="${3:-$2-arm64}"
platform="$2"
stripRoot="false"
if [ "$platform" = "darwin" ]; then
if [ "$name" = "webkit" ]; then
suffix="mac-14"
else
suffix="mac"
fi
else
if [ "$name" = "ffmpeg" ]; then
suffix="linux"
elif [ "$name" = "firefox" ]; then
stripRoot="true"
suffix="ubuntu-22.04"
else
suffix="ubuntu-22.04"
fi
fi
aarch64_suffix="$suffix-arm64"
revision="$(jq -r ".browsers.$name.revision" "$playwright_dir/browsers.json")"
replace_sha "$playwright_dir/$name.nix" "x86_64-linux" \
"$(prefetch_browser "https://playwright.azureedge.net/builds/$name/$revision/$name-$suffix.zip")"
replace_sha "$playwright_dir/$name.nix" "aarch64-linux" \
"$(prefetch_browser "https://playwright.azureedge.net/builds/$name/$revision/$name-$arm64_suffix.zip")"
replace_sha "$playwright_dir/$name.nix" "x86_64-$platform" \
"$(prefetch_browser "https://playwright.azureedge.net/builds/$name/$revision/$name-$suffix.zip" $stripRoot)"
replace_sha "$playwright_dir/$name.nix" "aarch64-$platform" \
"$(prefetch_browser "https://playwright.azureedge.net/builds/$name/$revision/$name-$aarch64_suffix.zip" $stripRoot)"
}
curl -fsSl \
@@ -58,10 +78,14 @@ curl -fsSl \
# We currently use Chromium from nixpkgs, so we don't need to download it here
# Likewise, darwin can be ignored here atm as we are using an impure install anyway.
update_browser "firefox" "ubuntu-22.04"
update_browser "webkit" "ubuntu-22.04"
update_browser "firefox" "linux"
update_browser "webkit" "linux"
update_browser "ffmpeg" "linux"
update_browser "chromium" "darwin"
update_browser "firefox" "darwin"
update_browser "webkit" "darwin"
update_browser "ffmpeg" "darwin"
# Update package-lock.json files for all npm deps that are built in playwright
+10 -6
View File
@@ -2,15 +2,15 @@
"comment": "This file is kept up to date via update.sh",
"browsers": {
"chromium": {
"revision": "1134",
"browserVersion": "129.0.6668.29"
"revision": "1140",
"browserVersion": "130.0.6723.31"
},
"firefox": {
"revision": "1463",
"browserVersion": "130.0"
"revision": "1465",
"browserVersion": "131.0"
},
"webkit": {
"revision": "2070",
"revision": "2083",
"revisionOverrides": {
"mac10.14": "1446",
"mac10.15": "1616",
@@ -22,7 +22,11 @@
"browserVersion": "18.0"
},
"ffmpeg": {
"revision": "1010"
"revision": "1010",
"revisionOverrides": {
"mac12": "1010",
"mac12-arm64": "1010"
}
}
}
}
+41 -16
View File
@@ -3,22 +3,47 @@
makeWrapper,
fontconfig_file,
chromium,
fetchzip,
revision,
suffix,
system,
throwSystem,
...
}:
runCommand "playwright-chromium"
{
nativeBuildInputs = [
makeWrapper
];
}
''
mkdir -p $out/chrome-linux
let
chromium-linux =
runCommand "playwright-chromium"
{
nativeBuildInputs = [
makeWrapper
];
}
''
mkdir -p $out/chrome-linux
# See here for the Chrome options:
# https://github.com/NixOS/nixpkgs/issues/136207#issuecomment-908637738
# We add --disable-gpu to be able to run in gpu-less environments such
# as headless nixos test vms.
makeWrapper ${chromium}/bin/chromium $out/chrome-linux/chrome \
--set-default SSL_CERT_FILE /etc/ssl/certs/ca-bundle.crt \
--set-default FONTCONFIG_FILE ${fontconfig_file}
''
# See here for the Chrome options:
# https://github.com/NixOS/nixpkgs/issues/136207#issuecomment-908637738
# We add --disable-gpu to be able to run in gpu-less environments such
# as headless nixos test vms.
makeWrapper ${chromium}/bin/chromium $out/chrome-linux/chrome \
--set-default SSL_CERT_FILE /etc/ssl/certs/ca-bundle.crt \
--set-default FONTCONFIG_FILE ${fontconfig_file}
'';
chromium-darwin = fetchzip {
url = "https://playwright.azureedge.net/builds/chromium/${revision}/chromium-${suffix}.zip";
stripRoot = false;
hash =
{
x86_64-darwin = "sha256-N/uh3Q2ivqeraAqRt80deVz1XEPyLTYI8L3DBfNQGWg=";
aarch64-darwin = "sha256-tR9PwGanPcsDQwi1BijeYJd9LhNIWgEoXs5u3gZpghU=";
}
.${system} or throwSystem;
};
in
{
x86_64-linux = chromium-linux;
aarch64-linux = chromium-linux;
x86_64-darwin = chromium-darwin;
aarch64-darwin = chromium-darwin;
}
.${system} or throwSystem
+11 -36
View File
@@ -27,20 +27,20 @@ let
}
.${system} or throwSystem;
version = "1.47.0";
version = "1.48.1";
src = fetchFromGitHub {
owner = "Microsoft";
repo = "playwright";
rev = "v${version}";
hash = "sha256-cKjVDy1wFo8NlF8v+8YBuQUF2OUYjCmv27uhEoVUrno=";
hash = "sha256-VMp/Tjd5w2v+IHD+CMaR/XdMJHkS/u7wFe0hNxa1TbE=";
};
babel-bundle = buildNpmPackage {
pname = "babel-bundle";
inherit version src;
sourceRoot = "${src.name}/packages/playwright/bundles/babel";
npmDepsHash = "sha256-HrDTkP2lHl2XKD8aGpmnf6YtSe/w9UePH5W9QfbaoMg=";
npmDepsHash = "sha256-kHuNFgxmyIoxTmvT+cyzDRfKNy18zzeUH3T+gJopWeA=";
dontNpmBuild = true;
installPhase = ''
cp -r . "$out"
@@ -50,7 +50,7 @@ let
pname = "expect-bundle";
inherit version src;
sourceRoot = "${src.name}/packages/playwright/bundles/expect";
npmDepsHash = "sha256-qnFx/AQZtmxNFrrabfOpsWy6I64DFJf3sWrJzL1wfU4=";
npmDepsHash = "sha256-KwxNqPefvPPHG4vbco2O4G8WlA7l33toJdfNWHMTDOQ=";
dontNpmBuild = true;
installPhase = ''
cp -r . "$out"
@@ -92,7 +92,7 @@ let
inherit version src;
sourceRoot = "${src.name}"; # update.sh depends on sourceRoot presence
npmDepsHash = "sha256-FaDTJmIiaaOCvq6tARfiWX5IBTTNOJ/iVkRsO4D8aqc=";
npmDepsHash = "sha256-cmUmYuUL7zfB7WEBKft43r69f7vaZDEjku8uwR3RZ1A=";
nativeBuildInputs = [ cacert ];
@@ -159,15 +159,11 @@ let
passthru = {
browsersJSON = (lib.importJSON ./browsers.json).browsers;
browsers =
{
x86_64-linux = browsers-linux { };
aarch64-linux = browsers-linux { };
x86_64-darwin = browsers-mac;
aarch64-darwin = browsers-mac;
}
.${system} or throwSystem;
browsers-chromium = browsers-linux { };
browsers = browsers { };
browsers-chromium = browsers {
withFirefox = false;
withWebkit = false;
};
};
});
@@ -196,28 +192,7 @@ let
};
});
browsers-mac = stdenv.mkDerivation {
pname = "playwright-browsers";
inherit (playwright) version;
dontUnpack = true;
nativeBuildInputs = [ cacert ];
installPhase = ''
runHook preInstall
export PLAYWRIGHT_BROWSERS_PATH=$out
${playwright-core}/cli.js install
rm -r $out/.links
runHook postInstall
'';
meta.platforms = lib.platforms.darwin;
};
browsers-linux = lib.makeOverridable (
browsers = lib.makeOverridable (
{
withChromium ? true,
withFirefox ? true,
@@ -12,6 +12,8 @@ fetchzip {
{
x86_64-linux = "sha256-FEm62UvMv0h6Sav93WmbPLw3CW1L1xg4nD26ca5ol38=";
aarch64-linux = "sha256-jtQ+NS++VHRiKoIV++PIxEnyVnYtVwUyNlSILKSH4A4=";
x86_64-darwin = "sha256-ED6noxSDeEUt2DkIQ4gNe/kL+zHVeb2AD5klBk93F88=";
aarch64-darwin = "sha256-3Adnvb7zvMXKFOhb8uuj5kx0wEIFicmckYx9WLlNNf0=";
}
.${system} or throwSystem;
}
+39 -22
View File
@@ -9,31 +9,48 @@
throwSystem,
}:
let
suffix' =
if lib.hasPrefix "linux" suffix then "ubuntu-22.04" + (lib.removePrefix "linux" suffix) else suffix;
in
stdenv.mkDerivation {
name = "playwright-firefox";
src = fetchzip {
url = "https://playwright.azureedge.net/builds/firefox/${revision}/firefox-${suffix'}.zip";
firefox-linux = stdenv.mkDerivation {
name = "playwright-firefox";
src = fetchzip {
url = "https://playwright.azureedge.net/builds/firefox/${revision}/firefox-${
"ubuntu-22.04" + (lib.removePrefix "linux" suffix)
}.zip";
hash =
{
x86_64-linux = "sha256-L/CJVtj9bVXKuKSLWw0wAdNICiRTg5ek+fw4togBoSI=";
aarch64-linux = "sha256-DgCuX+6KSnoHNFoFUli6S20GGHOExARasiJY9fy3CCE=";
}
.${system} or throwSystem;
};
inherit (firefox-bin.unwrapped)
nativeBuildInputs
buildInputs
runtimeDependencies
appendRunpaths
patchelfFlags
;
buildPhase = ''
mkdir -p $out/firefox
cp -R . $out/firefox
'';
};
firefox-darwin = fetchzip {
url = "https://playwright.azureedge.net/builds/firefox/${revision}/firefox-${suffix}.zip";
stripRoot = false;
hash =
{
x86_64-linux = "sha256-Hd9LlSRLW51gDoFyszqvg46Q/sMizLRsVKAN9atbwsw=";
aarch64-linux = "sha256-SEXH3gLOfNjOcnNWQjQ5gaaow47veVs0BoTYSgXw+24=";
x86_64-darwin = "sha256-HJ0jBmTW/Zz2fkmSo1gEv5P58PGyhXKnJVxJ12Q4IiM=";
aarch64-darwin = "sha256-YnnG8BX06vQlJmzZGaCKq1wKGp3yRaUQ4RF+tEWoK6U=";
}
.${system} or throwSystem;
};
inherit (firefox-bin.unwrapped)
nativeBuildInputs
buildInputs
runtimeDependencies
appendRunpaths
patchelfFlags
;
buildPhase = ''
mkdir -p $out/firefox
cp -R . $out/firefox
'';
in
{
x86_64-linux = firefox-linux;
aarch64-linux = firefox-linux;
x86_64-darwin = firefox-darwin;
aarch64-darwin = firefox-darwin;
}
.${system} or throwSystem
+84 -63
View File
@@ -50,7 +50,12 @@
}:
let
suffix' =
if lib.hasPrefix "linux" suffix then "ubuntu-22.04" + (lib.removePrefix "linux" suffix) else suffix;
if lib.hasPrefix "linux" suffix then
"ubuntu-22.04" + (lib.removePrefix "linux" suffix)
else if lib.hasPrefix "mac" suffix then
"mac-14" + (lib.removePrefix "mac" suffix)
else
suffix;
libvpx' = libvpx.overrideAttrs (
finalAttrs: previousAttrs: {
version = "1.12.0";
@@ -62,74 +67,90 @@ let
};
}
);
webkit-linux = stdenv.mkDerivation {
name = "playwright-webkit";
src = fetchzip {
url = "https://playwright.azureedge.net/builds/webkit/${revision}/webkit-${suffix'}.zip";
stripRoot = false;
hash =
{
x86_64-linux = "sha256-vz/c2Bzr1NWRZZL5hIRwnor2Wte61gS++8rRfmy9T+0=";
aarch64-linux = "sha256-dS4Hsy/lGZWgznviwkslSk5oBYdUIBxeQPfaEyLNXyc=";
}
.${system} or throwSystem;
};
in
stdenv.mkDerivation {
name = "playwright-webkit";
src = fetchzip {
nativeBuildInputs = [
autoPatchelfHook
patchelfUnstable
makeWrapper
];
buildInputs = [
at-spi2-atk
cairo
flite
fontconfig.lib
freetype
glib
gst_all_1.gst-plugins-bad
gst_all_1.gst-plugins-base
gst_all_1.gstreamer
harfbuzz
harfbuzzFull
icu70
lcms
libdrm
libepoxy
libevent
libgcc.lib
libgcrypt
libgpg-error
libjpeg8
libopus
libpng
libsoup_3
libtasn1
libwebp
libwpe
libwpe-fdo
libvpx'
libxml2
libxslt
libgbm
sqlite
systemdLibs
wayland-scanner
woff2.lib
libxkbcommon
zlib
];
patchelfFlags = [ "--no-clobber-old-sections" ];
buildPhase = ''
cp -R . $out
# remove unused gtk browser
rm -rf $out/minibrowser-gtk
wrapProgram $out/minibrowser-wpe/bin/MiniBrowser \
--prefix GIO_EXTRA_MODULES ":" "${glib-networking}/lib/gio/modules/"
'';
};
webkit-darwin = fetchzip {
url = "https://playwright.azureedge.net/builds/webkit/${revision}/webkit-${suffix'}.zip";
stripRoot = false;
hash =
{
x86_64-linux = "sha256-pHYGQYwu47jdOAD+/mLrP6Dd+2aDMHENddVwAu0uEfI=";
aarch64-linux = "sha256-0UeYWjeFnQ8yVa3juWg7Z7VF1GDbP4pJ9OUJRbv1OJw=";
x86_64-darwin = "sha256-lOAHJaDXtt80RhqFNaO1JhaJH5WAu6+rpoR+IsfzGeM=";
aarch64-darwin = "sha256-GrjTnMGTPBdRI3xE5t9HbXLrvgOjCdqbJGElTKhUoA4=";
}
.${system} or throwSystem;
};
nativeBuildInputs = [
autoPatchelfHook
patchelfUnstable
makeWrapper
];
buildInputs = [
at-spi2-atk
cairo
flite
fontconfig.lib
freetype
glib
gst_all_1.gst-plugins-bad
gst_all_1.gst-plugins-base
gst_all_1.gstreamer
harfbuzz
harfbuzzFull
icu70
lcms
libdrm
libepoxy
libevent
libgcc.lib
libgcrypt
libgpg-error
libjpeg8
libopus
libpng
libsoup_3
libtasn1
libwebp
libwpe
libwpe-fdo
libvpx'
libxml2
libxslt
libgbm
sqlite
systemdLibs
wayland-scanner
woff2.lib
libxkbcommon
zlib
];
patchelfFlags = [ "--no-clobber-old-sections" ];
buildPhase = ''
cp -R . $out
# remove unused gtk browser
rm -rf $out/minibrowser-gtk
wrapProgram $out/minibrowser-wpe/bin/MiniBrowser \
--prefix GIO_EXTRA_MODULES ":" "${glib-networking}/lib/gio/modules/"
'';
in
{
x86_64-linux = webkit-linux;
aarch64-linux = webkit-linux;
x86_64-darwin = webkit-darwin;
aarch64-darwin = webkit-darwin;
}
.${system} or throwSystem