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

libpcsclite.so.1 not found on NixOS #71

Open
StarGate01 opened this issue Sep 22, 2022 · 4 comments
Open

libpcsclite.so.1 not found on NixOS #71

StarGate01 opened this issue Sep 22, 2022 · 4 comments

Comments

@StarGate01
Copy link

StarGate01 commented Sep 22, 2022

Due to the hard-coded paths to libpcsclite.so.1 at https://github.com/martinpaljak/apdu4j/blob/master/pcsc/src/main/java/apdu4j/pcsc/TerminalManager.java#L54 , the PC/SC library cannot be found on the NixOS Linux distribution, which does not use the Filesystem Hierarchy Standard (/lib etc.), and instead relies on a hash-based content store.

strace reports multiple failed attempts to access the pcsc library:

[pid 36391] newfstatat(AT_FDCWD, "/usr/lib64/libpcsclite.so", 0x7f05c34d59b0, 0) = -1 ENOENT (No such file or directory)
[pid 36391] newfstatat(AT_FDCWD, "/usr/local/lib64/libpcsclite.so", 0x7f05c34d59b0, 0) = -1 ENOENT (No such file or directory)
[pid 36391] openat(AT_FDCWD, "/nix/store/wl6h3dcaw0c8ra3bdqqlyj1w2s9bxax4-sane-config/lib/sane/libpcsclite.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 36391] openat(AT_FDCWD, "/nix/store/fz54faknl123dimzz6jsppw193lx2mip-glibc-2.35-163/lib/libpcsclite.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 36391] openat(AT_FDCWD, "/nix/store/wl6h3dcaw0c8ra3bdqqlyj1w2s9bxax4-sane-config/lib/sane/libpcsclite.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 36391] openat(AT_FDCWD, "/nix/store/fz54faknl123dimzz6jsppw193lx2mip-glibc-2.35-163/lib/libpcsclite.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 36391] openat(AT_FDCWD, "/nix/store/wl6h3dcaw0c8ra3bdqqlyj1w2s9bxax4-sane-config/lib/sane/libpcsclite.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 36391] openat(AT_FDCWD, "/nix/store/fz54faknl123dimzz6jsppw193lx2mip-glibc-2.35-163/lib/libpcsclite.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 36391] openat(AT_FDCWD, "/nix/store/wl6h3dcaw0c8ra3bdqqlyj1w2s9bxax4-sane-config/lib/sane/libpcsclite.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
[pid 36391] openat(AT_FDCWD, "/nix/store/fz54faknl123dimzz6jsppw193lx2mip-glibc-2.35-163/lib/libpcsclite.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

The correct path would be /nix/store/0cdj8mkp03sh1yw9bnkg1sircj99scvp-pcsclite-1.9.5/lib/libpcsclite.so, generated from the Nix statement "${lib.getLib pkgs.pcsclite}/lib/libpcsclite.so".

I understand that supporting such edge-cases is probably not your priority, however a simple patch would maybe allow for an easy workaround: Add libpcsclite.so.1 without any directory path to the locations to be checked, such that I can add the correct path to the library to my PATH and have the program find it. Does the library loader respect the PATH environment variable anyway?

Thanks for any help or ideas.

@martinpaljak
Copy link
Owner

The whole funk in apdu4j with the library paths is to provide "works out of the box" adjustments, to not require tweaking JVM-s with library paths. So everything related to it is a bug/missing feature. Of course, things have improved a lot from JDK1.7 times...

@StarGate01
Copy link
Author

I have since fixed this by setting JAVA_OPTIONS = "-Dsun.security.smartcardio.library=${lib.getLib pkgs.pcsclite}/lib/libpcsclite.so"

see also: NixOS/nixpkgs#46840 (comment)

@martinpaljak
Copy link
Owner

Does this have a full path or is the variable present in environment? It should work without additional java options, so please don't close the issue

@martinpaljak martinpaljak reopened this Oct 26, 2022
@StarGate01
Copy link
Author

StarGate01 commented Oct 26, 2022

Due to the way Nix works, the variable is available during compile time; it evaluates to e.g. -Dsun.security.smartcardio.library=/nix/store/0cdj8mkp03sh1yw9bnkg1sircj99scvp-pcsclite-1.9.5/lib/libpcsclite.so, with the hash uniquely identifying the package. I don't think this path is available in an easy way during runtime, instead the approach would be to provide the path at packaging time of all dependent packages. Unfortunately I am not familiar with repacking maven packages for Nix.

The ${lib.getLib pkgs.pcsclite} statement is evaluated as part of the Nix DSL at system compile time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants