playwright: [BUG] Can't run Playwright in Nix
Context:
- Playwright Version: 1.8.0
- Operating System: Linux
- Node.js version: 12
- Browser: All
Describe the bug
Running Playwright in Nix Shell throws missing dependencies error. Even after explicitly adding the missing dependencies suggested by “launch doctor”, the same error is thrown.
Error: browserType.launch: Host system is missing dependencies!
--
| Missing libraries we didn't find packages for:
| libexpat.so.1
| libxshmfence.so.1
Probably, I’m hitting this error from here. Nix has it’s own ldconfig and it’s not found in sbin.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 23
- Comments: 32 (3 by maintainers)
Commits related to this issue
- fix: Allow portable bash paths for systems including NixOS (#23889) Although very common, bash is not guaranteed to be located at `/bin/bash`. NixOS is an example of this. More commonly, `/bin/ba... — committed to microsoft/playwright by PatrickShaw a year ago
- fix: Allow portable bash paths for systems including NixOS (#23889) Although very common, bash is not guaranteed to be located at `/bin/bash`. NixOS is an example of this. More commonly, `/bin/ba... — committed to OctoMind-dev/playwright by PatrickShaw a year ago
Playwright package is now available in unstable channel. I got it working with nix flake by using following
flake.nixand then runningnix develop`flake.lock`
We can make it agnostic to nix: look if
ldconfigis onPATH, if not try/sbin/ldconfig, if that doesn’t exist either fail?@olebedev , would you mind sharing a repo link (or gist) for the Nix derivation you use to wrap playwright’s browser binaries as referenced in #5806? Or are you using the one linked above?
Apologies for commenting on an old issue; I considered sending an email, but figured asking in a public forum might help others with the same question.
Since the PR for skipping the host validation got merged and there won’t be official supported added we will close it for now, feel free to reopen / upvote it when there is a higher demand.
@pbek I haven’t tried devbox yet because I want to use as few additional utilities as possible. I simply specify the version (found on nixhub) of the nixpkgs that has the version of playwright I need.
For example, I need playwright v1.34:
@kylegentle, no, I use my own-written Nix derivation. It’s not just a code snippet so I need to go through the OSS request process within the company I work for, to make it public. I will keep you posted here.
A system can have multiple nix profiles. Which one is used is dependent on the environment started. These virtualizations only affect the
PATH(and a few other things like env) but not the file system, so changing a symlink is not really idiomatic as you would suddenly bind the static filesystem to a specific, arbitrary nix profile. On CI (where we intend to run this) it would mean that the symlink would point to a random profile or possibly nothing at all. I understand that an env var driving this might be an API we don’t want to introduce but what do you think about falling back from the entry inPATHto the hardcoded location or skipping use of ldconfig altogether like @uri-canva suggested?@ml2, yes that’s what I would have been done too. Meanwhile, I tried devbox, works great too to pin the version.
Applying a 3000 or 23000 line patch is guaranteed to break at some point. Unless those patches get split up into smaller ones, we cannot maintainable apply them to a source build unless we fetch the same exact version.
One more note when using our browser bundle on Linux instead of the Playwright-provided one: this does mean that you won’t be getting any Playwright-specific browser patches. Maybe someone from the Playwright team could weigh in on the implications here?
The Playwright package splits the browser bundle depending on the platform. For Linux,
playwright.browsersis a derivation that emulates what you get when runningplaywright install, but with the Nixpkgs version of each browser. As @aabccd021 mentioned, you will need to setPLAYWRIGHT_BROWSERS_PATHto this derivation, instead of having Playwright download the precompiled browsers. Try something like this:(Add
--no-linkto thenix buildstep if you don’t wan’t theresultsymlink to the browsers derivation). I just tested this using NixOS/nixpkgs@5a350a8f31bb7ef0c6e79aea3795a890cf7743d4 and it seems to work:If you’re on Darwin,
playwright.browserswill be the same bundle you get when runningplaywright install(the pre-built binaries by the Playwright team, including their patches), just as an FOD so we get the reproducibility. On Mac, using Playwright’s install script as @adam248 described should work as well, butplaywright.browsersin combination with the environment variable will keep everything in the Nix store.I have 22.11 with playwright installed through config… that may work for python, but packages that depend on playwright like Node Slidev still don’t work and you’ll get the dreaded message:
@uri-canva impressive!
So to double-check: the
ldconfigis the last thing that stops you folks from using playwright on nix?Would you be open to send a PR that detects *NIX system and disables launch doctor there? I cannot guarantee we land it, but we’ll discuss it. I’d appreciate if it’s as non-invasive as possible.
P.S. I apologize for all the questions - I have zero experience with NIX systems, and playing with it in docker was painful - there’s even no bash 🤷♂️
Is it possible to make the linked workaround configurable: https://github.com/microsoft/playwright/blob/a9faa9c941fa0b0383d68dff2fb7ef825bd258ea/src/server/validateDependencies.ts#L247-L250?
Note the commit message of https://github.com/aslushnikov/playwright/commit/aa3019bc8225abd463602481e3362fc61ea33b40
This is one case where it’s not located there, and loading it from there leads to broken behaviour.
@SamBreaksThings we don’t support Nix at the moment and this is the first request we’ve received regarding it so far.
So until there’s a huge demand for Nix support, this will be low-pri for us. Is there something easy we can do to enable you use Playwright on Nix?