Error while loading shared libraries: libudev.so.1

Hello everyone,
I installed platformio-core on NixOS unstable to upload a code on a teensy board. But currently getting following error:

teensy_reboot: error while loading shared libraries: libudev.so.1: cannot open shared object file: No such file or directory
*** [upload] Error 127

Here is the full output:

> pio run -t upload
Processing teensy41 (platform: teensy; board: teensy41; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy41.html
PLATFORM: Teensy (5.0.0) > Teensy 4.1
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 7.75MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
 - framework-arduinoteensy @ 1.159.0 (1.59)
 - tool-teensy @ 1.159.0 (1.59)
 - toolchain-gccarmnoneeabi-teensy @ 1.110301.0 (11.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 96 compatible libraries
Scanning dependencies...
Dependency Graph
|-- XPT2046_Touchscreen @ 0.0.0-alpha+sha.26b691b2c8
|-- lvgl @ 9.1.0
|-- TFT_eSPI @ 2.5.43
|-- Audio @ 1.3
|-- SD @ 2.0.0
|-- SPI @ 1.0
|-- SerialFlash
|-- Wire @ 1.0
|-- EEPROM @ 2.0
|-- USBHost_t36 @ 0.2
Building in release mode
Linking .pio/build/teensy41/firmware.elf
Checking size .pio/build/teensy41/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
Building .pio/build/teensy41/firmware.hex
Configuring upload protocol...
AVAILABLE: jlink, teensy-cli, teensy-gui
CURRENT: upload_protocol = teensy-cli
Rebooting...
teensy_reboot: error while loading shared libraries: libudev.so.1: cannot open shared object file: No such file or directory
*** [upload] Error 127

Here is the location of the teensy_reboot which is installed by platformio:

~/.platformio/packages/tool-teensy/teensy_reboot

And here is the value of LD_LIBRARY_PATH environment variable:

echo $LD_LIBRARY_PATH
/nix/store/g29km1srdqrvyvlq7mnkkji4w1ay0i98-pipewire-1.0.5-jack/lib

installing teensy-udev-rules doesn’t fix the issue

teensy_reboot: error while loading shared libraries: libudev.so.1: cannot open shared object file

This suggests that it’s the teensy_reboot binary which was dynamically linked against the libudev.so.1.

On a Non-NixOS system, this isn’t an issue since it’ll be able to find the shared library.

On NixOS… if nothing else, you might be able to write a shim which sets LD_LIBRARY_PATH & then calls the original teensy_reboot:

#!/usr/bin/env bash
env LD_LIBRARY_PATH=$(nix path-info nixpkgs#libuv)/lib ./teensy_reboot.orig $*

It’s my understanding that nix-ld ought to be able to handle this, too.

I do not run teensy_reboot directly, PlatformIO will call it. I tried something like this but still getting same error:

env LD_LIBRARY_PATH=$(nix path-info nixpkgs#libuv)/lib pio run -t upload $*

Is there any way to set LD_LIBRARY_PATH or nix-ld in configuration.nix file?
I added these line to configuration.nix but not sure if it is the correct way:

  programs.nix-ld.enable = true;

  programs.nix-ld.libraries = with pkgs; [
    platformio-core
    platformio
    teensy-loader-cli
  ];

Sure, but I was thinking something like:

$ cd ~/.platformio/packages/tool-teensy/
$ mv teensy_reboot teensy_reboot.orig
$ touch teensy_reboot
$ chmod +x teensy_reboot

Then editing this teensy_reboot to call teensy_reboot.orig with LD_LIBRARY_PATH set.

Setting LD_LIBRARY_PATH in configuration.nix is likely to break things.

If setting LD_LIBRARY_PATH using env didn’t fix the problem, setting it in configuration.nix wouldn’t either.

1 Like

I don’t know the project in question but the platformio package has a platformio-chrootenv variant which runs inside of an FHSEnv. Have you tried that?

Here is what I get in result

Rebooting...
these 2 paths will be fetched (6.29 MiB download, 28.97 MiB unpacked):
  /nix/store/apab5i73dqa09wx0q27b6fbhd1r18ihl-glibc-2.39-31
  /nix/store/adymciwshrcsm52xjdblsvrcwjqj6k5b-libuv-1.48.0
error: path '/nix/store/adymciwshrcsm52xjdblsvrcwjqj6k5b-libuv-1.48.0' is not valid
/home/USERNAME/.platformio/packages/tool-teensy/teensy_reboot.orig: error while loading shared libraries: libudev.so.1: cannot open shared object file: No such file or directory
*** [upload] Error 127

Could you help me to know how should I use it? I could not find platformio-chrootenv on Nix repo

Ah, it appears that’s the default on Linux.

In that case it’s clear why nix-ld won’t do anything; its ldso is overwritten with the FHSenv’s ldso inside the FHSEnv.

The package sadly doesn’t offer a convenient way of doing that via an override. You’d have to edit the package’s chrootenv.nix to include udev. It’d be great if you could create a PR for that against Nixpkgs so that the package works as expected for all others attempting to do the same thing you are going forward.

Finally found some time to open a PR and fix the issue. It is merged and fixed the issue.
Thanks for the helps.

2 Likes