Libmagic Library not found when running Lutris in Nix-Shell

I wanted to clone the Lutris Repository to fix simple a Bug. It is written in Python. It does not have a premade shell, so I made one myself.

When i Run the Program it panics with the following error

OSError: libmagic.so.1: cannot open shared object file: No such file or directory

The Libmagic library is included in pkgs.file. My shell:

{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
  buildInputs = with pkgs.buildPackages; [
  python312
  python312Packages.pygobject3
  python312Packages.pillow
  python312Packages.requests
  python312Packages.pyyaml
  python312Packages.setproctitle
  python312Packages.distro
  gobject-introspection
  gtk3
  python312Packages.dbus-python
  webkitgtk_4_1
  python312Packages.magic
  python312Packages.python-magic
  psmisc
  virtualgl
  vulkan-tools
  p7zip
  file
 ];
 shellhook = "export LD_LIBRARY_PATH=${pkgs.file}/lib";
}

Did i add LD_Library_Path the right way? or is it another Problem?

Thank you in advance for any advice!

To start off, you’re probably better off with using inputsFrom = [ pkgs.lutris ]; or similar.

I tried it, but it didn’t work. It spat out errors that i already solved. I tried adding inputsFrom to the shell (same error as before) and replacing BuildInputs with InputsFrom (no python interpreter?) nonetheless Thank you.

That’s a misspelling, it’s inputsFrom not InputsFrom.

If you need to add additional packages, prefer packages over buildInputs.

in my code i spelled it correctly

What are these errors?

Missing python modules

To be more specific, what’re the exact code and commands you used, and the exact errors you recieved?

{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
  inputsFrom = [pkgs.lutris];
  buildInputs = with pkgs.buildPackages; [
  python312
  python312Packages.pygobject3
  python312Packages.pillow
  python312Packages.requests
  python312Packages.pyyaml
  python312Packages.setproctitle
  python312Packages.distro
  gobject-introspection
  gtk3
  python312Packages.dbus-python
  webkitgtk_4_1
  python312Packages.magic
  python312Packages.python-magic
  psmisc
  virtualgl
  vulkan-tools
  p7zip
  file
  ];
 shellhook = "export LD_LIBRARY_PATH=${pkgs.file}/lib";
}

and executing lutris with ./bin/lutris -d throws

/nix/store/lkgfphix3sgfsm38smsw38xk81h3f3ig-glibc-2.40-66-bin/bin/ldconfig: Can't open cache file /nix/store/vbrdc5wgzn0w1zdp10xd2favkjn5fk7y-glibc-2.40-66/etc/ld.so.cache
: No such file or directory
2025-04-21 15:03:36,650: ['/nix/store/lkgfphix3sgfsm38smsw38xk81h3f3ig-glibc-2.40-66-bin/bin/ldconfig', '-p'] command failed: Command '['/nix/store/lkgfphix3sgfsm38smsw38xk81h3f3ig-glibc-2.40-66-bin/bin/ldconfig', '-p']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/home/mirko/BigProjects/lutris/./bin/lutris", line 62, in <module>
    from lutris.gui.application import Application  # pylint: disable=no-name-in-module
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mirko/BigProjects/lutris/lutris/gui/application.py", line 45, in <module>
    from lutris.gui.dialogs.delegates import CommandLineUIDelegate, InstallUIDelegate, LaunchUIDelegate
  File "/home/mirko/BigProjects/lutris/lutris/gui/dialogs/delegates.py", line 10, in <module>
    from lutris.services import get_enabled_services
  File "/home/mirko/BigProjects/lutris/lutris/services/__init__.py", line 6, in <module>
    from lutris.services.amazon import AmazonService
  File "/home/mirko/BigProjects/lutris/lutris/services/amazon.py", line 25, in <module>
    from lutris.services.base import SERVICE_LOGIN, OnlineService
  File "/home/mirko/BigProjects/lutris/lutris/services/base.py", line 20, in <module>
    from lutris.gui.views.media_loader import download_media
  File "/home/mirko/BigProjects/lutris/lutris/gui/views/media_loader.py", line 5, in <module>
    from lutris.gui.widgets.utils import MEDIA_CACHE_INVALIDATED
  File "/home/mirko/BigProjects/lutris/lutris/gui/widgets/utils.py", line 13, in <module>
    from lutris.util import datapath, magic, system
  File "/home/mirko/BigProjects/lutris/lutris/util/magic.py", line 227, in <module>
    libmagic = ctypes.CDLL(dll)
               ^^^^^^^^^^^^^^^^
  File "/nix/store/fqm9bqqlmaqqr02qbalm1bazp810qfiw-python3-3.12.9/lib/python3.12/ctypes/__init__.py", line 379, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: libmagic.so.1: cannot open shared object file: No such file or directory

edit: I changed buildInputs to packages and nothing changed
edit 2: When I remove packages and only use inputsFrom it doesnt work because i don’t even have a python interpreter

Okay, can you try removing buildInputs/packages entirely? Are you still facing errors with that?

EDIT: just saw the last part, that’s odd.

Ah okay, lutris is a wrapped package. Try (without buildInputs/packages, for a moment)

inputsFrom = [
  pkgs.lutris-unwrapped
  pkgs.lutris
];

Using this gives me:

/nix/store/lkgfphix3sgfsm38smsw38xk81h3f3ig-glibc-2.40-66-bin/bin/ldconfig: Can't open cache file /nix/store/vbrdc5wgzn0w1zdp10xd2favkjn5fk7y-glibc-2.40-66/etc/ld.so.cache
: No such file or directory
2025-04-21 15:12:02,630: ['/nix/store/lkgfphix3sgfsm38smsw38xk81h3f3ig-glibc-2.40-66-bin/bin/ldconfig', '-p'] command failed: Command '['/nix/store/lkgfphix3sgfsm38smsw38xk81h3f3ig-glibc-2.40-66-bin/bin/ldconfig', '-p']' returned non-zero exit status 1.
Error importing Lutris application module: failed to find libmagic.  Check your installation

Okay, I noticed the lutris-unwrapped expression has some bits that may be harder to replicate in a shell:

Can you try building the code with nix? For example:

nix-build --expr 'let pkgs = import <nixpkgs> {}; in
  pkgs.lutris.override {
    lutris-unwrapped = pkgs.lutris-unwrapped.overrideAttrs {
      src = /path/to/your/local/clone;
    };
  }
'

(changing the src path)

1 Like

That worked! Thank you so much! :heart:

1 Like