Search code examples
pythonnix-shell

How to use nix-shell to install playwright from PyPi?


I am trying to create a nix-shell that installs python and playwright. My code does install python, but I cannot installed playwright properly.

with (import <nixpkgs> {});

let
  playwright = pkgs.python38Packages.buildPythonPackage rec {
    pname = "playwright";
    version = "1.12.1";

    src = pkgs.python38Packages.fetchPypi {
      inherit pname version;
    };

    propagatedBuildInputs = with pkgs.python38Packages; [];

    doCheck = false;
  };

  customPython = pkgs.python38.buildEnv.override {
    extraLibs = [ playwright ];
  };
in

pkgs.mkShell {
  buildInputs = [ customPython ];
}

And this gives me the following error:

while evaluating the attribute 'outPath' at /nix/store/gjqpc2i5nbi1yrzm0caaryvs8y1nhc8h-nixpkgs-21.11pre292293.84aa23742f6/nixpkgs/lib/customisation.nix:164:7:
while evaluating the attribute 'src' of the derivation 'python3.8-playwright-1.12.1' at /nix/store/gjqpc2i5nbi1yrzm0caaryvs8y1nhc8h-nixpkgs-21.11pre292293.84aa23742f6/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:201:11:
hash '' has wrong length for hash type 'sha256'

How can I fix its hash?


Solution

  • so you could put something along the lines of hash here:

        src = pkgs.python38Packages.fetchPypi {
          inherit pname version;
          data_sha256 = "sha256:<yourhash>"
        };
    

    while building your pkgs, so that it's defined explicitly (rn, its parsing it as '' as evident in the op)