OpenSSL error during `uv tool install typ2docx`

Hi,

When I tried to install typ2docx by running uv tool install typ2docx, it failed with this error:

      warning: openssl-sys@0.9.111: Could not find directory of OpenSSL installation, and this `-sys` crate cannot proceed without this knowledge. If
      OpenSSL is installed and this crate had trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the compilation process. See
      stderr section below for further information.
      error: failed to run custom build command for `openssl-sys v0.9.111`

      Caused by:
        process didn't exit successfully:
      `/home/behrangsa/.cache/uv/sdists-v9/pypi/typ2docx/0.8.0/vdgj2pA-lwkUFA0QykDoe/src/target/release/build/openssl-sys-247bc3c82a33c366/build-script-main`
      (exit status: 101)
        --- stdout
        cargo:rustc-check-cfg=cfg(osslconf, values("OPENSSL_NO_OCB", "OPENSSL_NO_SM4", "OPENSSL_NO_SEED", "OPENSSL_NO_CHACHA", "OPENSSL_NO_CAST",
      "OPENSSL_NO_IDEA", "OPENSSL_NO_CAMELLIA", "OPENSSL_NO_RC4", "OPENSSL_NO_BF", "OPENSSL_NO_PSK", "OPENSSL_NO_DEPRECATED_3_0", "OPENSSL_NO_SCRYPT",
      "OPENSSL_NO_SM3", "OPENSSL_NO_RMD160", "OPENSSL_NO_EC2M", "OPENSSL_NO_OCSP", "OPENSSL_NO_CMS", "OPENSSL_NO_COMP", "OPENSSL_NO_SOCK",
      "OPENSSL_NO_STDIO", "OPENSSL_NO_EC", "OPENSSL_NO_SSL3_METHOD", "OPENSSL_NO_KRB5", "OPENSSL_NO_TLSEXT", "OPENSSL_NO_SRP", "OPENSSL_NO_SRTP",
      "OPENSSL_NO_RFC3779", "OPENSSL_NO_SHA", "OPENSSL_NO_NEXTPROTONEG", "OPENSSL_NO_ENGINE", "OPENSSL_NO_BUF_FREELISTS", "OPENSSL_NO_RC2"))
        cargo:rustc-check-cfg=cfg(openssl)
        cargo:rustc-check-cfg=cfg(libressl)
        cargo:rustc-check-cfg=cfg(boringssl)
        cargo:rustc-check-cfg=cfg(awslc)
        cargo:rustc-check-cfg=cfg(libressl250)
        cargo:rustc-check-cfg=cfg(libressl251)
        cargo:rustc-check-cfg=cfg(libressl252)
        cargo:rustc-check-cfg=cfg(libressl261)
        cargo:rustc-check-cfg=cfg(libressl270)
        cargo:rustc-check-cfg=cfg(libressl271)
        cargo:rustc-check-cfg=cfg(libressl273)
        cargo:rustc-check-cfg=cfg(libressl280)
        cargo:rustc-check-cfg=cfg(libressl281)
        cargo:rustc-check-cfg=cfg(libressl291)
        cargo:rustc-check-cfg=cfg(libressl310)
        cargo:rustc-check-cfg=cfg(libressl321)
        cargo:rustc-check-cfg=cfg(libressl332)
        cargo:rustc-check-cfg=cfg(libressl340)
        cargo:rustc-check-cfg=cfg(libressl350)
        cargo:rustc-check-cfg=cfg(libressl360)
        cargo:rustc-check-cfg=cfg(libressl361)
        cargo:rustc-check-cfg=cfg(libressl370)
        cargo:rustc-check-cfg=cfg(libressl380)
        cargo:rustc-check-cfg=cfg(libressl381)
        cargo:rustc-check-cfg=cfg(libressl382)
        cargo:rustc-check-cfg=cfg(libressl390)
        cargo:rustc-check-cfg=cfg(libressl400)
        cargo:rustc-check-cfg=cfg(libressl410)
        cargo:rustc-check-cfg=cfg(libressl420)
        cargo:rustc-check-cfg=cfg(ossl101)
        cargo:rustc-check-cfg=cfg(ossl102)
        cargo:rustc-check-cfg=cfg(ossl102f)
        cargo:rustc-check-cfg=cfg(ossl102h)
        cargo:rustc-check-cfg=cfg(ossl110)
        cargo:rustc-check-cfg=cfg(ossl110f)
        cargo:rustc-check-cfg=cfg(ossl110g)
        cargo:rustc-check-cfg=cfg(ossl110h)
        cargo:rustc-check-cfg=cfg(ossl111)
        cargo:rustc-check-cfg=cfg(ossl111b)
        cargo:rustc-check-cfg=cfg(ossl111c)
        cargo:rustc-check-cfg=cfg(ossl111d)
        cargo:rustc-check-cfg=cfg(ossl300)
        cargo:rustc-check-cfg=cfg(ossl310)
        cargo:rustc-check-cfg=cfg(ossl320)
        cargo:rustc-check-cfg=cfg(ossl330)
        cargo:rustc-check-cfg=cfg(ossl340)
        cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR
        X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR unset
        cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
        OPENSSL_LIB_DIR unset
        cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR
        X86_64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR unset
        cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
        OPENSSL_INCLUDE_DIR unset
        cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_DIR
        X86_64_UNKNOWN_LINUX_GNU_OPENSSL_DIR unset
        cargo:rerun-if-env-changed=OPENSSL_DIR
        OPENSSL_DIR unset
        cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
        cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
        cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
        cargo:rerun-if-env-changed=HOST_PKG_CONFIG
        cargo:rerun-if-env-changed=PKG_CONFIG
        cargo:rerun-if-env-changed=OPENSSL_STATIC
        cargo:rerun-if-env-changed=OPENSSL_DYNAMIC
        cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
        cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
        cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
        cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
        cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
        cargo:rerun-if-env-changed=PKG_CONFIG_PATH
        cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
        cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
        cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
        cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
        cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
        cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
        cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
        cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR


        Could not find openssl via pkg-config:

        pkg-config exited with status code 1
        > PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags openssl

        The system library `openssl` required by crate `openssl-sys` was not found.
        The file `openssl.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
        The PKG_CONFIG_PATH environment variable is not set.

        HINT: if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing `openssl.pc`.


        cargo:warning=Could not find directory of OpenSSL installation, and this `-sys` crate cannot proceed without this knowledge. If OpenSSL is
      installed and this crate had trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the compilation process. See stderr section
      below for further information.

        --- stderr


        Could not find directory of OpenSSL installation, and this `-sys` crate cannot
        proceed without this knowledge. If OpenSSL is installed and this crate had
        trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
        compilation process.

        Make sure you also have the development packages of openssl installed.
        For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

        If you're in a situation where you think the directory *should* be found
        automatically, please open a bug at https://github.com/rust-openssl/rust-openssl
        and include information about your system as well as this message.

        $HOST = x86_64-unknown-linux-gnu
        $TARGET = x86_64-unknown-linux-gnu
        openssl-sys = 0.9.111


      warning: build failed, waiting for other jobs to finish...
      💥 maturin failed
        Caused by: Failed to build a native library through cargo
        Caused by: Cargo build finished with "exit status: 101": `env -u CARGO PYO3_BUILD_EXTENSION_MODULE="1"
      PYO3_ENVIRONMENT_SIGNATURE="cpython-3.13-64bit" PYO3_PYTHON="/home/behrangsa/.cache/uv/builds-v0/.tmp5zWsi8/bin/python"
      PYTHON_SYS_EXECUTABLE="/home/behrangsa/.cache/uv/builds-v0/.tmp5zWsi8/bin/python" "cargo" "rustc" "--profile" "release" "--message-format"
      "json-render-diagnostics" "--manifest-path" "/home/behrangsa/.cache/uv/sdists-v9/pypi/typ2docx/0.8.0/vdgj2pA-lwkUFA0QykDoe/src/Cargo.toml" "--lib"`
      Error: command ['maturin', 'pep517', 'build-wheel', '-i', '/home/behrangsa/.cache/uv/builds-v0/.tmp5zWsi8/bin/python', '--compatibility', 'off']

Any ideas how can I work around this problem?

Just FYI, I already have these instructions/stanzas in my configuration.nix file:

  programs.nix-ld = {
    enable = true;
    libraries = with pkgs; [
      # Core libraries for Rust binaries (like biomejs)
      stdenv.cc.cc.lib  # Provides libstdc++.so.6 and libgcc_s.so.1
      glibc             # Provides libc.so.6, libm.so.6, libdl.so.2, librt.so.1, libpthread.so.0

      # Additional libraries commonly needed by Node.js binary packages
      zlib            # Common compression library
      libgcc          # GCC runtime library
      openssl         # For packages with HTTPS/crypto needs
      icu             # For packages with internationalization
      libuuid         # For packages generating UUIDs
    ];
  };

Thanks in advance.

This would be more fruitful than messing with nix-ld (and I see even upstream is helping out here):

2 Likes

@behrangsa Author of typ2docx here. Thanks for trying out the tool. uv is supposed to take care of the whole installation and manage the environment. I’ve encountered similar issue when creating the web service for this tool. It turned out that I had to install openssl-dev to make it compile:

FROM rust:alpine AS typ2docx
RUN apk add pkgconfig openssl-dev gcompat
COPY pyproject.toml /
# TODO: Alpine 3.22 on x86_64 doesn’t have latest uv
RUN wget -qO- https://astral.sh/uv/install.sh | sh
RUN /root/.local/bin/uv tool install typ2docx --python-platform x86_64-manylinux_2_40 --verbose

Give this a shot. If that’s the solution I’ll add it to the readme.

1 Like

Hi all,

In the meantime, I managed to work around it using this shell.nix file:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = with pkgs; [
    uv
    openssl
    pkg-config
    stdenv.cc.cc.lib
    zlib
  ];

  # This automatically sets up the path for any binary that needs these libs
  shellHook = ''
    export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath [
      pkgs.stdenv.cc.cc.lib
      pkgs.zlib
    ]}:$LD_LIBRARY_PATH"
  '';
}

Without zlib I was getting another error:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/tmp/nix-shell-358311-718893023/typ2docx_kiztxgmw/saxon.py", line 3, in <module>
    from saxonche import PySaxonProcessor
ImportError: libz.so.1: cannot open shared object file: No such file or directory
Error: Failed to merge DOCX with Saxon

Hello, you can try out the latest commits in the PR mentioned above. I updated it so it should work now.

1 Like

How can I test that commit?

NIXPKGS_ALLOW_UNFREE=1 nix-shell -p typ2docx -I nixpkgs=https://github.com/NixOS/nixpkgs/tarball/d90d7f94017c153dc00871e07f530fee2cd2ecef

Try this.(You can get the sha1 of the commit from the pr above)

1 Like

Hi,

This worked too ( after compiling half the internet :wink: ).

typ2docx main.typ -e pdf2docx
Converting TYP -> PDF with Typst
Extracting math source code
Extracted 0 math blocks
Converting TYP -> DOCX with Pandoc
Converting PDF -> DOCX with pdf2docx
[INFO] Start to convert /tmp/nix-shell-710756-4171229059/typ2docx_6y5h67f7/a.pdf
[INFO] [1/4] Opening document...
[INFO] [2/4] Analyzing document...
[INFO] [3/4] Parsing pages...
[INFO] (1/23) Page 1
[INFO] (2/23) Page 2
[INFO] (3/23) Page 3
...
[INFO] (21/23) Page 21
[INFO] (22/23) Page 22
[INFO] (23/23) Page 23
[INFO] [4/4] Creating pages...
[INFO] (1/23) Page 1
[INFO] (2/23) Page 2
[INFO] (3/23) Page 3
[INFO] (4/23) Page 4
...
[INFO] (21/23) Page 21
[INFO] (22/23) Page 22
[INFO] (23/23) Page 23
[INFO] Terminated in 3.38s.
Merging DOCX
Output saved to /home/behrangsa/foo/main.docx