nix-playwright

Configures Nix-based local execution of Playwright e2e test suites on NixOS.

957|79|Updated May 9, 2021
One-click install
npx skills add https://github.com/srid/emanote --skill nix-playwright
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nix-playwright
Source: https://github.com/srid/emanote/tree/main/.agents/skills/nix-playwright
Command: npx skills add https://github.com/srid/emanote --skill nix-playwright

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Playwright's bundled Chromium download relies on apt-get and sudo, which fails on NixOS and pure-Nix hosts. This Skill provides a self-contained Nix setup so an existing Playwright e2e suite can run locally without modifying GitHub Actions CI.

Core Features & Use Cases

  • Self-contained tests/shell.nix: Resolves a pinned nixpkgs-latest input from the parent flake lock and exposes playwright-driver.browsers via PLAYWRIGHT_BROWSERS_PATH.
  • Decoupled flake input: Adds an independent nixpkgs-latest pin so the Playwright browser revision updates on its own cadence, separate from the main nixpkgs.
  • Justfile recipe: Provides an e2e target that enters the nix-shell, installs npm dependencies if missing, and runs the test suite.
  • Use Case: A developer on NixOS clones a project with a Playwright suite under tests/ and needs npm test to work locally without apt-based browser installation.

Quick Start

Set up my existing Playwright e2e tests to run locally on NixOS using a Nix shell and a justfile recipe.

Frequently Asked Questions about nix-playwright

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run Playwright tests on NixOS?

Create a tests/shell.nix that imports a pinned nixpkgs and sets PLAYWRIGHT_BROWSERS_PATH to pkgs.playwright-driver.browsers with PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1. Then run the suite inside nix-shell, since npx playwright install --with-deps does not work on NixOS.

Why does Playwright fail with browser revision not found on Nix?

This error occurs when the pkgs.playwright-driver version drifts from the playwright version in tests/package.json. Fix it by running nix flake update nixpkgs-latest, matching the package.json version to the new driver, and regenerating the lockfile with npm install.

Does this Nix Playwright setup replace GitHub Actions CI?

No, GitHub Actions CI is left untouched because apt-provided Chromium on Ubuntu runners is cheaper than a Nix devshell. This setup targets local runs and Nix-based CI systems like Vira only.

How do I pin a separate nixpkgs version for Playwright browsers?

Add an independent flake input such as inputs.nixpkgs-latest.url = "github:nixos/nixpkgs/nixpkgs-unstable". The tests/shell.nix then reads the parent flake.lock to resolve that pin without needing a flake context.

Can I use this approach without an existing Playwright test suite?

No, this pattern assumes a project already has a Playwright e2e suite, typically under tests/. It only provides the Nix shell environment and justfile entry to run that suite locally on Nix-based systems.