From 18f34890d2ed06220fc75d64f692623814fb1ca1 Mon Sep 17 00:00:00 2001 From: Marie Ramlow Date: Mon, 17 Feb 2025 12:08:56 +0100 Subject: [PATCH 1/2] playwright-driver: use upstream chromium build Use the exact chromium version upstream uses for playwright, to prevent breaking from browser updates in nixpkgs. --- pkgs/development/web/playwright/chromium.nix | 109 ++++++++++++++++--- pkgs/development/web/playwright/driver.nix | 39 +++++-- 2 files changed, 120 insertions(+), 28 deletions(-) diff --git a/pkgs/development/web/playwright/chromium.nix b/pkgs/development/web/playwright/chromium.nix index 2c355272b0fe8..00f4b138c62c8 100644 --- a/pkgs/development/web/playwright/chromium.nix +++ b/pkgs/development/web/playwright/chromium.nix @@ -8,27 +8,102 @@ suffix, system, throwSystem, + lib, + alsa-lib, + at-spi2-atk, + atk, + autoPatchelfHook, + cairo, + cups, + dbus, + expat, + glib, + gobject-introspection, + libGL, + libgbm, + libgcc, + libxkbcommon, + nspr, + nss, + pango, + patchelf, + pciutils, + stdenv, + systemd, + vulkan-loader, + xorg, ... }: let - chromium-linux = - runCommand "playwright-chromium" - { - nativeBuildInputs = [ - makeWrapper - ]; - } - '' - mkdir -p $out/chrome-linux + chromium-linux = stdenv.mkDerivation { + name = "playwright-chromium"; + src = fetchzip { + url = "https://playwright.azureedge.net/builds/chromium/${revision}/chromium-${suffix}.zip"; + hash = + { + x86_64-linux = "sha256-9bK8HOGoQY5kYYfJypYHeuAoVlXIh/1tv1IsXPpUTpA="; + aarch64-linux = "sha256-KL6tYnPDszXjCHiSNOPHLtz839JPljSOoP7biQfTTAI="; + } + .${system} or throwSystem; + }; + + nativeBuildInputs = [ + autoPatchelfHook + patchelf + makeWrapper + ]; + buildInputs = [ + alsa-lib + at-spi2-atk + atk + cairo + cups + dbus + expat + glib + gobject-introspection + libgbm + libgcc + libxkbcommon + nspr + nss + pango + stdenv.cc.cc.lib + systemd + xorg.libX11 + xorg.libXcomposite + xorg.libXdamage + xorg.libXext + xorg.libXfixes + xorg.libXrandr + xorg.libxcb + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/chrome-linux + cp -R . $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} - ''; + wrapProgram $out/chrome-linux/chrome \ + --set-default SSL_CERT_FILE /etc/ssl/certs/ca-bundle.crt \ + --set-default FONTCONFIG_FILE ${fontconfig_file} + + runHook postInstall + ''; + + appendRunpaths = lib.makeLibraryPath [ + libGL + vulkan-loader + pciutils + ]; + + postFixup = '' + # replace bundled vulkan-loader since we are also already adding our own to RPATH + rm "$out/chrome-linux/libvulkan.so.1" + ln -s -t "$out/chrome-linux" "${lib.getLib vulkan-loader}/lib/libvulkan.so.1" + ''; + }; chromium-darwin = fetchzip { url = "https://playwright.azureedge.net/builds/chromium/${revision}/chromium-${suffix}.zip"; stripRoot = false; diff --git a/pkgs/development/web/playwright/driver.nix b/pkgs/development/web/playwright/driver.nix index ab0638768a08e..24162834f5646 100644 --- a/pkgs/development/web/playwright/driver.nix +++ b/pkgs/development/web/playwright/driver.nix @@ -165,6 +165,7 @@ let withWebkit = false; withChromiumHeadlessShell = false; }; + inherit components; }; }); @@ -193,6 +194,32 @@ let }; }); + components = { + chromium = callPackage ./chromium.nix { + inherit suffix system throwSystem; + inherit (playwright-core.passthru.browsersJSON.chromium) revision; + fontconfig_file = makeFontsConf { + fontDirectories = [ ]; + }; + }; + chromium-headless-shell = callPackage ./chromium-headless-shell.nix { + inherit suffix system throwSystem; + inherit (playwright-core.passthru.browsersJSON.chromium) revision; + }; + firefox = callPackage ./firefox.nix { + inherit suffix system throwSystem; + inherit (playwright-core.passthru.browsersJSON.firefox) revision; + }; + webkit = callPackage ./webkit.nix { + inherit suffix system throwSystem; + inherit (playwright-core.passthru.browsersJSON.webkit) revision; + }; + ffmpeg = callPackage ./ffmpeg.nix { + inherit suffix system throwSystem; + inherit (playwright-core.passthru.browsersJSON.ffmpeg) revision; + }; + }; + browsers = lib.makeOverridable ( { withChromium ? true, @@ -223,17 +250,7 @@ let lib.nameValuePair # TODO check platform for revisionOverrides "${lib.replaceStrings [ "-" ] [ "_" ] name}-${value.revision}" - ( - callPackage (./. + "/${name}.nix") ( - { - inherit suffix system throwSystem; - inherit (value) revision; - } - // lib.optionalAttrs (name == "chromium") { - inherit fontconfig_file; - } - ) - ) + components.${name} ) browsers ) ) From 9424a47a657f423d3d12ded83fced9974f87a7d9 Mon Sep 17 00:00:00 2001 From: Marie Ramlow Date: Fri, 21 Feb 2025 10:18:51 +0100 Subject: [PATCH 2/2] playwright: add myself as a maintainer --- pkgs/development/web/playwright/driver.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgs/development/web/playwright/driver.nix b/pkgs/development/web/playwright/driver.nix index 24162834f5646..dcdfb2f6cc51d 100644 --- a/pkgs/development/web/playwright/driver.nix +++ b/pkgs/development/web/playwright/driver.nix @@ -140,7 +140,10 @@ let description = "Framework for Web Testing and Automation"; homepage = "https://playwright.dev"; license = lib.licenses.asl20; - maintainers = with lib.maintainers; [ kalekseev ]; + maintainers = with lib.maintainers; [ + kalekseev + marie + ]; inherit (nodejs.meta) platforms; }; };