Rust Binaries not Compatible with other Linux

I compiled my rust program (super simple one too as a test, just hello world). I ran it on my NixOS computer, but when I tried moving it to a server running a different distro of linux bash does not recognize it. Here is the output from file:
main: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/xmprbk52mlcdsljz66m8yf7cf0xf36n1-glibc-2.38-44/lib/, for GNU/Linux 3.10.0, with debug_info, not stripped

and here is my shell.nix:

{ pkgs ? import <nixpkgs> {} }:
  gems = pkgs.bundlerEnv {
    name = "ultrahook-env";
    inherit (pkgs.ruby) bundler;
    gemdir = ./.; # path to Gemfile
in pkgs.mkShell rec {
  buildInputs = with pkgs; [
  RUSTC_VERSION = pkgs.lib.readFile ./rust-toolchain;
  LIBCLANG_PATH = pkgs.lib.makeLibraryPath [pkgs.llvmPackages_latest.libclang.lib];
  shellHook = ''
    export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
    export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
  RUSTFLAGS = (a: ''-L ${a}/lib'') [
    # add libraries here (e.g. pkgs.libvmi)
    ( (a: ''-I"${a}/include"'') [
      # add dev libraries here (e.g.
    ++ [

It can’t work. Nix does not respect FHS.

Nix builds its binaries in complete isolation of outside world, and therefore they can’t recognize libraries installed by other distros.

A binary built by Nix will not seek its in the /usr/lib/ of the distro, but in the /nix/store.


Have you ever tried to do the same with, say, a binary built in Archlinux and trying to run it on Ubuntu? It will fail by the same reason. The binaries built in Archlinux expected their .so files installed with certain properties (kernel version, gcc version, libc version…), and it will likely be different from Ubuntu.

In Nix/NixOS it is more evident.

Thanks. Found a solution with patchelf though. How do I compile a Rust binary on NixOS that works on other Linux distros? - #2 by NobbZ