summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthieu Coudron <teto@users.noreply.github.com>2023-04-18 23:18:03 +0200
committerGitHub <noreply@github.com>2023-04-18 23:18:03 +0200
commit6d9b8796028dde4e3b0c8bebac1666295b914e81 (patch)
treea4cfea4d06eade1a5ad24a61538282fc1732f6cd
parent7abd3e8f67e26b1aa859cf3a14d1065cae2f97fb (diff)
downloadnixpkgs-6d9b8796028dde4e3b0c8bebac1666295b914e81.tar
nixpkgs-6d9b8796028dde4e3b0c8bebac1666295b914e81.tar.gz
nixpkgs-6d9b8796028dde4e3b0c8bebac1666295b914e81.tar.bz2
nixpkgs-6d9b8796028dde4e3b0c8bebac1666295b914e81.tar.lz
nixpkgs-6d9b8796028dde4e3b0c8bebac1666295b914e81.tar.xz
nixpkgs-6d9b8796028dde4e3b0c8bebac1666295b914e81.tar.zst
nixpkgs-6d9b8796028dde4e3b0c8bebac1666295b914e81.zip
playwright-driver: init at 1.30.1 (#223382)
it was actually moved from
pkgs/development/python-modules/playwright/default.nix to its own
pkgs/development/web/playwright/driver.nix .

I am trying to package the typescript version of playwright and the
browsers are needed there, it's more convenient to split them away from the python module.

Careful playwright.browsers is not accessible anymore.

Apply suggestions from code review

Co-authored-by: Yannik Rödel <hey@yannik.info>
-rw-r--r--pkgs/development/python-modules/playwright/default.nix129
-rw-r--r--pkgs/development/python-modules/pytest-playwright/default.nix3
-rw-r--r--pkgs/development/web/playwright/driver.nix130
-rw-r--r--pkgs/top-level/all-packages.nix2
-rw-r--r--pkgs/top-level/python-packages.nix4
5 files changed, 141 insertions, 127 deletions
diff --git a/pkgs/development/python-modules/playwright/default.nix b/pkgs/development/python-modules/playwright/default.nix
index 5e5c9d1a3db..c58b3bb6bb0 100644
--- a/pkgs/development/python-modules/playwright/default.nix
+++ b/pkgs/development/python-modules/playwright/default.nix
@@ -1,131 +1,21 @@
 { lib
-, stdenv
 , buildPythonPackage
-, chromium
-, ffmpeg
 , git
 , greenlet
-, jq
-, nodejs
 , fetchFromGitHub
-, fetchurl
-, makeFontsConf
-, makeWrapper
 , pyee
 , python
 , pythonOlder
-, runCommand
 , setuptools-scm
-, unzip
+, playwright-driver
 }:
 
 let
-  inherit (stdenv.hostPlatform) system;
-  throwSystem = throw "Unsupported system: ${system}";
-
-  driverVersion = "1.31.1";
-
-  driver = let
-    suffix = {
-      x86_64-linux = "linux";
-      aarch64-linux = "linux-arm64";
-      x86_64-darwin = "mac";
-      aarch64-darwin = "mac-arm64";
-    }.${system} or throwSystem;
-    filename = "playwright-${driverVersion}-${suffix}.zip";
-  in stdenv.mkDerivation {
-    pname = "playwright-driver";
-    version = driverVersion;
-
-    src = fetchurl {
-      url = "https://playwright.azureedge.net/builds/driver/${filename}";
-      sha256 = {
-        x86_64-linux = "1wg49kfs8fflmx8g01bkckbjkghhwy7c44akckjf7dp4lbh1z8fd";
-        aarch64-linux = "0f09a0cxqxihy8lmbjzii80jkpf3n5xlvhjpgdkwmrr3wh0nnixj";
-        x86_64-darwin = "1zd0dz8jazymcpa1im5yzxb7rwl6wn4xz19lpz83bnpd1njq01b3";
-        aarch64-darwin = "0hcn80zm9aki8hzsf1cljzcmi4iaw7fascs8ajj0qcwqkkm4jnw0";
-      }.${system} or throwSystem;
-    };
-
-    sourceRoot = ".";
-
-    nativeBuildInputs = [ unzip ];
-
-    postPatch = ''
-      # Use Nix's NodeJS instead of the bundled one.
-      substituteInPlace playwright.sh --replace '"$SCRIPT_PATH/node"' '"${nodejs}/bin/node"'
-      rm node
-
-      # Hard-code the script path to $out directory to avoid a dependency on coreutils
-      substituteInPlace playwright.sh \
-        --replace 'SCRIPT_PATH="$(cd "$(dirname "$0")" ; pwd -P)"' "SCRIPT_PATH=$out"
-
-      patchShebangs playwright.sh package/bin/*.sh
-    '';
-
-    installPhase = ''
-      runHook preInstall
-
-      mkdir -p $out/bin
-      mv playwright.sh $out/bin/playwright
-      mv package $out/
-
-      runHook postInstall
-    '';
-
-    passthru = {
-      inherit filename;
-    };
-  };
-
-  browsers-mac = stdenv.mkDerivation {
-    pname = "playwright-browsers";
-    version = driverVersion;
-
-    dontUnpack = true;
-
-    installPhase = ''
-      runHook preInstall
-
-      export PLAYWRIGHT_BROWSERS_PATH=$out
-      ${driver}/bin/playwright install
-      rm -r $out/.links
-
-      runHook postInstall
-    '';
-
-    meta.platforms = lib.platforms.darwin;
-  };
-
-  browsers-linux = {}: let
-    fontconfig = makeFontsConf {
-      fontDirectories = [];
-    };
-  in runCommand "playwright-browsers"
-  {
-    nativeBuildInputs = [
-      makeWrapper
-      jq
-    ];
-  } (''
-    BROWSERS_JSON=${driver}/package/browsers.json
-    CHROMIUM_REVISION=$(jq -r '.browsers[] | select(.name == "chromium").revision' $BROWSERS_JSON)
-    mkdir -p $out/chromium-$CHROMIUM_REVISION/chrome-linux
-
-    # See here for the Chrome options:
-    # https://github.com/NixOS/nixpkgs/issues/136207#issuecomment-908637738
-    makeWrapper ${chromium}/bin/chromium $out/chromium-$CHROMIUM_REVISION/chrome-linux/chrome \
-      --set SSL_CERT_FILE /etc/ssl/certs/ca-bundle.crt \
-      --set FONTCONFIG_FILE ${fontconfig}
-
-    FFMPEG_REVISION=$(jq -r '.browsers[] | select(.name == "ffmpeg").revision' $BROWSERS_JSON)
-    mkdir -p $out/ffmpeg-$FFMPEG_REVISION
-    ln -s ${ffmpeg}/bin/ffmpeg $out/ffmpeg-$FFMPEG_REVISION/ffmpeg-linux
-  '');
+  driver = playwright-driver;
 in
 buildPythonPackage rec {
   pname = "playwright";
-  version = "1.31.1";
+  version =  "1.31.1";
   format = "setuptools";
   disabled = pythonOlder "3.7";
 
@@ -191,18 +81,11 @@ buildPythonPackage rec {
     "playwright"
   ];
 
-  passthru = rec {
+  passthru = {
     inherit driver;
-    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 { };
-
     tests = {
-      inherit driver browsers;
+      driver = playwright-driver;
+      browsers = playwright-driver.browsers;
     };
   };
 
diff --git a/pkgs/development/python-modules/pytest-playwright/default.nix b/pkgs/development/python-modules/pytest-playwright/default.nix
index 9e620a6210a..ee174a12183 100644
--- a/pkgs/development/python-modules/pytest-playwright/default.nix
+++ b/pkgs/development/python-modules/pytest-playwright/default.nix
@@ -2,6 +2,7 @@
 , fetchFromGitHub
 , buildPythonPackage
 , playwright
+, playwright-driver
 , pytest
 , pytest-base-url
 , pytestCheckHook
@@ -46,7 +47,7 @@ buildPythonPackage rec {
   doCheck = false;
 
   preCheck = ''
-    export PLAYWRIGHT_BROWSERS_PATH=${playwright.browsers}
+    export PLAYWRIGHT_BROWSERS_PATH=${playwright-driver.browsers}
   '';
 
   pythonImportsCheck = [
diff --git a/pkgs/development/web/playwright/driver.nix b/pkgs/development/web/playwright/driver.nix
new file mode 100644
index 00000000000..2ebb884aab1
--- /dev/null
+++ b/pkgs/development/web/playwright/driver.nix
@@ -0,0 +1,130 @@
+{ lib
+, stdenv
+, chromium
+, ffmpeg
+, git
+, jq
+, nodejs
+, fetchFromGitHub
+, fetchurl
+, makeFontsConf
+, makeWrapper
+, runCommand
+, unzip
+}:
+let
+  inherit (stdenv.hostPlatform) system;
+
+  throwSystem = throw "Unsupported system: ${system}";
+
+  driver = stdenv.mkDerivation (finalAttrs:
+    let
+      suffix = {
+        x86_64-linux = "linux";
+        aarch64-linux = "linux-arm64";
+        x86_64-darwin = "mac";
+        aarch64-darwin = "mac-arm64";
+      }.${system} or throwSystem;
+      filename = "playwright-${finalAttrs.version}-${suffix}.zip";
+    in
+    {
+    pname = "playwright-driver";
+    version =  "1.31.1";
+
+    src = fetchurl {
+      url = "https://playwright.azureedge.net/builds/driver/${filename}";
+      sha256 = {
+        x86_64-linux = "1wg49kfs8fflmx8g01bkckbjkghhwy7c44akckjf7dp4lbh1z8fd";
+        aarch64-linux = "0f09a0cxqxihy8lmbjzii80jkpf3n5xlvhjpgdkwmrr3wh0nnixj";
+        x86_64-darwin = "1zd0dz8jazymcpa1im5yzxb7rwl6wn4xz19lpz83bnpd1njq01b3";
+        aarch64-darwin = "0hcn80zm9aki8hzsf1cljzcmi4iaw7fascs8ajj0qcwqkkm4jnw0";
+      }.${system} or throwSystem;
+    };
+
+    sourceRoot = ".";
+
+    nativeBuildInputs = [ unzip ];
+
+    postPatch = ''
+      # Use Nix's NodeJS instead of the bundled one.
+      substituteInPlace playwright.sh --replace '"$SCRIPT_PATH/node"' '"${nodejs}/bin/node"'
+      rm node
+
+      # Hard-code the script path to $out directory to avoid a dependency on coreutils
+      substituteInPlace playwright.sh \
+        --replace 'SCRIPT_PATH="$(cd "$(dirname "$0")" ; pwd -P)"' "SCRIPT_PATH=$out"
+
+      patchShebangs playwright.sh package/bin/*.sh
+    '';
+
+    installPhase = ''
+      runHook preInstall
+
+      mkdir -p $out/bin
+      mv playwright.sh $out/bin/playwright
+      mv package $out/
+
+      runHook postInstall
+    '';
+
+    passthru = {
+      inherit filename;
+      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-mac = stdenv.mkDerivation {
+    pname = "playwright-browsers";
+    inherit (driver) version;
+
+    dontUnpack = true;
+
+    installPhase = ''
+      runHook preInstall
+
+      export PLAYWRIGHT_BROWSERS_PATH=$out
+      ${driver}/bin/playwright install
+      rm -r $out/.links
+
+      runHook postInstall
+    '';
+
+    meta.platforms = lib.platforms.darwin;
+  };
+
+  browsers-linux = { withChromium ? true }: let
+    fontconfig = makeFontsConf {
+      fontDirectories = [];
+    };
+  in
+    runCommand ("playwright-browsers"
+    + lib.optionalString withChromium "-chromium")
+  {
+    nativeBuildInputs = [
+      makeWrapper
+      jq
+    ];
+  } (''
+    BROWSERS_JSON=${driver}/package/browsers.json
+  '' + lib.optionalString withChromium ''
+    CHROMIUM_REVISION=$(jq -r '.browsers[] | select(.name == "chromium").revision' $BROWSERS_JSON)
+    mkdir -p $out/chromium-$CHROMIUM_REVISION/chrome-linux
+
+    # See here for the Chrome options:
+    # https://github.com/NixOS/nixpkgs/issues/136207#issuecomment-908637738
+    makeWrapper ${chromium}/bin/chromium $out/chromium-$CHROMIUM_REVISION/chrome-linux/chrome \
+      --set SSL_CERT_FILE /etc/ssl/certs/ca-bundle.crt \
+      --set FONTCONFIG_FILE ${fontconfig}
+  '' + ''
+    FFMPEG_REVISION=$(jq -r '.browsers[] | select(.name == "ffmpeg").revision' $BROWSERS_JSON)
+    mkdir -p $out/ffmpeg-$FFMPEG_REVISION
+    ln -s ${ffmpeg}/bin/ffmpeg $out/ffmpeg-$FFMPEG_REVISION/ffmpeg-linux
+  '');
+in
+  driver
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 8b50fe4dc0c..11f8db997f1 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -11144,6 +11144,8 @@ with pkgs;
 
   playwright = with python3Packages; toPythonApplication playwright;
 
+  playwright-driver = callPackage ../development/web/playwright/driver.nix { };
+
   please = callPackage ../tools/security/please { };
 
   plecost = callPackage ../tools/security/plecost { };
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index e094604801d..a63f8797aac 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -7406,9 +7406,7 @@ self: super: with self; {
 
   pkuseg = callPackage ../development/python-modules/pkuseg { };
 
-  playwright = callPackage ../development/python-modules/playwright {
-    inherit (pkgs) jq;
-  };
+  playwright = callPackage ../development/python-modules/playwright { };
 
   pmsensor = callPackage ../development/python-modules/pmsensor { };