Poetry2nix: mismatch cryptography sha256 but unable to modify

I have the derivation reported at the end of this post but when I am building it with nix-shell I get the following trace message “trace: warning: Unknown cryptography version: ‘41.0.4’. Please update getCargoHash.”

and then the run fails with the following error

installing
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/lr06kyfn2nzxq718jf5c2mw00kz5ir5f-cryptography-41.0.4-vendor.tar.gz
checking for references to /build/ in /nix/store/lr06kyfn2nzxq718jf5c2mw00kz5ir5f-cryptography-41.0.4-vendor.tar.gz...
patching script interpreter paths in /nix/store/lr06kyfn2nzxq718jf5c2mw00kz5ir5f-cryptography-41.0.4-vendor.tar.gz
error: hash mismatch in fixed-output derivation '/nix/store/9dflz91pqq7h80fkgbya62q3109vspfh-cryptography-41.0.4-vendor.tar.gz.drv':
         specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
            got:    sha256-oXR8yBUgiA9BOfkZKBJneKWlpwHB71t/74b/5WpiKmw=
error: building '/nix/store/9dflz91pqq7h80fkgbya62q3109vspfh-cryptography-41.0.4-vendor.tar.gz.drv' failed
building '/nix/store/vjmlv1fhlhhrlbjsmcww2283d7xf1d1f-importlib_resources-6.1.0.tar.gz.drv'...
error: 1 dependencies of derivation '/nix/store/npn8q9bml5mwgdwgznhy9axxw0nxvbxp-python3.10-cryptography-41.0.4.drv' failed to build
error: building '/nix/store/npn8q9bml5mwgdwgznhy9axxw0nxvbxp-python3.10-cryptography-41.0.4.drv' failed
error: 1 dependencies of derivation '/nix/store/9k75i6rg9vfcncfsrf3sigpi6wr82g0b-python3-3.10.12-env.drv' failed to build
error: building '/nix/store/9k75i6rg9vfcncfsrf3sigpi6wr82g0b-python3-3.10.12-env.drv' failed

This looks really strange because I do not know how to solve it and also because it looks like the sha256 that I am setting is not the one that Nix will match. I read also cryptography 35 · Issue #413 · nix-community/poetry2nix · GitHub but I was not able to solve the problem.

There is someone who can help me understand and solve the problem?

Thanks!

let
  # Import nixpkgs
  pkgs = import <nixpkgs> { };

  # Import poetry2nix and its functions
  poetry2nix = pkgs.poetry2nix;

  # Create a Python environment using poetry2nix
  finalEnv = poetry2nix.mkPoetryEnv {
    python = pkgs.python310;
    projectDir = ../../.;
    poetrylock = ../../poetry.lock; # Path to your poetry.lock file
    overrides = poetry2nix.overrides.withDefaults (self: super: {
      attrs = super.attrs.overridePythonAttrs
        (old: { buildInputs = old.buildInputs or [ ] ++ [ super.hatchling ]; });
      protobuf3 = super.protobuf3.overridePythonAttrs (old: {
        buildInputs = old.buildInputs or [ ] ++ [ super.setuptools ];
      });
      werkzeug = super.werkzeug.overridePythonAttrs
        (old: { buildInputs = old.buildInputs or [ ] ++ [ self.flit-core ]; });

      flask = super.flask.overridePythonAttrs
        (old: { buildInputs = old.buildInputs or [ ] ++ [ self.flit-core ]; });

      execnet = super.execnet.overridePythonAttrs
        (old: { buildInputs = old.buildInputs or [ ] ++ [ self.hatchling ]; });

      cryptography = super.cryptography.overrideAttrs (oldAttrs: {
        src = pkgs.fetchurl {
          url = "https://pypi.io/packages/source/c/cryptography/cryptography-41.0.4.tar.gz";
          sha256 = "oXR8yBUgiA9BOfkZKBJneKWlpwHB71t/74b/5WpiKmw=";
        };
      });
    });
  };
in with pkgs;
stdenv.mkDerivation {
  name = "git-dev-nix-env";

  buildInputs = [
    gcc
    sqlite
    autoconf
    git
    clang
    libtool
    sqlite
    autoconf
    autogen
    automake
    gnumake
    pkg-config
    gmp
    zlib
    gettext
    libsodium

    # Python dep
    poetry
    python310
    python310Packages.pip
    python310Packages.pytest
    python310Packages.setuptools
    finalEnv # Add the poetry environment here

    # optional dev libraries
    ccache

    # debugs libraries
    valgrind

    # Indirected dependencies for running tests
    bitcoind
  ];

  nativeBuildInputs = [ python310Packages.setuptools ];
  propagatedBuildInputs = [ python310Packages.setuptools ];
}

This was a bug in poetry2nix that has been resolved in the recent version on the master branch.

Since it will take some time before this fix reaches a stable release, I’ve posted a workaround to address the issue I originally mentioned in my blog post.

I imported poetry2nix using the following code:

  # Import nixpkgs
  pkgs = import <nixpkgs> { };

  # Import poetry2nix and its functions
  poetry2nixSrc = pkgs.fetchFromGitHub {
    owner = "nix-community";
    repo = "poetry2nix";
    rev = "master"; # Fetch the latest master
    sha256 = "sha256-p6niqag7b4XEHvzWgG0X/xjoW/ZXbAxW8ggd8yReT3Y=";
  };

  poetry2nix = import poetry2nixSrc { };