diff --git a/pkgs/development/python-modules/playwright/update.sh b/pkgs/development/python-modules/playwright/update.sh index 2b283d3b607a16..a8dfacdafac2af 100755 --- a/pkgs/development/python-modules/playwright/update.sh +++ b/pkgs/development/python-modules/playwright/update.sh @@ -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 diff --git a/pkgs/development/web/playwright/chromium.nix b/pkgs/development/web/playwright/chromium.nix index 709cef5c5ca416..458f82b33926f1 100644 --- a/pkgs/development/web/playwright/chromium.nix +++ b/pkgs/development/web/playwright/chromium.nix @@ -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-G9DPo/pXFuaZICT47TSE+bvncS//ydylJVpnfQYp68U="; + aarch64-darwin = "sha256-2JedruJ/y7Zidn6oRfUxi0MleaH5Cp6XQ+F7ImSCTjA="; + } + .${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 diff --git a/pkgs/development/web/playwright/driver.nix b/pkgs/development/web/playwright/driver.nix index 1058a61d48fbcd..05fae59266a552 100644 --- a/pkgs/development/web/playwright/driver.nix +++ b/pkgs/development/web/playwright/driver.nix @@ -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, diff --git a/pkgs/development/web/playwright/ffmpeg.nix b/pkgs/development/web/playwright/ffmpeg.nix index f541031019ed3e..108b19a29214d2 100644 --- a/pkgs/development/web/playwright/ffmpeg.nix +++ b/pkgs/development/web/playwright/ffmpeg.nix @@ -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; } diff --git a/pkgs/development/web/playwright/firefox.nix b/pkgs/development/web/playwright/firefox.nix index 0f404bee2899fc..553dadf4420d5a 100644 --- a/pkgs/development/web/playwright/firefox.nix +++ b/pkgs/development/web/playwright/firefox.nix @@ -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-Hd9LlSRLW51gDoFyszqvg46Q/sMizLRsVKAN9atbwsw="; + aarch64-linux = "sha256-SEXH3gLOfNjOcnNWQjQ5gaaow47veVs0BoTYSgXw+24="; + } + .${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-tclyoXGK0oc40ppqFVHJEGOtiFpc/D8wB37tBHhYhjg="; + aarch64-darwin = "sha256-EEY3cxZaZwNbWwkWy8m9hSDgEV3hotcDPD1ehiQWFig="; } .${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 diff --git a/pkgs/development/web/playwright/webkit.nix b/pkgs/development/web/playwright/webkit.nix index 5c8062bb6f7032..f8590911a0a55d 100644 --- a/pkgs/development/web/playwright/webkit.nix +++ b/pkgs/development/web/playwright/webkit.nix @@ -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-pHYGQYwu47jdOAD+/mLrP6Dd+2aDMHENddVwAu0uEfI="; + aarch64-linux = "sha256-0UeYWjeFnQ8yVa3juWg7Z7VF1GDbP4pJ9OUJRbv1OJw="; + } + .${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 + mesa + 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-sP7MxAMDkrBTN7HR44xrxKPdCF2HzsL5GiaCMHQcqeU="; + aarch64-darwin = "sha256-Sw2+w6HT/e0rdLp7jXj5g3C1Uh05JnP9MznIgg7Glyc="; } .${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 - mesa - 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