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

playwright-test: Add PLAYWRIGHT_BROWSERS_PATH to build environment #368391

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

the-sun-will-rise-tomorrow
Copy link
Contributor

This allows writing self-contained node scripts (using a nix-shell shebang), without requiring a separate shell.nix which sets PLAYWRIGHT_BROWSERS_PATH to pkgs.playwright-driver.browsers.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

Copy link
Contributor

@kalekseev kalekseev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need --set-default PLAYWRIGHT_BROWSERS_PATH "${playwright-core.passthru.browsers}" in makeWrapper?

Also the python library needs the same changes.

@@ -191,9 +192,25 @@ let
runHook postInstall
'';

setupHook = writeText "setupHook.sh" ''
addBrowsersPath () {
export PLAYWRIGHT_BROWSERS_PATH="${playwright-core.passthru.browsers}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to override this var? if user wants to run his script with different browsers path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, you can override it as usual (by setting it in the environment before running the script).

I think overlays etc. should still work too? Or do we need to use pkgs.playwright-driver instead of the local playwright-core definition to pull in customizations? There's a few references to playwright-core already...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Playwright package named core but in nixpkgs it was named driver initially and we keep it for backward compatibility. Would be nice to migrate to core eventually but at the moment playwright PRs are waiting for months before someone review and merge them so let's use driver

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't mean the name, but whether we're using the definition from pkgs so that overrides apply. I think that if we want to make packages overridable with things like overlays or overrideAttrs, then we have to use finalAttrs or import ourselves and use that to refer to our package instead of using what we defined directly.

Let me try a few things...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I don't see any way to override the browser derivation.

I see that in #344614 the browsers were wrapped in makeOverridable, but that was so that a user can customize and use just the browsers (by setting PLAYWRIGHT_BROWSERS_PATH to point to them), not for building a Node or Python package that uses a different set of browsers in its wrapped scripts.

So, it looks like doing it that way was never possible, but we are not making it worse here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to override this var? if user wants to run his script with different browsers path

Actually forgot about the case if the user sets the variable before running nix-shell (and doesn't use --pure). Changed it so we set it only if it's unset.

@the-sun-will-rise-tomorrow
Copy link
Contributor Author

Do we still need --set-default PLAYWRIGHT_BROWSERS_PATH "${playwright-core.passthru.browsers}" in makeWrapper?

Yes, it's still useful, as that creates a praywright command that will run with the correct value from any environment. The setupHook can only apply to things that use the package as a dependency (which includes nix-shell and nix-shell shebangs).

Also the python library needs the same changes.

OK, added.

@@ -101,6 +112,9 @@ buildPythonPackage rec {
{
driver = playwright-driver;
browsers = playwright-driver.browsers;
env = runCommand "playwright-env-test" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have playwright test that uses python package, I guess we can remove this var in it https://github.com/nixos/nixpkgs/blob/26713f779299cd4688ef2f35e7f19cbc2e207f79/nixos/tests/playwright-python.nix#L15 to test the setupHook

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change will not apply to that test. There, we don't run Playwright from a derivation directly, but instead use writePython3Bin which will create a command that we will then run from outside later, with a different environment that won't have that variable.

@ofborg ofborg bot requested review from kalekseev, yrd and techknowlogick December 27, 2024 09:40
This allows writing self-contained node scripts (using a nix-shell
shebang), without requiring a separate shell.nix which sets
PLAYWRIGHT_BROWSERS_PATH to pkgs.playwright-driver.browsers.
…ironment

This allows writing self-contained Python scripts (using a nix-shell
shebang), without requiring a separate shell.nix which sets
PLAYWRIGHT_BROWSERS_PATH to pkgs.playwright-driver.browsers.
Copy link
Contributor

@kalekseev kalekseev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ofborg ofborg bot requested a review from kalekseev December 27, 2024 10:51
@wegank wegank added 12.approvals: 1 This PR was reviewed and approved by one reputable person 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in the package labels Dec 29, 2024
@kalekseev kalekseev requested a review from teto December 30, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: python 10.rebuild-darwin: 11-100 10.rebuild-linux: 11-100 12.approvals: 1 This PR was reviewed and approved by one reputable person 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in the package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants