Skip to content

Instantly share code, notes, and snippets.

@schickling
Created February 13, 2023 15:38
Show Gist options
  • Save schickling/228faae3aecc795c9e9370e4541d2b5b to your computer and use it in GitHub Desktop.
Save schickling/228faae3aecc795c9e9370e4541d2b5b to your computer and use it in GitHub Desktop.
{ lib, stdenv, pkgs ? import <nixpkgs> { } }:
let
packages = {
playwright-chromium = pkgs.callPackage ./playwright-chromium.nix { };
};
rev = "1041";
inherit (pkgs.stdenv.hostPlatform) system;
selectSystem = attrs:
attrs.${system} or (throw "Unsupported system: ${system}");
suffix = selectSystem {
x86_64-linux = "linux";
aarch64-linux = "linux";
x86_64-darwin = "mac";
aarch64-darwin = "mac";
};
in
stdenv.mkDerivation rec {
name = "playwright-browsers";
src = ./.;
dontBuild = true;
buildInputs = with pkgs; [
packages.playwright-chromium
] ++ lib.optionals stdenv.isLinux [
xorg.libX11
xorg.libX11.dev
xorg.libXext
xorg.libxcb
];
shellHook = lib.optionalString stdenv.isLinux ''
export LD_LIBRARY_PATH="${lib.makeLibraryPath buildInputs}";
'';
installPhase = ''
mkdir -p $out/chromium-${rev}/chrome-${suffix}
cp -rT ${packages.playwright-chromium} $out/chromium-${rev}/chrome-${suffix}
'';
}
{ lib, pkgs ? import <nixpkgs> { } }:
let
inherit (pkgs) fetchzip lib stdenv;
inherit (pkgs.stdenv) mkDerivation;
inherit (pkgs.stdenv.hostPlatform) system;
selectSystem = attrs:
attrs.${system} or (throw "Unsupported system: ${system}");
# Build rev number manually read by running `npx playwright install`
rev = "1041";
suffix = selectSystem {
x86_64-linux = "linux";
aarch64-linux = "linux-arm64";
x86_64-darwin = "mac";
aarch64-darwin = "mac-arm64";
};
sha256 = {
# Fill in on demand
"1041" = selectSystem {
x86_64-linux = "32dD4zpOP1UZ/tWhmdrmelooayh4W3Ygsz078o9HMHU=";
aarch64-darwin = "sha256-qXjhql4xlooFLV7JGIJ66rdj0v1ODzf3ll4LckN0Hbs=";
# x86_64-linux = lib.fakeSha256;
# aarch64-darwin = lib.fakeSha256;
};
}.${rev};
# https://github.com/microsoft/playwright/blob/e08168e16e5b29a678cd7f31e201d9b851666cde/packages/playwright-core/src/server/registry/index.ts#L77
upstream_chromium = fetchzip {
url =
"https://playwright.azureedge.net/builds/chromium/${rev}/chromium-${suffix}.zip";
inherit sha256;
stripRoot = true;
};
in
mkDerivation rec {
name = "chromium-playwright";
version = rev;
src = upstream_chromium;
nativeBuildInputs = lib.optionals stdenv.isLinux [ pkgs.patchelf ];
installPhase = lib.optionalString stdenv.isDarwin ''
mkdir -p $out
cp -r $src/* $out/
''
+ lib.optionalString stdenv.isLinux ''
mkdir $out
cp -r $src/* $out/
# patchelf the binary
wrapper="${pkgs.google-chrome-dev}/bin/google-chrome-unstable"
wrapper_2="$(cat "$wrapper" | grep '^exec ' | grep -o -P '/nix/store/[^"]+' | head -n 1)"
binary="$(dirname "$wrapper_2")/chrome"
interpreter="$(patchelf --print-interpreter "$binary")"
rpath="$(patchelf --print-rpath "$binary")"
chmod u+w $out/chrome
stat $out/chrome
patchelf --set-interpreter "$interpreter" $out/chrome
patchelf --set-rpath "$rpath" $out/chrome
chmod u-w $out/chrome
# create the wrapper script
mv $out/chrome $out/chrome.bin
cat "$wrapper" | grep -vE '^exec ' > $out/chrome
echo "exec \"$out/chrome.bin\" \"\$@\"" >> $out/chrome
chmod a+x $out/chrome
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment