Jump to content

Nix-ld: Difference between revisions

From Official NixOS Wiki
Nix-ld: Add a few important libraries.
Imurx (talk | contribs)
updated x packages to their new names
 
Line 35: Line 35:
     enable = true;
     enable = true;
     libraries = with pkgs; [
     libraries = with pkgs; [
      # List by default
        # List by default
       zlib
       zlib
       zstd
       zstd
Line 50: Line 50:
       xz
       xz
       systemd
       systemd
     
 
       # My own additions
       # My own additions
       xorg.libXcomposite
       libxcomposite
       xorg.libXtst
       libxtst
       xorg.libXrandr
       libxrandr
       xorg.libXext
       libxext
       xorg.libX11
       libx11
       xorg.libXfixes
       libxfixes
       libGL
       libGL
       libva
       libva
       pipewire
       pipewire
       xorg.libxcb
       libxcb
       xorg.libXdamage
       libxdamage
       xorg.libxshmfence
       libxshmfence
       xorg.libXxf86vm
       libxxf86vm
       libelf
       libelf


Line 73: Line 73:
       # Inspired by steam
       # Inspired by steam
       # https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/st/steam/package.nix#L36-L85
       # https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/st/steam/package.nix#L36-L85
       networkmanager    
       networkmanager
       vulkan-loader
       vulkan-loader
       libgbm
       libgbm
Line 82: Line 82:
       zenity
       zenity
       # glibc_multi.bin # Seems to cause issue in ARM
       # glibc_multi.bin # Seems to cause issue in ARM
     
 
       # # Without these it silently fails
       # # Without these it silently fails
       xorg.libXinerama
       libxinerama
       xorg.libXcursor
       libxcursor
       xorg.libXrender
       libxrender
       xorg.libXScrnSaver
       libxscrnsaver
       xorg.libXi
       libxi
       xorg.libSM
       libSM
       xorg.libICE
       libICE
       gnome2.GConf
       gnome2.GConf
       nspr
       nspr
Line 102: Line 102:
       # Only libraries are needed from those two
       # Only libraries are needed from those two
       libudev0-shim
       libudev0-shim
     
 
       # needed to run unity
       # needed to run unity
       gtk3
       gtk3
Line 114: Line 114:
       # export XDG_DATA_DIRS=/nix/store/0nfsywbk0qml4faa7sk3sdfmbd85b7ra-gsettings-desktop-schemas-43.0/share/gsettings-schemas/gsettings-desktop-schemas-43.0:/nix/store/rkscn1raa3x850zq7jp9q3j5ghcf6zi2-gtk+3-3.24.35/share/gsettings-schemas/gtk+3-3.24.35/:$XDG_DATA_DIRS
       # export XDG_DATA_DIRS=/nix/store/0nfsywbk0qml4faa7sk3sdfmbd85b7ra-gsettings-desktop-schemas-43.0/share/gsettings-schemas/gsettings-desktop-schemas-43.0:/nix/store/rkscn1raa3x850zq7jp9q3j5ghcf6zi2-gtk+3-3.24.35/share/gsettings-schemas/gtk+3-3.24.35/:$XDG_DATA_DIRS
       # other issue: (Unity:377230): GLib-GIO-CRITICAL **: 21:09:04.706: g_dbus_proxy_call_sync_internal: assertion 'G_IS_DBUS_PROXY (proxy)' failed
       # other issue: (Unity:377230): GLib-GIO-CRITICAL **: 21:09:04.706: g_dbus_proxy_call_sync_internal: assertion 'G_IS_DBUS_PROXY (proxy)' failed
     
 
       # Verified games requirements
       # Verified games requirements
       xorg.libXt
       libxt
       xorg.libXmu
       libxmu
       libogg
       libogg
       libvorbis
       libvorbis
       SDL
       SDL
       SDL2_image
       SDL2_image
       glew110
       glew_1_10
       libidn
       libidn
       tbb
       tbb
     
 
       # Other things from runtime
       # Other things from runtime
       flac
       flac
Line 151: Line 151:
       libvpx
       libvpx
       librsvg
       librsvg
       xorg.libXft
       libxft
       libvdpau
       libvdpau
       # ...
       # ...

Latest revision as of 00:52, 19 May 2026

Nix-ld

Nix-ld is a module that is really practical to enable to have a more "traditional" experience in NixOS by recreating the loaders like /lib/ld-linux.so.2, needed to run any executable that is not patched by nix. It is not needed when installing regular packages "the nix way", but it is really handy to quickly test a binary not packaged for nix, or when developing, for instance in javascript/nodejs, since these languages often pre-download many binaries (of course, a proper packaging is of course better, but potentially too tedious when quickly prototyping).

To enable it, you just need to put in your /etc/nixos/configuration.nix the following:

programs.nix-ld = {
    enable = true;
    libraries = with pkgs; [
      ## Put here any library that is required when running a package
      ## ...
      ## Uncomment if you want to use the libraries provided by default in the steam distribution
      ## but this is quite far from being exhaustive
      ## https://github.com/NixOS/nixpkgs/issues/354513
      # (pkgs.runCommand "steamrun-lib" {} "mkdir $out; ln -s ${pkgs.steam-run.fhsenv}/usr/lib64 $out/lib")
    ];
  };
  ## Uncomment if you used steamrun's libraries
  # nixpkgs.config.allowUnfree = true;

By default, nix-ld comes with only a few libraries, and you need to manually add your own. A simple (but a bit tedious) approach to know which library to add is to run the program, and check for errors like:

$ ./blender
./blender: error while loading shared libraries: libxkbcommon.so.0: cannot open shared object file: No such file or directory

Then, you can search the package that provides the missing library via:

$ nix run github:nix-community/nix-index-database -- lib/libxkbcommon.so.0 --top-level
libxkbcommon.out                                      0 s /nix/store/4di7f8w515xl6grwv13pk6855awav0b1-libxkbcommon-1.8.1/lib/libxkbcommon.so.0
libxkbcommon.out                                342,952 x /nix/store/4di7f8w515xl6grwv13pk6855awav0b1-libxkbcommon-1.8.1/lib/libxkbcommon.so.0.8.1

so here you would add for instance xorg.libXxf86vm. It is however a bit long to find all these libraries, so you may want to just copy/paste this pre-made list until something is done to provide a decent list in Nixpkgs (to avoid cluttering you configuration, copy it in a separate nix file and import it it your main configuration):

{ config, pkgs, lib, ... }:
{
  # Allow unfree packages
  nixpkgs.config.allowUnfree = true;
  # Automatically creates a loader in /lib/* to avoid patching stuff
  # To disable it temporarily use
  # unset NIX_LD
  programs.nix-ld = {
    enable = true;
    libraries = with pkgs; [
        # List by default
      zlib
      zstd
      stdenv.cc.cc
      curl
      openssl
      attr
      libssh
      bzip2
      libxml2
      acl
      libsodium
      util-linux
      xz
      systemd

      # My own additions
      libxcomposite
      libxtst
      libxrandr
      libxext
      libx11
      libxfixes
      libGL
      libva
      pipewire
      libxcb
      libxdamage
      libxshmfence
      libxxf86vm
      libelf

      # Required
      glib
      gtk2

      # Inspired by steam
      # https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/st/steam/package.nix#L36-L85
      networkmanager
      vulkan-loader
      libgbm
      libdrm
      libxcrypt
      coreutils
      pciutils
      zenity
      # glibc_multi.bin # Seems to cause issue in ARM

      # # Without these it silently fails
      libxinerama
      libxcursor
      libxrender
      libxscrnsaver
      libxi
      libSM
      libICE
      gnome2.GConf
      nspr
      nss
      cups
      libcap
      SDL2
      libusb1
      dbus-glib
      ffmpeg
      # Only libraries are needed from those two
      libudev0-shim

      # needed to run unity
      gtk3
      icu
      libnotify
      gsettings-desktop-schemas
      # https://github.com/NixOS/nixpkgs/issues/72282
      # https://github.com/NixOS/nixpkgs/blob/2e87260fafdd3d18aa1719246fd704b35e55b0f2/pkgs/applications/misc/joplin-desktop/default.nix#L16
      # log in /home/leo/.config/unity3d/Editor.log
      # it will segfault when opening files if you don’t do:
      # export XDG_DATA_DIRS=/nix/store/0nfsywbk0qml4faa7sk3sdfmbd85b7ra-gsettings-desktop-schemas-43.0/share/gsettings-schemas/gsettings-desktop-schemas-43.0:/nix/store/rkscn1raa3x850zq7jp9q3j5ghcf6zi2-gtk+3-3.24.35/share/gsettings-schemas/gtk+3-3.24.35/:$XDG_DATA_DIRS
      # other issue: (Unity:377230): GLib-GIO-CRITICAL **: 21:09:04.706: g_dbus_proxy_call_sync_internal: assertion 'G_IS_DBUS_PROXY (proxy)' failed

      # Verified games requirements
      libxt
      libxmu
      libogg
      libvorbis
      SDL
      SDL2_image
      glew_1_10
      libidn
      tbb

      # Other things from runtime
      flac
      freeglut
      libjpeg
      libpng
      libpng12
      libsamplerate
      libmikmod
      libtheora
      libtiff
      pixman
      speex
      SDL_image
      SDL_ttf
      SDL_mixer
      SDL2_ttf
      SDL2_mixer
      libappindicator-gtk2
      libdbusmenu-gtk2
      libindicator-gtk2
      libcaca
      libcanberra
      libgcrypt
      libvpx
      librsvg
      libxft
      libvdpau
      # ...
      # Some more libraries that I needed to run programs
      pango
      cairo
      atk
      gdk-pixbuf
      fontconfig
      freetype
      dbus
      alsa-lib
      expat
      # for blender
      libxkbcommon

      libxcrypt-legacy # For natron
      libGLU # For natron

      # Appimages need fuse, e.g. https://musescore.org/fr/download/musescore-x86_64.AppImage
      fuse
      e2fsprogs
    ];
  };  

}

Once activated (you may need to reboot the first time you enable nix-ld to make sure the environment variables are properly set), I was for instance able to run blender 4.4.3 using the unpatched binary provided by the blender foundation, and develop npm projects with npm install like in any normal linux distribution.