buildRustPackage installs wrong version of dependency (glium)

TL;DR: buildRustPackage installs glium 0.31 instead of 0.32.1(as defined in Cargo.lock).

Hi! I’m trying to install stl-thumb, since I’m working with STL files a lot. I found a PR for that package (that has never been merged) and I’ve used that as a starting point. I can build the package successfully, but when I run the program I get this error:

➜ RUST_BACKTRACE=full ./result/bin/stl-thumb -s 512 Turretbase.stl Turretbase.png
warning: queue 0x5f7c87802cb0 destroyed while proxies still attached:
  wl_keyboard#15 still attached
  xdg_activation_v1#12 still attached
  zwp_text_input_manager_v3#11 still attached
  zwp_pointer_constraints_v1#10 still attached
  zwp_relative_pointer_manager_v1#9 still attached
  wl_seat#8 still attached
  wl_subcompositor#7 still attached
  wl_output#6 still attached
  wl_shm#5 still attached
  wl_compositor#4 still attached
  wl_registry#2 still attached

thread 'main' (107223) panicked at /build/stl-thumb-0.5.0-vendor/source-registry-0/glium-0.31.0/src/texture/get_format.rs:135:25:
internal error: entered unreachable code
stack backtrace:
   0:     0x5f7c78caee45 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h146b70d74c048d79
   1:     0x5f7c78cd9c9a - core::fmt::write::h51386424c21d3e45
   2:     0x5f7c78caf526 - std::io::default_write_fmt::h47a11ac8bae1d5ef
   3:     0x5f7c78cac306 - std::panicking::default_hook::{{closure}}::h462d29ed9732de2f
   4:     0x5f7c78cac1a8 - std::panicking::default_hook::h682fafcf73fec659
   5:     0x5f7c78cac53b - std::panicking::panic_with_hook::h10639e56d0a2a34c
   6:     0x5f7c78cac3ea - std::panicking::panic_handler::{{closure}}::h4728219671baa18c
   7:     0x5f7c78cabb79 - std::sys::backtrace::__rust_end_short_backtrace::h7dc7f75ff139bf56
   8:     0x5f7c78ca7cfd - __rustc[43118a2d2b012dd]::rust_begin_unwind
   9:     0x5f7c789f411c - core::panicking::panic_fmt::h88511d505791b674
  10:     0x5f7c789f40e2 - core::panicking::panic::h1504b2a348a2a162
  11:     0x5f7c78b8b6b5 - glium::texture::get_format::get_format::hf65c04157e286302
  12:     0x5f7c78a46119 - glium::fbo::FramebufferAttachments::validate_regular::hb4360786dc884581
  13:     0x5f7c78a57603 - glium::framebuffer::SimpleFrameBuffer::new_impl::h4c120117f6ac22e3
  14:     0x5f7c78a33897 - stl_thumb::render_to_image::h8fe348c826a93642
  15:     0x5f7c78a31784 - stl_thumb::render_to_file::hc9bb0163ff409901
  16:     0x5f7c789f4dd7 - stl_thumb::main::h079d68c1747ac77e
  17:     0x5f7c789f4226 - std::sys::backtrace::__rust_begin_short_backtrace::hdfe919b89800a9c7
  18:     0x5f7c789f421c - std::rt::lang_start::{{closure}}::hf787cfda0ae5c609
  19:     0x5f7c78caa814 - std::rt::lang_start_internal::h5f328771995ea445
  20:     0x5f7c789f4f8d - main
  21:     0x7b8e0442b285 - __libc_start_call_main
  22:     0x7b8e0442b338 - __libc_start_main_alias_2
  23:     0x5f7c789f4145 - _start
  24:                0x0 - <unknown>

As you can see, the error occurs in glium-0.31.0. However, the glium version in Cargo.lock is 0.32.1:

[[package]]
name = "glium"
version = "0.32.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2766728ecb86014b91d3d687614b32d65aacbbdc887f424a7b03cba3ab593bf"
dependencies = [
 "backtrace",
 "fnv",
 "gl_generator",
 "glutin",
 "lazy_static",
 "memoffset",
 "smallvec",
 "takeable-option",
]

I’ve set cargoHash to lib.fakeHash to see if it’s wrong, but ended up with exactly the same hash in the got XXX error message. I’ve also tried to use the original Cargo.lock from upstream instead if the hash (deleted cargoHash from default.nix), but that also results in a hash mismatch error:

➜ nix build .#stl-thumb                                                                                                                                     
warning: Git tree '/home/remrot/git/nixos' is dirty
error: Cannot build '/nix/store/6yah65hmvf8106g2nr4v443ni4zhrszf-stl-thumb-0.5.0.drv'.
       Reason: builder failed with exit code 1.                                                                                                             
       Output paths:                                          
         /nix/store/2wzj3rczw7wa2j95qad76s62rg6890kd-stl-thumb-0.5.0    
       Last 25 log lines:                                                                                                                                   
       > > source = "registry+https://github.com/rust-lang/crates.io-index"
       > > checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02"
       > > dependencies = [                                                                                                                                 
       > >  "simd-adler32",                                                                                                                                 
       > > ]                                                          
       > >                                                              
       > > [[package]]                                              
       > > name = "zune-jpeg"                                                                                                                               
       > > version = "0.4.13"                                                                                                                               
       > > source = "registry+https://github.com/rust-lang/crates.io-index"                                                                                 
       > > checksum = "16099418600b4d8f028622f73ff6e3deaabdff330fb9a2a131dea781ee8b0768"
       > > dependencies = [                                            
       > >  "zune-core",                                     
       > > ]                                                                                                                                                
       >                                                                      
       > ERROR: cargoHash or cargoSha256 is out of date                   
       >                       
       > Cargo.lock is not the same in /build/cargo-vendor-dir
       >                                            
       > To fix the issue:       
       > 1. Set cargoHash/cargoSha256 to an empty string: `cargoHash = "";`
       > 2. Build the derivation and wait for it to fail with a hash mismatch
       > 3. Copy the "got: sha256-..." value back into the cargoHash field
       >    You should have: cargoHash = "sha256-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=";
       >
       For full logs, run:
         nix log /nix/store/6yah65hmvf8106g2nr4v443ni4zhrszf-stl-thumb-0.5.0.drv

This is my current stl-thumb/default.nix:

{
  lib,
  fetchFromGitHub,
  libXcursor,
  libXrandr,
  libXi,
  rustPlatform,
  libx11,
  wayland,
  libGL,
  cmake,
  pkg-config,
  fontconfig,
}:

rustPlatform.buildRustPackage rec {
  pname = "stl-thumb";
  version = "0.5.0";

  src = fetchFromGitHub {
    owner = "unlimitedbacon";
    repo = "stl-thumb";
    tag = "v${version}";
    sha256 = "sha256-sMgYrVQAtyVTfQyuTb/8OtRuDpagNQpt5YoF9lGIMHg=";
  };

  nativeBuildInputs = [
    cmake
    pkg-config
  ];

  buildInputs = [ fontconfig ];

  # propagatedBuildInputs = [
  #   libXcursor
  #   libXrandr
  #   libXi
  #   wayland
  #   libx11
  # ];

  # Tests require a display server
  doCheck = false;

  cargoLock = {
    lockFile = ./Cargo.lock;
  };

  postInstall = ''
    mkdir $out/include
    cp libstl_thumb.h $out/include
    mkdir -p $out/share/thumbnailers
    mkdir -p $out/mime/packages
    cp stl-thumb.thumbnailer $out/share/thumbnailers/stl-thumb.thumbnailer
    cp stl-thumb-mime.xml $out/mime/packages/stl-thumb-mime.xml
  '';
  # libs are loaded dynamically; make sure we'll find them
  postFixup = ''
    patchelf \
    --add-needed ${lib.getLib libx11}/lib/libX11.so \
    --add-needed ${lib.getLib wayland}/lib/libwayland-client.so \
    --add-needed ${lib.getLib libGL}/lib/libEGL.so \
    $out/bin/stl-thumb
  '';

  meta = {
    description = "Thumbnail generator for STL files";
    homepage = "https://github.com/unlimitedbacon/stl-thumb";
    license = lib.licenses.mit;
    mainProgram = "stl-thumb";
    platforms = lib.platforms.linux;
    maintainers = with lib.maintainers; [ me ];
  };
}

So, for some reason buildRustPackage installs the wrong version of glium. I guess it’s some kind of caching issue but I have no idea how to fix it…

Hey, I was the one working on the package before you. I figured you’d want to know I found a replacement that is already available. The package name is f3d. You might try it out and see if it does what you’re wanting from stl-thumb.

2 Likes

Hey, thanks for the tip! Very much appreciated!

I’m currently trying out f3d and see if I can use it as a replacement. My main usecase for stl-thumb is creating thumbnails for Orynt, using a script that runs over all STLs in a given folder and calls stl-thumb -s 512 <STL> <PNG>. I really like how good the thumbnails look with zero configuration.

I found the --output option in f3d for rendering to a file, but due to the camera position they’re not very useful. I guess I have to play with the settings to get better results…

@SyntaxualSugar : how did you configure f3d thumbnail generation in NixOS? The package from nixpkgs does not configure anything and I’m not sure how to set it up in a declarative way…

Edit: I mean the DE integration (e.g. Nautilus).