26 src = fetchFromGitHub {
30 hash = "sha256-6ohh4NSYqJ+i1JRdsKbcJZns07c+roVJ87r0lvBbExU=";
35 url = "https://github.com/RapidAI/RapidOCR/releases/download/v1.1.0/required_for_whl_v1.3.0.zip";
36 hash = "sha256-j/0nzyvu/HfNTt5EZ+2Phe5dkyPOdQw/OZTz0yS63aA=";
39 + "/required_for_whl_v1.3.0/resources/models";
42 pname = "rapidocr-onnxruntime";
46 sourceRoot = "${src.name}/python";
49 # Upstream uses a very unconventional structure to organize the packages, and we have to coax the
50 # existing infrastructure to work with it.
51 # See https://github.com/RapidAI/RapidOCR/blob/02829ef986bc2a5c4f33e9c45c9267bcf2d07a1d/.github/workflows/gen_whl_to_pypi_rapidocr_ort.yml#L80-L92
52 # for the "intended" way of building this package.
54 # The setup.py supplied by upstream tries to determine the current version by
55 # fetching the latest version of the package from PyPI, and then bumping the version number.
56 # This is not allowed in the Nix build environment as we do not have internet access,
57 # hence we patch that out and get the version from the build environment directly.
59 (replaceVars ./setup-py-override-version-checking.patch {
65 mv setup_onnxruntime.py setup.py
66 mkdir -p rapidocr_onnxruntime/models
68 ln -s ${models}/* rapidocr_onnxruntime/models
70 # Magic patch from upstream - what does this even do??
71 echo "from .rapidocr_onnxruntime.main import RapidOCR, VisRes" > __init__.py
74 # Upstream expects the source files to be under rapidocr_onnxruntime/rapidocr_onnxruntime
75 # instead of rapidocr_onnxruntime for the wheel to build correctly.
77 mkdir rapidocr_onnxruntime_t
78 mv rapidocr_onnxruntime rapidocr_onnxruntime_t
79 mv rapidocr_onnxruntime_t rapidocr_onnxruntime
82 # Revert the above hack
84 mv rapidocr_onnxruntime rapidocr_onnxruntime_t
85 mv rapidocr_onnxruntime_t/* .
88 build-system = [ setuptools ];
102 pythonImportsCheck = [ "rapidocr_onnxruntime" ];
104 nativeCheckInputs = [
109 # These are tests for different backends.
110 disabledTestPaths = [
112 "tests/test_paddle.py"
116 # Needs Internet access
121 # This seems to be related to https://github.com/microsoft/onnxruntime/issues/10038
122 # Also some related issue: https://github.com/NixOS/nixpkgs/pull/319053#issuecomment-2167713362
123 badPlatforms = [ "aarch64-linux" ];
124 changelog = "https://github.com/RapidAI/RapidOCR/releases/tag/v${version}";
125 description = "Cross platform OCR Library based on OnnxRuntime";
126 homepage = "https://github.com/RapidAI/RapidOCR";
127 license = with lib.licenses; [ asl20 ];
128 maintainers = with lib.maintainers; [ pluiedev ];
129 mainProgram = "rapidocr_onnxruntime";