Jump to content

Nix-ld: Difference between revisions

From Official NixOS Wiki
Imurx (talk | contribs)
updated x packages to their new names
add dependencies for zxlive
 
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
       libxcomposite
       xorg.libXcomposite
       libxtst
       xorg.libXtst
       libxrandr
       xorg.libXrandr
       libxext
       xorg.libXext
       libx11
       xorg.libX11
       libxfixes
       xorg.libXfixes
       libGL
       libGL
       libva
       libva
       pipewire
       pipewire
       libxcb
       xorg.libxcb
       libxdamage
       xorg.libXdamage
       libxshmfence
       xorg.libxshmfence
       libxxf86vm
       xorg.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
       libxinerama
       xorg.libXinerama
       libxcursor
       xorg.libXcursor
       libxrender
       xorg.libXrender
       libxscrnsaver
       xorg.libXScrnSaver
       libxi
       xorg.libXi
       libSM
       xorg.libSM
       libICE
       xorg.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
       libxt
       xorg.libXt
       libxmu
       xorg.libXmu
       libogg
       libogg
       libvorbis
       libvorbis
       SDL
       SDL
       SDL2_image
       SDL2_image
       glew_1_10
       glew110
       libidn
       libidn
       tbb
       tbb
 
     
       # Other things from runtime
       # Other things from runtime
       flac
       flac
Line 151: Line 151:
       libvpx
       libvpx
       librsvg
       librsvg
       libxft
       xorg.libXft
       libvdpau
       libvdpau
       # ...
       # ...
Line 173: Line 173:
       fuse
       fuse
       e2fsprogs
       e2fsprogs
      # darktable nightly AppImage https://github.com/darktable-org/darktable/releases
      gmp
      # RapidRaw
      harfbuzz
      libgpg-error
      # https://github.com/xournalpp/xournalpp/releases/download/v1.2.4/xournalpp-1.2.4-x86_64.AppImage
      fribidi
      librsvg
      # https://github.com/nix-community/nix-ld/issues/95#issuecomment-3041993870
      (runCommand "librsvg" {} ''
        mkdir -p $out/lib/gdk-pixbuf-2.0/2.10.0/loaders
        ln -s "${librsvg}/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader_svg.so" "$out/lib/libpixbufloader-svg.so"
      '')
      # pdfmastereditor
      sane-backends
      pkcs11helper
      # Qt6 requires this (e.g. used in zxlive)
      libpulseaudio
      krb5
      libxcb-cursor
      xorg.xcbutilwm
      xorg.xcbutil
      xorg.xcbutilimage
      xorg.xcbutilkeysyms
      xorg.xcbutilrenderutil
     
     ];
     ];
   };   
   };   


}
}


</syntaxhighlight>
</syntaxhighlight>


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 [https://download.blender.org/release/Blender4.4/blender-4.4.3-linux-x64.tar.xz unpatched binary provided by the blender foundation], and develop npm projects with <code>npm install</code> like in any normal linux distribution.
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 [https://download.blender.org/release/Blender4.4/blender-4.4.3-linux-x64.tar.xz unpatched binary provided by the blender foundation], and develop npm projects with <code>npm install</code> like in any normal linux distribution.

Latest revision as of 14:21, 16 June 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
      xorg.libXcomposite
      xorg.libXtst
      xorg.libXrandr
      xorg.libXext
      xorg.libX11
      xorg.libXfixes
      libGL
      libva
      pipewire
      xorg.libxcb
      xorg.libXdamage
      xorg.libxshmfence
      xorg.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
      xorg.libXinerama
      xorg.libXcursor
      xorg.libXrender
      xorg.libXScrnSaver
      xorg.libXi
      xorg.libSM
      xorg.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
      xorg.libXt
      xorg.libXmu
      libogg
      libvorbis
      SDL
      SDL2_image
      glew110
      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
      xorg.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

      # darktable nightly AppImage https://github.com/darktable-org/darktable/releases
      gmp

      # RapidRaw
      harfbuzz
      libgpg-error
      # https://github.com/xournalpp/xournalpp/releases/download/v1.2.4/xournalpp-1.2.4-x86_64.AppImage
      fribidi
      librsvg
      # https://github.com/nix-community/nix-ld/issues/95#issuecomment-3041993870
      (runCommand "librsvg" {} ''
        mkdir -p $out/lib/gdk-pixbuf-2.0/2.10.0/loaders
        ln -s "${librsvg}/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader_svg.so" "$out/lib/libpixbufloader-svg.so"
      '')

      # pdfmastereditor
      sane-backends
      pkcs11helper

      # Qt6 requires this (e.g. used in zxlive)
      libpulseaudio
      krb5
      libxcb-cursor
      xorg.xcbutilwm
      xorg.xcbutil
      xorg.xcbutilimage
      xorg.xcbutilkeysyms
      xorg.xcbutilrenderutil
      
    ];
  };  

}

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.