fix(nix): use nixpkgs playwright-driver and disable Playwright browser downloads
Some checks failed
ci / tests (push) Has been cancelled

https://chatgpt.com/share/694af26e-fb6c-800f-b0e3-e710cd035798
This commit is contained in:
Kevin Veen-Birkenbach
2025-12-23 20:49:57 +01:00
parent a582e8be13
commit bf69c110a7

View File

@@ -15,6 +15,7 @@
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
python = pkgs.python312; python = pkgs.python312;
playwrightDriver = pkgs.playwright-driver;
in in
rec { rec {
matomo-bootstrap = python.pkgs.buildPythonApplication { matomo-bootstrap = python.pkgs.buildPythonApplication {
@@ -22,10 +23,17 @@
version = "1.0.1"; # keep in sync with pyproject.toml version = "1.0.1"; # keep in sync with pyproject.toml
pyproject = true; pyproject = true;
src = self; src = self;
pythonImportsCheck = [ ]; # disable import-check phase (prevents Playwright/installer side effects)
nativeBuildInputs = with python.pkgs; [ # disable import-check phase (prevents Playwright/installer side effects)
pythonImportsCheck = [ ];
nativeBuildInputs =
(with python.pkgs; [
setuptools setuptools
wheel wheel
])
++ [
pkgs.makeWrapper
]; ];
propagatedBuildInputs = with python.pkgs; [ propagatedBuildInputs = with python.pkgs; [
@@ -34,6 +42,20 @@
doCheck = false; doCheck = false;
# IMPORTANT (Nix):
# Do NOT let Playwright download ubuntu/fhs browser binaries into ~/.cache/ms-playwright.
# Instead, point Playwright to nixpkgs-provided browsers (playwright-driver).
#
# This fixes errors like:
# BrowserType.launch ... headless_shell ENOENT
#
# ...which happens when Playwright downloads a fallback ubuntu build that cannot run on NixOS.
postFixup = ''
wrapProgram "$out/bin/matomo-bootstrap" \
--set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD 1 \
--set PLAYWRIGHT_BROWSERS_PATH "${playwrightDriver.browsers}"
'';
meta = with pkgs.lib; { meta = with pkgs.lib; {
description = "Headless bootstrap tooling for Matomo (installation + API token provisioning)"; description = "Headless bootstrap tooling for Matomo (installation + API token provisioning)";
homepage = "https://github.com/kevinveenbirkenbach/matomo-bootstrap"; homepage = "https://github.com/kevinveenbirkenbach/matomo-bootstrap";
@@ -50,6 +72,7 @@
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
python = pkgs.python312; python = pkgs.python312;
playwrightDriver = pkgs.playwright-driver;
pythonPlaywright = python.withPackages (ps: [ pythonPlaywright = python.withPackages (ps: [
ps.playwright ps.playwright
@@ -62,9 +85,20 @@
runtimeInputs = [ pythonPlaywright ]; runtimeInputs = [ pythonPlaywright ];
text = '' text = ''
# Install Playwright browsers. # Nix mode: NO browser downloads.
#
# Playwright upstream "install" downloads ubuntu/fhs browser binaries into ~/.cache/ms-playwright.
# Those binaries often don't run on NixOS, producing ENOENT on launch (missing loader/libs).
#
# We keep this app for backwards-compat (tests/docs call it), but it is intentionally a NO-OP.
#
# IMPORTANT: Do not print anything to stdout (tests expect token-only stdout). # IMPORTANT: Do not print anything to stdout (tests expect token-only stdout).
exec ${pythonPlaywright}/bin/python -m playwright install chromium chromium-headless-shell 1>&2 {
echo "Playwright browsers are provided by nixpkgs (playwright-driver)."
echo "Using PLAYWRIGHT_BROWSERS_PATH=${playwrightDriver.browsers}"
echo "Set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 to prevent downloads."
} 1>&2
exit 0
''; '';
}; };
in in