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

use system chdman if available, fails to run due to libSDL2 dependency #1398

Closed
acuteaura opened this issue Dec 14, 2024 · 6 comments · Fixed by #1443
Closed

use system chdman if available, fails to run due to libSDL2 dependency #1398

acuteaura opened this issue Dec 14, 2024 · 6 comments · Fixed by #1443
Assignees
Labels
enhancement New feature or request

Comments

@acuteaura
Copy link

acuteaura commented Dec 14, 2024

Paste the command

npx igir@latest copy zip report --dat DAT/*.zip --input Oxy/ --output Emulation/ --dir-dat-name

Describe the bug

chdman is available in path, but igir attempts to use one shipped via npm and falls flat on its face, because NixOS

ERROR: Oxy/<snip>.chd: failed to parse file: /home/nas/.npm/_npx/0d8028b15d717946/node_modules/@emmercm/chdman-linux-x64/chdman: error
while loading shared libraries: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory

Expected behavior

igir checks path for tools it may need and prefers to use those; or ships static builds

Debug logs

N/A

DAT(s) used

N/A

igir version

v3.0.1

Node.js version

nixpkgs#nodejs_20

Operating system

NixOS 24.05 (Uakari)

Additional context

No response

@acuteaura acuteaura added the potential-bug A potential issue that needs confirmation and/or triage label Dec 14, 2024
@acuteaura acuteaura changed the title use system chdman if available, fails to run due to libSDL dependency use system chdman if available, fails to run due to libSDL2 dependency Dec 14, 2024
@emmercm
Copy link
Owner

emmercm commented Feb 13, 2025

Unfortunately, this is expected, and isn't a NixOS-specific problem.

I have spent easily dozens of hours trying to get chdman to statically compile, and I just opened some issues on MAME to clarify my understanding: https://github.com/mamedev/mame/issues?q=is%3Aissue%20author%3Aemmercm%20

If you happen to know how your binary was built I'd love to know, otherwise, let me think on a solution here.

There's a small footer in the supported archives section that mentions you need to install SDL2: https://igir.io/input/reading-archives/#supported-types-for-reading. I haven't found a better place to put that instruction, and I don't think it would be appropriate for Igir to attempt installation on your behalf.

@emmercm emmercm removed the potential-bug A potential issue that needs confirmation and/or triage label Feb 13, 2025
@acuteaura
Copy link
Author

SDL2 is correct.

  programs.nix-ld.enable = true;
  programs.nix-ld.libraries = with pkgs; [
    SDL2
  ];

But NixOS is unfortunately pretty special, because several versions of anything can exist at all times, the ldd output for chdman looks something like this:

        linux-vdso.so.1 (0x00007ffdcd735000)
        libdl.so.2 => /nix/store/81mi7m3k3wsiz9rrrg636sx21psj20hc-glibc-2.40-66/lib/libdl.so.2 (0x00007f9a22194000)
        librt.so.1 => /nix/store/81mi7m3k3wsiz9rrrg636sx21psj20hc-glibc-2.40-66/lib/librt.so.1 (0x00007f9a2218f000)
        libSDL2-2.0.so.0 => /nix/store/y0vi3axnpydl85krg5z3202fc9nww60z-SDL2-2.30.11/lib/libSDL2-2.0.so.0 (0x00007f9a21f12000)
        libpthread.so.0 => /nix/store/81mi7m3k3wsiz9rrrg636sx21psj20hc-glibc-2.40-66/lib/libpthread.so.0 (0x00007f9a21f0d000)
        libutil.so.1 => /nix/store/81mi7m3k3wsiz9rrrg636sx21psj20hc-glibc-2.40-66/lib/libutil.so.1 (0x00007f9a21f06000)
        libexpat.so.1 => /nix/store/wh44r80xfs54l63xcg1fflvmgbvzbq8a-expat-2.6.4/lib/libexpat.so.1 (0x00007f9a21ed9000)
        libz.so.1 => /nix/store/jb442jir0a2x7zsk0d63xb6rh8p280ai-zlib-1.3.1/lib/libz.so.1 (0x00007f9a21eba000)
        libFLAC.so.12 => /nix/store/zc1yn5x6h7ack7cfnm40qhb8xkqkzrdl-flac-1.4.3/lib/libFLAC.so.12 (0x00007f9a21e36000)
        libutf8proc.so.3 => /nix/store/1lbni4ri5zx0jyk2g9ax3vl82s0gi9wg-utf8proc-2.10.0/lib/libutf8proc.so.3 (0x00007f9a21dde000)
        libstdc++.so.6 => /nix/store/ggqfrwgzpr3v3dkvh4cnmhymnvf6cqja-gcc-14-20241116-lib/lib/libstdc++.so.6 (0x00007f9a21b6a000)
        libm.so.6 => /nix/store/81mi7m3k3wsiz9rrrg636sx21psj20hc-glibc-2.40-66/lib/libm.so.6 (0x00007f9a21a81000)
        libgcc_s.so.1 => /nix/store/ggqfrwgzpr3v3dkvh4cnmhymnvf6cqja-gcc-14-20241116-lib/lib/libgcc_s.so.1 (0x00007f9a21a53000)
        libc.so.6 => /nix/store/81mi7m3k3wsiz9rrrg636sx21psj20hc-glibc-2.40-66/lib/libc.so.6 (0x00007f9a2184e000)
        libX11.so.6 => /nix/store/80r6vnyb23f84b4jx3qdb9spy3f02akk-libX11-1.8.10/lib/libX11.so.6 (0x00007f9a216fc000)
        libXext.so.6 => /nix/store/n3d6zzfmfy6s36s9hadwrp56gvxpiy8g-libXext-1.3.6/lib/libXext.so.6 (0x00007f9a216e7000)
        libXcursor.so.1 => /nix/store/02glin2yjx2l0xnmiv3i17hryyjqdxbh-libXcursor-1.2.3/lib/libXcursor.so.1 (0x00007f9a216d8000)
        libXi.so.6 => /nix/store/8xrgg7vv2nx5amy6mbvkpr8cjqgzknr5-libXi-1.8.2/lib/libXi.so.6 (0x00007f9a216c4000)
        libXfixes.so.3 => /nix/store/q8n5x0j3nfz42v992f2ja41mz56h2hwv-libXfixes-6.0.1/lib/libXfixes.so.3 (0x00007f9a216bc000)
        libXrandr.so.2 => /nix/store/73xrpyf9ngd7ap1gz6mqgpbbi4qgm5ib-libXrandr-1.5.4/lib/libXrandr.so.2 (0x00007f9a216af000)
        libXss.so.1 => /nix/store/8zcsk1sj4qgc81j7b9ydan1h7kkagclq-libXScrnSaver-1.2.4/lib/libXss.so.1 (0x00007f9a216aa000)
        libogg.so.0 => /nix/store/l40h0gjdx62awcl97w370h01qnrgfwbb-libogg-1.3.5/lib/libogg.so.0 (0x00007f9a2169d000)
        /nix/store/81mi7m3k3wsiz9rrrg636sx21psj20hc-glibc-2.40-66/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f9a2219b000)
        libxcb.so.1 => /nix/store/9r75y0673s5h26q5ibhavvw0mxpzpz39-libxcb-1.17.0/lib/libxcb.so.1 (0x00007f9a21670000)
        libXrender.so.1 => /nix/store/j9j0pkp5yj5r795v6yk3vw1mz4zyc42j-libXrender-0.9.12/lib/libXrender.so.1 (0x00007f9a21663000)
        libXau.so.6 => /nix/store/pjn9a9zvdcdjx08ahvxl0a116d2d6q32-libXau-1.0.12/lib/libXau.so.6 (0x00007f9a2165c000)
        libXdmcp.so.6 => /nix/store/ip40w780270janfx2cqh6m815ag1y5s1-libXdmcp-1.1.5/lib/libXdmcp.so.6 (0x00007f9a21654000)

So yes, I can make it work by putting a specific SDL2 version into nix-ld, but this is not exactly desired.

@emmercm
Copy link
Owner

emmercm commented Feb 13, 2025

I don't think I understood your response. Is that the current compiled version of https://github.com/emmercm/chdman-js will never work with NixOS, or that SDL2 isn't auto-installed as part of Igir?

@acuteaura
Copy link
Author

Nix does not run traditional dynamically linked ELF binaries without workarounds, because there could be a dozen different versions of libSDL2-2.0.so.0 (or, indeed, chdman) installed on the system at the same time.

Precompiled binaries that were not created for NixOS usually have a so-called link-loader hardcoded into them. On Linux/x86_64 this is for example /lib64/ld-linux-x86-64.so.2. for glibc. NixOS, on the other hand, usually has its dynamic linker in the glibc package in the Nix store and therefore cannot run these binaries. Nix-ld provides a shim layer for these types of binaries. It is installed in the same location where other Linux distributions install their link loader, ie. /lib64/ld-linux-x86-64.so.2 and then loads the actual link loader as specified in the environment variable NIX_LD. In addition, it also accepts a colon-separated path from library lookup paths in NIX_LD_LIBRARY_PATH. This environment variable is rewritten to LD_LIBRARY_PATH before passing execution to the actual ld. This allows you to specify additional libraries that the executable needs to run.

The easiest way to work around this is to check if chdman is in PATH and use that one if it exists.

@emmercm emmercm added the enhancement New feature or request label Feb 13, 2025
@emmercm
Copy link
Owner

emmercm commented Feb 13, 2025

My worry with that would be if the user's version of chdman is below some minimum version for certain functionality, but that might be unfounded with Igir's relatively simple usage of it. I'll think of the best way to accomplish this.

@acuteaura
Copy link
Author

acuteaura commented Feb 13, 2025

might also be a good idea to allow specifying a path somehow (environment?) for external tools

in nix you can just write something like ${pkgs.mame.tools}/bin/chdman to automatically pull chdman (version in the same channel) in as a dependency for your derivation and then generate a wrapper with a specific environment.

would certainly simplify #1410 and let you build everything from scratch properly (nixpkgs doesn't generally like binary dependencies if they can be avoided)

the current package seems orphaned and very outdated, but seems to use the (autp-patched) binaries included

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

Successfully merging a pull request may close this issue.

2 participants