Unable to run Rust Projects on NixOS

I am trying to run an example of the Dixous crate, but get runtime errors.

I use a shell.nix to create a devshell, and upon adding some buildinputs the building finally works out.

nix-shell --command 'cargo build'

But when I want to run an example

nix-shell --command 'cargo run --example calculator'

I get the error

    Finished dev [unoptimized + debuginfo] target(s) in 0.35s
     Running `target/debug/examples/calculator`
/nix/store/mvn4dn334081g7vqx7514k86p2ppdb2w-dconf-0.40.0-lib/lib/gio/modules/libdconfsettings.so: undefined symbol: g_assertion_message_cmpint
Failed to load module: /nix/store/mvn4dn334081g7vqx7514k86p2ppdb2w-dconf-0.40.0-lib/lib/gio/modules/libdconfsettings.so
/nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libc.so.6: version `GLIBC_2.38' not found (required by /nix/store/cmf7hyf5qbd1rm89c4dwa2z0pvql8j6l-gvfs-1.52.2/lib/gio/modules/libgvfsdbus.so)
Failed to load module: /nix/store/cmf7hyf5qbd1rm89c4dwa2z0pvql8j6l-gvfs-1.52.2/lib/gio/modules/libgvfsdbus.so

(calculator:908057): Gtk-WARNING **: 18:46:37.845: Could not load a pixbuf from icon theme.
This may indicate that pixbuf loaders or the mime database could not be found.
**
Gtk:ERROR:../gtk/gtkiconhelper.c:495:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /run/current-system/sw/share/icons/Adwaita/scalable/status/image-missing.svg: Unable to load image-loading module: /nix/store/y2cy098f84s4h6xiqclvf2ikqafg247p-librsvg-2.57.1/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so: /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libm.so.6: version `GLIBC_2.38' not found (required by /nix/store/y2cy098f84s4h6xiqclvf2ikqafg247p-librsvg-2.57.1/lib/librsvg-2.so.2) (gdk-pixbuf-error-quark, 5)
Bail out! Gtk:ERROR:../gtk/gtkiconhelper.c:495:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /run/current-system/sw/share/icons/Adwaita/scalable/status/image-missing.svg: Unable to load image-loading module: /nix/store/y2cy098f84s4h6xiqclvf2ikqafg247p-librsvg-2.57.1/lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so: /nix/store/46m4xx889wlhsdj72j38fnlyyvvvvbyb-glibc-2.37-8/lib/libm.so.6: version `GLIBC_2.38' not found (required by /nix/store/y2cy098f84s4h6xiqclvf2ikqafg247p-librsvg-2.57.1/lib/librsvg-2.so.2) (gdk-pixbuf-error-quark, 5)
shell.nix
let
  rust_overlay = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz");
  pkgs = import <nixpkgs> { overlays = [ rust_overlay ]; };
  rustVersion = "latest";
  rust = pkgs.rust-bin.stable.${rustVersion}.default.override {
    extensions = [
      "rust-src" # for rust-analyzer
      "rust-analyzer"
    ];
  };
  libs = with pkgs; [
    webkitgtk
    gtk3
    cairo
    gdk-pixbuf
    glib
    dbus
    openssl_3
  ];
  buildInputs = [ rust ] ++ (with pkgs; [
    gcc
    glibc
    gtk3
    libsoup_3
    openssl
    pkg-config
    sqlite
    webkitgtk_4_1
    xdotool
  ]);
in
pkgs.mkShell {
  inherit buildInputs;

  nativeBuildInputs = buildInputs;

  RUST_BACKTRACE = 1;
  RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
  PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
}

You define libs but I don’t see you use it anywhere

adding inherit libs; makes no difference

That’s not what I meant. All the packages in libs need to be in either buildInputs, nativeBuildInputs, propagatedBuildInputs, etc in order for the build to know about them. I don’t think a libs attribute by itself means anything, it’s essentially an unused variable.

Yes, I added all packages from the libs variable and all other listed somewhere packages into both buildInputs and nativeBuildInputs, but the symptoms are still the same.

Eventually I got rid of the overlay and it worked. There seemed to have been a mismatch in library versions.

The following updated shell.nix does indeed build the example correctly:

shell.nix
let
  pkgs = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz) {};
  buildInputs = with pkgs; [
    cairo
    cargo
    dbus
    dconf
    gcc
    gdk-pixbuf
    glib
    glibc
    gtk3
    libsoup_3
    openssl
    openssl_3
    pkg-config
    rust-analyzer
    rustc
    sqlite
    webkitgtk
    webkitgtk_4_1
    xdotool
  ];
in
  pkgs.mkShell {
    inherit buildInputs;
    nativeBuildInputs = buildInputs;
  
    RUST_BACKTRACE = "full";
    RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
    PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
  }

I was able to use your original shell.nix to run the example yesterday but did not get the time to post.
So I would indeed suspect a mismatch with the overlay and the nixpkgs you have on your system. Maybe pin both?