Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failure: playwright #215450

Closed
adam248 opened this issue Feb 9, 2023 · 23 comments
Closed

Build failure: playwright #215450

adam248 opened this issue Feb 9, 2023 · 23 comments
Labels
0.kind: build failure A package fails to build

Comments

@adam248
Copy link
Contributor

adam248 commented Feb 9, 2023

DISCLAIMER: I just installed NixOS for the first time (about a week ago) and I am IN LOVE!!! (and have a lot of passion right now) so excuse any over the top excitment

Steps To Reproduce

Steps to reproduce the behavior:

  1. build playwright on NixOS via the configuration.nix
  2. run the required playwright install command after install
  3. you will get a warning that BEWARE: your OS is not officially supported by Playwright; downloading fallback build.
  4. if you try to run any playwright commands after that you get the error (see at the end):

Additional context

Here is the BUG on the playwright's github package](microsoft/playwright#5501)

It sounds like they are willing to support NixOS if only someone from the Nix community will help them with the dependency management.

(This is what Nix does best people! Let's do this!)

Notify maintainers

@techknowlogick
@yrd
@SuperSandro2000

Metadata

playwright open

╔══════════════════════════════════════════════════════╗
║ Host system is missing dependencies to run browsers. ║
║ Missing libraries:                                   ║
║     libgobject-2.0.so.0                              ║
║     libglib-2.0.so.0                                 ║
║     libnss3.so                                       ║
║     libnssutil3.so                                   ║
║     libsmime3.so                                     ║
║     libnspr4.so                                      ║
║     libatk-1.0.so.0                                  ║
║     libatk-bridge-2.0.so.0                           ║
║     libcups.so.2                                     ║
║     libgio-2.0.so.0                                  ║
║     libdrm.so.2                                      ║
║     libdbus-1.so.3                                   ║
║     libatspi.so.0                                    ║
║     libX11.so.6                                      ║
║     libXcomposite.so.1                               ║
║     libXdamage.so.1                                  ║
║     libXext.so.6                                     ║
║     libXfixes.so.3                                   ║
║     libXrandr.so.2                                   ║
║     libgbm.so.1                                      ║
║     libexpat.so.1                                    ║
║     libxcb.so.1                                      ║
║     libxkbcommon.so.0                                ║
║     libpango-1.0.so.0                                ║
║     libcairo.so.2                                    ║
║     libasound.so.2                                   ║
║     libwayland-client.so.0                           ║
╚══════════════════════════════════════════════════════╝

@adam248 adam248 added the 0.kind: build failure A package fails to build label Feb 9, 2023
@adam248
Copy link
Contributor Author

adam248 commented Feb 9, 2023

Is there a way to make nix use the Microsoft playwright github repo to install directly onto NixOS?
I think the current version of playwright on nix is the Python wrapped version?
Not sure though... but I think playwright should be a standalone package in Nix (and a separate one for python as a a Python3Package)
The playwright package shouldn't depend on Python, it is the other way around. (I believe)
image

@adam248
Copy link
Contributor Author

adam248 commented Feb 9, 2023

Can we create a single default.nix and offer to add it to the Microsoft repo?
I am not sure if that is the Nix way, but it might help the maintainers of the playwright offival repo begin to understand how nix can help them even??? 🧎‍♂️ 2Birds1Rock?

@yrd
Copy link
Member

yrd commented Feb 9, 2023

Is there a way to make nix use the Microsoft playwright github repo to install directly onto NixOS?
Can we create a single default.nix and offer to add it to the Microsoft repo?

That would be what's called an IFD, which is not allowed in the Nixpkgs repository because it hinders parallelism while building.

I think the current version of playwright on nix is the Python wrapped version?

That's correct.

but I think playwright should be a standalone package in Nix

We've actually had this discussion before: #184511 (comment). Personally, I still don't think there's a need to split up the package any further than it already is. Correct me if I'm wrong, but Python shouldn't be a dependency on playwright.browsers (at least not on Linux, on Darwin it's a build-time dependency). So you can still set the environment variable as a described in your other issue when using the JavaScript library.

@adam248
Copy link
Contributor Author

adam248 commented Feb 9, 2023

thanks, I seemed to have missed #184511 in my previous search.
will read though soon.
Still wondering how to get the playwright CLI working (even if I am misunderstanding the wrapped version being ok) ...
maybe a playwright-cli version is needed that has all of its dependencies included... (will try to read a bit more...)

@adam248
Copy link
Contributor Author

adam248 commented Feb 9, 2023

After a quick second review, I can confirm that the official nix package playwright is not really made to be the playwright cli tool. It is mainly focused on being the Python library implementation of playwright from the MS playwright for python repo. This is misleading as far as I can tell...
image

As this is a Python library it is not built to be used as a cli tool but rather imported into a Nix-packaged Python project.
Once again, if I have misread anything, please let me know.
I do believe that having a Nix package called just playwright that is a Python library is confusing...

EDIT: I was just reading further and I might still be missing a few things...

@adam248
Copy link
Contributor Author

adam248 commented Feb 9, 2023

no, just tried to install dependencies with the CLI and no luck... It doesn't know how to install from Nix, it is looking for Ubuntu...

playwright install-deps chrome
BEWARE: your OS is not officially supported by Playwright; installing dependencies for Ubuntu as a fallback.
Installing dependencies...
Switching to root user to install dependencies...
sh: apt-get: not found
Failed to install browser dependencies
Error: Installation process exited with code: 127

@adam248
Copy link
Contributor Author

adam248 commented Feb 9, 2023

The thing is I know the browser dependencies are installed as I have firefox and chrome currently installed on my system and working.
playwright is just not symlinked correctly to Nix Store locations...
Any suggestion?
I noticed that someone mentioned using pythonPackages.playwright.browsers for Node as well, but I am neither trying to build a Node app nor a Python app, I just want to use the CLI tool.

@yrd
Copy link
Member

yrd commented Feb 9, 2023

Okay, a few points here:

  1. Are you running Ubuntu (or another distribution) with Nix install oder NixOS? Either way, running Playwright from Nixpkgs should work, as long as you're using the browser bundle from there as well, and not installing it through Playwright (and not using playwright install or playwright install-deps) .

  2. The playwright Python package includes a CLI. It's what you get when running python -m playwright. Python's packaging system (and by extension, Nixpkgs) exposes this as a playwright binary for convenience:

Example
$ nix build --impure --expr 'with builtins; with getFlake "nixpkgs"; legacyPackages.x86_64-linux.python3.withPackages (p: [p.playwright])'
$ ./result/bin/python -m playwright
Usage: playwright [options] [command]

Options:
  -V, --version                          output the version number
  -h, --help                             display help for command

Commands:
  open [options] [url]                   open page in browser specified via -b, --browser
  codegen [options] [url]                open page and generate code for user actions
  install [options] [browser...]         ensure browsers necessary for this version of Playwright are installed
  install-deps [options] [browser...]    install dependencies necessary to run browsers (will ask for sudo permissions)
  cr [options] [url]                     open page in Chromium
  ff [options] [url]                     open page in Firefox
  wk [options] [url]                     open page in WebKit
  screenshot [options] <url> <filename>  capture a page screenshot
  pdf [options] <url> <filename>         save page as pdf
  show-trace [options] [trace...]        show trace viewer
  help [command]                         display help for command
  1. playwright install-deps chrome won't work. This is expected, because Playwright doesn't know how to install dependencies on NixOS. You'll instead need use the browser bundle (which come with all dependencies in the closure) packaged in Nixpkgs.

All in all, if you want a CLI, try this one-liner:

PLAYWRIGHT_BROWSERS_PATH=$(nix build --print-out-paths --no-link nixpkgs#playwright.browsers) nix run nixpkgs#playwright -- open nixos.org 

the official nix package playwright is not really made to be the playwright cli tool

As mentioned above, the Nixpkgs package currently points to python3Packages.playwright, which includes the CLI. Although when developing using Playwright, you won't actually be needing the CLI. Set the PLAYWRIGHT_BROWSERS_PATH environment variable to the output of nixpkgs#playwright.browsers instead.

I know the browser dependencies are installed

You probably have system-wide Firefox and / or Chrome installations, which are completely independent of Playwright. In fact, this is also the case when using Playwright on non-Nix(OS), since playwright install would normally install custom browser builds which are only used by Playwright and nothing else.

@adam248
Copy link
Contributor Author

adam248 commented Feb 10, 2023

  1. I am running NixOS 22.11.2345.af96094e9b8 (Raccoon) x86_64 with no other OS on my system. I also have the unstable channel enabled for a few packages, but playwright is on stable so not relevant I think.
  2. This is what I believe I have misunderstood. Thank you. The CLI tool is a Python CLI script. (not a separate compiled binary.)
  3. Yes, I understand that. However, I am installing playwright in /etc/nixos/configuration.nix, and there isn't any information about how to install the browser bundle separately that I can see. I have installed it at the user level users.users.<myuser>.packages = with pkgs; [ playwright ];, should it be at the system level?
PLAYWRIGHT_BROWSERS_PATH=$(nix build --print-out-paths --no-link nixpkgs#playwright.browsers) nix run nixpkgs#playwright -- open nixos.org

Thank you very much for the script, it worked beautifully. This is advanced magic that I need to learn!

Finally, my main and last question is this, how can I setup my configuration.nix to have all this install on the system for easy reuse? Or is this script the only way available for now to run playwright directly.

Thank you very much for your help. 😀

Maybe we need a playwright page on https://nixos.wiki/
I'll see if I can draft up something...

@yrd
Copy link
Member

yrd commented Feb 10, 2023

Ah, now I see what you're trying to do 😉 If you're only looking for the CLI, try something like this:

{
  users.users.myuser.packages = [
    (pkgs.runCommand "wrapped-playwright" {} ''
      mkdir -p "$out/bin"
      makeWrapper "${pkgs.playwright}/bin/playwright" "$out/bin/playwright" \
        --set PLAYWRIGHT_BROWSERS_PATH "${pkgs.playwright.browsers}
    }))
  ];
}

This will create a new package with a single binary playwright, which is a script that executes the Playwright CLI preconfigured with the environment variable.

@adam248
Copy link
Contributor Author

adam248 commented Feb 11, 2023

Thank you very much.
Unfortunately, I tried adding it to my /etc/nixos/configuration.nix, my only config file at the moment.
This is the config that builds my entire OS.
I modified your example to fit with my current config.

users.users.adam = {
  isNormalUser = true;
  extraGroups = [ "wheel" "docker" "video" "audio" "networkmanager" "lp" "scanner" ];
  initalPassword = "...";
  packages = with pkgs; [
    (runCommand "wrapped-playwright" {} ''
    mkdir -p "$out/bin"
    makeWrapper "${playwright}/bin/playwright" "$out/bin/playwright" \
      -- set PLAYWRIGHT_BROWSERS_PATH "${playwright.browsers}"
  '')
  # my other packages for my sys are listed here below this ^ command
  ];
};

Ran: sudo nixos-rebuild switch
And got this error:

building Nix...
building the system configuration...
these 4 derivations will be built:
  /nix/store/bsx7xzh0sx2c23nbn2nn3b575rzql71m-wrapped-playwright.drv
  /nix/store/ng1i7fvj43pdrxdwr5havkjm6r4lsxir-user-environment.drv
  /nix/store/6y7145wam7pc4j479basmxpyz0mvpsxp-etc.drv
  /nix/store/j0x3ajrq8i0gv0dinwkzrrbm7xw0jjw4-nixos-system-nxbx-dsktp-22.11.2483.49efda9011e.drv
building '/nix/store/bsx7xzh0sx2c23nbn2nn3b575rzql71m-wrapped-playwright.drv'...
/build/.attr-0l2nkwhif96f51f4amnlf414lhl4rv9vh8iffyp431v6s28gsr90: line 2: makeWrapper: command not found
error: builder for '/nix/store/bsx7xzh0sx2c23nbn2nn3b575rzql71m-wrapped-playwright.drv' failed with exit code 127
error: 1 dependencies of derivation '/nix/store/ng1i7fvj43pdrxdwr5havkjm6r4lsxir-user-environment.drv' failed to build
error: 1 dependencies of derivation '/nix/store/6y7145wam7pc4j479basmxpyz0mvpsxp-etc.drv' failed to build
error: 1 dependencies of derivation '/nix/store/j0x3ajrq8i0gv0dinwkzrrbm7xw0jjw4-nixos-system-nxbx-dsktp-22.11.2483.49efda9011e.drv' failed to build

I tried to add makeWrapper to the initial imports but it didn't work the way I thought it would.
I tried reading the docs about makeWrapper but they were all talking about package building not system wide configurations, so I wasn't sure how to apply the knowledge to my global config.

Should I start making a "sub" config where these special wrapper commands go?
Then reference/include them in my main config?

@yrd
Copy link
Member

yrd commented Feb 11, 2023

Dammit, I forgot to add makeWrapper in my snippet. Try replacing the runCommand line with this:

(runCommand "wrapped-playwright" { buildInputs = [ pkgs.makeWrapper ]; } ''

Edit: If you want to learn more about makeWrapper and runCommand, have a look here: https://nixos.wiki/wiki/Nix_Cookbook (See the section on wrapping packages)

@adam248
Copy link
Contributor Author

adam248 commented Feb 11, 2023

      (runCommand "wrapped-playwright" { buildInputs = [ makeWrapper ]; } ''
      mkdir -p "$out/bin"
      makeWrapper "${playwright}/bin/playwright" "$out/bin/playwright" \
        --set PLAYWRIGHT_BROWSERS_PATH "${playwright.browsers}"
      '')

Worked like a charm!
Thank you so much.
AND I LEARNT STUFF TOOO!

playwright open nixos.org
works as expected...
Nix is the coolest thing ever!

@adam248
Copy link
Contributor Author

adam248 commented Feb 11, 2023

I used to use Arch BTW... lol
goodbye building from source!!!!

@yrd
Copy link
Member

yrd commented Feb 11, 2023

Awesome, glad to hear!
I'll close this for now, feel free to reopen if you find any more bugs.

@yrd yrd closed this as completed Feb 11, 2023
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/running-playwright-tests/25655/1

@pbek
Copy link
Contributor

pbek commented Apr 27, 2023

Should the playwright.browsers part still work? I always get at:

error: attribute 'browsers' missing

       at /etc/nixos/hosts/gaia/configuration.nix:59:43:

           58|       makeWrapper "${playwright}/bin/playwright" "$out/bin/playwright" \
           59|         --set PLAYWRIGHT_BROWSERS_PATH "${playwright.browsers}"
             |                                           ^
           60|       '')

my config:

  users.users.omega = {
    packages = with pkgs; [
      playwright
      (runCommand "wrapped-playwright" { buildInputs = [ makeWrapper ]; } ''
      mkdir -p "$out/bin"
      makeWrapper "${playwright}/bin/playwright" "$out/bin/playwright" \
        --set PLAYWRIGHT_BROWSERS_PATH "${playwright.browsers}"
      '')
    ];
  };

@teto
Copy link
Member

teto commented Apr 27, 2023

There was a bit of shuffling recently and playwright.browsers does'nt exist anymore pkgs/development/python-modules/playwright/default.nix . You can use playwright-driver.browsers instead.
Btw I am looking for insight on how people use playwright if you wanna comment on #217693
You might be interested in trying out #227071 too

@pbek
Copy link
Contributor

pbek commented Apr 28, 2023

This went through now, thank you:

  users.users.omega = {
    packages = with pkgs; [
      playwright
      (runCommand "wrapped-playwright" { buildInputs = [ makeWrapper ]; } ''
      mkdir -p "$out/bin"
      makeWrapper "${playwright}/bin/playwright" "$out/bin/playwright" \
        --set PLAYWRIGHT_BROWSERS_PATH "${playwright-driver.browsers}"
      '')
    ];
  };

But when I did a playwright install and then a playwright open nixos.org, I still got:

[Error: 
╔══════════════════════════════════════════════════════╗
║ Host system is missing dependencies to run browsers. ║
║ Missing libraries:                                   ║
║     libgobject-2.0.so.0                              ║
║     libglib-2.0.so.0                                 ║
║     libnss3.so                                       ║
║     libnssutil3.so                                   ║
║     libsmime3.so                                     ║
║     libnspr4.so                                      ║
║     libatk-1.0.so.0                                  ║
║     libatk-bridge-2.0.so.0                           ║
║     libcups.so.2                                     ║
║     libgio-2.0.so.0                                  ║
║     libdrm.so.2                                      ║
║     libdbus-1.so.3                                   ║
║     libatspi.so.0                                    ║
║     libX11.so.6                                      ║
║     libXcomposite.so.1                               ║
║     libXdamage.so.1                                  ║
║     libXext.so.6                                     ║
║     libXfixes.so.3                                   ║
║     libXrandr.so.2                                   ║
║     libgbm.so.1                                      ║
║     libexpat.so.1                                    ║
║     libxcb.so.1                                      ║
║     libxkbcommon.so.0                                ║
║     libpango-1.0.so.0                                ║
║     libcairo.so.2                                    ║
║     libasound.so.2                                   ║
╚══════════════════════════════════════════════════════╝]

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/running-playwright-tests/25655/8

@teto
Copy link
Member

teto commented Apr 28, 2023

@pbek the browsers installed by playwright install wont work on nixos as you noticed, they can't link dynamically. Your playwright should use the browsers passed via PLAYWRIGHT_BROWSERS_PATH. What might happen (I am still new to playwright) is that playwright is picky when it comes to browser choice, the folder must be named with the same version as your plawyright. Maybe let's stop hijacking this thread and create a new one with a proper Minimal Working Example, ideally a test we could just add to nixpkgs ?

@pbek
Copy link
Contributor

pbek commented Apr 28, 2023

I need to get back to a system where I don't have nixos on first to produce a working playwright test. 😆

@pbek
Copy link
Contributor

pbek commented May 3, 2023

I took this over to #227071 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: build failure A package fails to build
Projects
None yet
Development

No branches or pull requests

5 participants