FAQ: Difference between revisions

Sdht0 (talk | contribs)
Add nix-ld as recommendation to run unlatched binaries
Tags: Mobile edit Mobile web edit
Line 152: Line 152:


If you are in a hurry and just want to get shit running, continue reading:<br />
If you are in a hurry and just want to get shit running, continue reading:<br />
Compiled binaries have hard-coded interpreter and require certain dynamic libraries. You can use [https://nixos.org/patchelf.html patchelf] to set the library path and dynamic linker appropriately:
 
You can use [https://github.com/Mic92/nix-ld nix-ld] to run compiled binaries. For example, if your binary needs zlib and openssl:
 
<syntaxhighlight lang="nix">
programs.nix-ld = {
  enable = true;
  libraries = [ pkgs.zlib pkgs.openssl ];
};</syntaxhighlight>
 
Log out and back in to apply the environment variables it sets, and you can then directly run the binary.
 
If you don't want to configure the list of libraries manually, a quick and dirty way to run nearly any precompiled binary is the following:
 
<syntaxhighlight lang="nix">
programs.nix-ld = {
  enable = true;
  libraries = pkgs.steam-run.fhsenv.args.multiPkgs pkgs;
};</syntaxhighlight>
 
This uses the libraries that are used by [[Steam]] to simulate a traditional Linux FHS environment to run games in. It's a [https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/games/steam/fhsenv.nix big list] that usually contains all the libraries your binary needs to run.
 
Another possibility is to use [https://nixos.org/patchelf.html patchelf] to set the library path and dynamic linker appropriately, since compiled binaries have hard-coded interpreter and require certain dynamic libraries.


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">