Skip to content

MTP plugin: New plugin MTP/PTP for USB-connected devices (Android, cameras, iOS Camera Roll)#3382

Open
stpork wants to merge 11 commits into
elfmz:masterfrom
stpork:feature-mtp-plugin
Open

MTP plugin: New plugin MTP/PTP for USB-connected devices (Android, cameras, iOS Camera Roll)#3382
stpork wants to merge 11 commits into
elfmz:masterfrom
stpork:feature-mtp-plugin

Conversation

@stpork

@stpork stpork commented May 5, 2026

Copy link
Copy Markdown
Contributor

A new plugin to browse USB-connected MTP/PTP devices (Android, cameras, iOS Camera Roll) directly from the file panel.

  • Copy / move / rename / delete in both directions; cross-panel copy on the same device skips the host roundtrip.
  • Progress + abort, overwrite prompt (Skip/Newer/Rename), English + Russian.
  • Vendored static libmtp 1.1.23 — only system dep is libusb-1.0.
  • Linux kernel-claimer kick + macOS icdd dislodge handled automatically.

-DMTP=OFF to disable. See mtp/README.md for full notes.

@stpork stpork force-pushed the feature-mtp-plugin branch 6 times, most recently from 9c16069 to c3f9c4f Compare May 5, 2026 21:41
@stpork stpork changed the title Add MTP/PTP plugin MTP plugin: New plugin MTP/PTP for USB-connected devices (Android, cameras, iOS Camera Roll) May 5, 2026
@stpork stpork force-pushed the feature-mtp-plugin branch from e58f903 to 009dbcc Compare May 6, 2026 20:09
@elfmz

elfmz commented May 9, 2026

Copy link
Copy Markdown
Owner

Please mention in README.md that libusb-1.0-0-dev is needed to install and add it to example apt command as its seems its required now unless -MTP=NO specified for cmake.
Alternatively can detect presence of libusb and activate MTP by default only if its found

stpork added 4 commits May 9, 2026 22:09
Browse, copy, move, rename and delete files on USB-connected phones and cameras (Android, iOS PTP, digital cameras). Built on vendored libmtp.
@stpork stpork force-pushed the feature-mtp-plugin branch from cb1a01b to 62cfc08 Compare May 9, 2026 19:15
@stpork

stpork commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

Please mention in README.md that libusb-1.0-0-dev is needed to install and add it to example apt command as its seems its required now unless -MTP=NO specified for cmake. Alternatively can detect presence of libusb and activate MTP by default only if its found

Instead, I wired libusb statically into the plugin and rebased.

@tempergate

tempergate commented May 11, 2026

Copy link
Copy Markdown
Contributor

> Instead, I wired libusb statically into the plugin and rebased.

It was a terrible idea, now it just not working
far2l.log

previous version worked great. Is it possible to rallback to the third commit, when the plugin worked?
62cfc08 brakes it
Switching back to distro-provided libusb1 bring it back to live, But latest two commits makes it non-functional, even when I'm adding libusb1 buildInputs.

It is better to have extra dependency, than non-functional pluggin

I'm not using FHS distro, so that could be a reason it dosn't works for me.
I noticed you added skip for free BSD to use system installed library, could you at least add the same skip for Nix systems, to use build inputs system library.

Here is far:about

          FAR2L Version: 2.8.0-beta
         Build Compiler: GCC, version 15.2.0
         Build Platform: arm64 (Linux)
                Backend: GUI|WX
    ConsoleColorPalette: 24
 Win size in char cells: 204x56
                  Admin: -
                    PID: 762712
  Main | Help languages: English | English
   OEM | ANSI codepages: 437 | 1252
Far directory (FARHOME): "/nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/share/far2l/"
       Config directory: "/home/fox/.config/far2l/"
        Cache directory: "/home/fox/.cache/far2l/"
         Temp directory: "/tmp/far2l_3e8_0/"
   Command shell (User): "zsh -i"

 os-release PRETTY_NAME: NixOS 26.05 (Yarara)
                  uname: Linux 6.19.14 #1-NixOS SMP PREEMPT Tue Jan  1 00:00:00 UTC 1980 aarch64
       System component: Build/wxWidgets 3.2.9
       System component: wxWidgets 3.2.9
       System component: GTK 3.24.52
               HOSTNAME: hackbook
                   USER: fox
            FARSETTINGS: 
             FAR2L_ARGS: --wayland
                   TERM: alacritty
              COLORTERM: truecolor
       XDG_SESSION_TYPE: wayland
    XDG_SESSION_DESKTOP: Hyprland
    XDG_CURRENT_DESKTOP: Hyprland
            GDK_BACKEND: wayland
        DESKTOP_SESSION: hyprland
        WSL_DISTRO_NAME: 
  WSL2_GUI_APPS_ENABLED: 
                DISPLAY: :0
        WAYLAND_DISPLAY: wayland-1
          GTK_IM_MODULE: 
           QT_IM_MODULE: 
             XMODIFIERS: 

      Number of plugins: 26
--- Plugin#01 adb.far-plug-wide ---
Plugin#01 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/adb/plug/adb.far-plug-wide
Plugin#01 Settings Name: adb@51f7926393d94d62
Plugin#01         SysID: 0x41444250
Plugin#01      [ ] Cached  [x] Loaded 
Plugin#01 F11: [x] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#01      [ ] EditorInput 
Plugin#01      DiskMenuString:  1="ADB"
Plugin#01    PluginMenuString:  1="ADB Plugin"
Plugin#01       CommandPrefix: "adb"
--- Plugin#02 align.far-plug-wide ---
Plugin#02 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/align/plug/align.far-plug-wide
Plugin#02 Settings Name: align@48971da4346ed318
Plugin#02         SysID: 0xB076F0B0
Plugin#02      [ ] Cached  [x] Loaded 
Plugin#02 F11: [ ] Panel   [ ] Dialog  [ ] Viewer  [x] Editor 
Plugin#02      [ ] EditorInput 
Plugin#02    PluginMenuString:  1="Align block"
--- Plugin#03 arclite.far-plug-wide ---
Plugin#03 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/arclite/plug/arclite.far-plug-wide
Plugin#03 Settings Name: arclite@7fcd7e01b230c38b
Plugin#03         SysID: 0x65642111
Plugin#03      [ ] Cached  [x] Loaded 
Plugin#03 F11: [x] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#03      [ ] EditorInput 
Plugin#03    PluginMenuString:  1="ArcLite"
Plugin#03  PluginConfigString:  1="ArcLite"
Plugin#03       CommandPrefix: "arc"
--- Plugin#04 autowrap.far-plug-wide ---
Plugin#04 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/autowrap/plug/autowrap.far-plug-wide
Plugin#04 Settings Name: autowrap@aa608edd6d75f046
Plugin#04         SysID: 0xDEEC52C3
Plugin#04      [ ] Cached  [x] Loaded 
Plugin#04 F11: [ ] Panel   [ ] Dialog  [ ] Viewer  [x] Editor 
Plugin#04      [x] EditorInput 
Plugin#04    PluginMenuString:  1="Auto wrap"
--- Plugin#05 calc.far-plug-wide ---
Plugin#05 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/calc/plug/calc.far-plug-wide
Plugin#05 Settings Name: calc@a7930dfdc2caf44a
Plugin#05         SysID: 0x894EAABB
Plugin#05      [ ] Cached  [x] Loaded 
Plugin#05 F11: [x] Panel   [ ] Dialog  [x] Viewer  [x] Editor 
Plugin#05      [ ] EditorInput 
Plugin#05    PluginMenuString:  1="Calculator"
Plugin#05  PluginConfigString:  1="Calculator"
Plugin#05       CommandPrefix: "calc:"
--- Plugin#06 colorer.far-plug-wide ---
Plugin#06 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/colorer/plug/colorer.far-plug-wide
Plugin#06 Settings Name: colorer@9b86873729f592b
Plugin#06         SysID: 0xD2F36B62
Plugin#06      [ ] Cached  [x] Loaded 
Plugin#06 F11: [ ] Panel   [ ] Dialog  [ ] Viewer  [x] Editor 
Plugin#06      [x] EditorInput 
Plugin#06    PluginMenuString:  1="FarColorer"
Plugin#06  PluginConfigString:  1="FarColorer"
--- Plugin#07 compare.far-plug-wide ---
Plugin#07 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/compare/plug/compare.far-plug-wide
Plugin#07 Settings Name: compare@db2dbc52b7fd17f1
Plugin#07         SysID: 0x4F6BDE22
Plugin#07      [ ] Cached  [x] Loaded 
Plugin#07 F11: [x] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#07      [ ] EditorInput 
Plugin#07    PluginMenuString:  1="Advanced compare"
--- Plugin#08 drawline.far-plug-wide ---
Plugin#08 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/drawline/plug/drawline.far-plug-wide
Plugin#08 Settings Name: drawline@6b79094da7c538e3
Plugin#08         SysID: 0xC941E865
Plugin#08      [ ] Cached  [x] Loaded 
Plugin#08 F11: [ ] Panel   [ ] Dialog  [ ] Viewer  [x] Editor 
Plugin#08      [ ] EditorInput 
Plugin#08    PluginMenuString:  1="Draw lines"
--- Plugin#09 editcase.far-plug-wide ---
Plugin#09 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/editcase/plug/editcase.far-plug-wide
Plugin#09 Settings Name: editcase@eb97a1407c99b108
Plugin#09         SysID: 0x0E92FC81
Plugin#09      [ ] Cached  [x] Loaded 
Plugin#09 F11: [ ] Panel   [ ] Dialog  [ ] Viewer  [x] Editor 
Plugin#09      [ ] EditorInput 
Plugin#09    PluginMenuString:  1="Change Case"
--- Plugin#10 editorcomp.far-plug-wide ---
Plugin#10 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/editorcomp/plug/editorcomp.far-plug-wide
Plugin#10 Settings Name: editorcomp@5d5ce3970ca2d963
Plugin#10         SysID: 0x11ADD930
Plugin#10      [ ] Cached  [x] Loaded 
Plugin#10 F11: [ ] Panel   [ ] Dialog  [ ] Viewer  [x] Editor 
Plugin#10      [x] EditorInput 
Plugin#10    PluginMenuString:  1="Editor Autocomplete"
Plugin#10  PluginConfigString:  1="Editor Autocomplete"
--- Plugin#11 edsort.far-plug-wide ---
Plugin#11 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/edsort/plug/edsort.far-plug-wide
Plugin#11 Settings Name: edsort@e26ecc3c431da1de
Plugin#11         SysID: 0x45535254
Plugin#11      [ ] Cached  [x] Loaded 
Plugin#11 F11: [ ] Panel   [ ] Dialog  [ ] Viewer  [x] Editor 
Plugin#11      [ ] EditorInput 
Plugin#11    PluginMenuString:  1="Sort rows"
--- Plugin#12 farftp.far-plug-mb ---
Plugin#12 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/farftp/plug/farftp.far-plug-mb
Plugin#12 Settings Name: farftp@828c28dae56546a4
Plugin#12         SysID: 0x46465450
Plugin#12      [ ] Cached  [x] Loaded 
Plugin#12 F11: [x] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#12      [ ] EditorInput 
Plugin#12      DiskMenuString:  1="FTP"
Plugin#12    PluginMenuString:  1="FTP client"
Plugin#12  PluginConfigString:  1="FTP client"
Plugin#12       CommandPrefix: "ftp"
--- Plugin#13 filecase.far-plug-wide ---
Plugin#13 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/filecase/plug/filecase.far-plug-wide
Plugin#13 Settings Name: filecase@ade03cbb6271806c
Plugin#13         SysID: 0xADAC3050
Plugin#13      [ ] Cached  [x] Loaded 
Plugin#13 F11: [x] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#13      [ ] EditorInput 
Plugin#13    PluginMenuString:  1="Case conversion"
--- Plugin#14 gitgutter.far-plug-wide ---
Plugin#14 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/gitgutter/plug/gitgutter.far-plug-wide
Plugin#14 Settings Name: gitgutter@adecd91925434c1
Plugin#14      [ ] Cached  [x] Loaded 
Plugin#14 F11: [ ] Panel   [ ] Dialog  [ ] Viewer  [x] Editor 
Plugin#14      [x] EditorInput 
Plugin#14    PluginMenuString:  1="GitGutter"
Plugin#14  PluginConfigString:  1="GitGutter"
--- Plugin#15 hexitor.far-plug-wide ---
Plugin#15 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/hexitor/plug/hexitor.far-plug-wide
Plugin#15 Settings Name: hexitor@4695fc7cc8d05e5a
Plugin#15         SysID: 0x48455852
Plugin#15      [ ] Cached  [x] Loaded 
Plugin#15 F11: [x] Panel   [ ] Dialog  [x] Viewer  [x] Editor 
Plugin#15      [ ] EditorInput 
Plugin#15    PluginMenuString:  1="Hex editor"
Plugin#15  PluginConfigString:  1="Hex editor"
--- Plugin#16 ImageViewer.far-plug-wide ---
Plugin#16 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/ImageViewer/plug/ImageViewer.far-plug-wide
Plugin#16 Settings Name: ImageViewer@ddfc7ea99a75070
Plugin#16         SysID: 0x05E91C96
Plugin#16      [ ] Cached  [x] Loaded 
Plugin#16 F11: [x] Panel   [ ] Dialog  [x] Viewer  [ ] Editor 
Plugin#16      [ ] EditorInput 
Plugin#16    PluginMenuString:  1="Image Viewer"
Plugin#16  PluginConfigString:  1="Image Viewer"
Plugin#16       CommandPrefix: "img:"
--- Plugin#17 incsrch.far-plug-wide ---
Plugin#17 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/incsrch/plug/incsrch.far-plug-wide
Plugin#17 Settings Name: incsrch@2f73fcd806262fe0
Plugin#17         SysID: 0x84C0C745
Plugin#17      [ ] Cached  [x] Loaded 
Plugin#17 F11: [ ] Panel   [ ] Dialog  [ ] Viewer  [x] Editor 
Plugin#17      [ ] EditorInput 
Plugin#17    PluginMenuString:  1="Incremental Search"
Plugin#17  PluginConfigString:  1="Incremental Search"
--- Plugin#18 inside.far-plug-mb ---
Plugin#18 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/inside/plug/inside.far-plug-mb
Plugin#18 Settings Name: inside@3d931f9043b2df8d
Plugin#18         SysID: 0xFF5449D0
Plugin#18      [ ] Cached  [x] Loaded 
Plugin#18 F11: [x] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#18      [ ] EditorInput 
Plugin#18  PluginConfigString:  1="Inside"
Plugin#18       CommandPrefix: "inside"
--- Plugin#19 memo.far-plug-wide ---
Plugin#19 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/memo/plug/memo.far-plug-wide
Plugin#19 Settings Name: memo@448e3ead66708c9c
Plugin#19         SysID: 0x4D454D4F
Plugin#19      [ ] Cached  [x] Loaded 
Plugin#19 F11: [x] Panel   [x] Dialog  [x] Viewer  [x] Editor 
Plugin#19      [ ] EditorInput 
Plugin#19    PluginMenuString:  1="Memo"
Plugin#19  PluginConfigString:  1="Memo"
--- Plugin#20 mtp.far-plug-wide ---
Plugin#20 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/mtp/plug/mtp.far-plug-wide
Plugin#20 Settings Name: mtp@cca45c3ef8db204a
Plugin#20         SysID: 0x4D545050
Plugin#20      [ ] Cached  [x] Loaded 
Plugin#20 F11: [x] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#20      [ ] EditorInput 
Plugin#20      DiskMenuString:  1="MTP"
Plugin#20    PluginMenuString:  1="MTP Plugin"
Plugin#20       CommandPrefix: "mtp"
--- Plugin#21 multiarc.far-plug-mb ---
Plugin#21 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/multiarc/plug/multiarc.far-plug-mb
Plugin#21 Settings Name: multiarc@43871dcee8e38345
Plugin#21         SysID: 0x14CA31E6
Plugin#21      [ ] Cached  [x] Loaded 
Plugin#21 F11: [x] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#21      [ ] EditorInput 
Plugin#21  PluginConfigString:  1="Archive support"
Plugin#21       CommandPrefix: "ma"
--- Plugin#22 NetRocks.far-plug-wide ---
Plugin#22 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/NetRocks/plug/NetRocks.far-plug-wide
Plugin#22 Settings Name: NetRocks@ced37220f1976cac
Plugin#22         SysID: 0xAE8CE351
Plugin#22      [ ] Cached  [x] Loaded 
Plugin#22 F11: [x] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#22      [ ] EditorInput 
Plugin#22      DiskMenuString:  1="NetRocks"
Plugin#22    PluginMenuString:  1="NetRocks"
Plugin#22  PluginConfigString:  1="NetRocks options"
Plugin#22       CommandPrefix: "net:sftp:scp:shell:ftp:ftps:smb:nfs:dav:davs:aws:file:"
--- Plugin#23 OpenWith.far-plug-wide ---
Plugin#23 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/OpenWith/plug/OpenWith.far-plug-wide
Plugin#23 Settings Name: OpenWith@a0ed3eda8eeb6c12
Plugin#23         SysID: 0x93CDEF19
Plugin#23      [ ] Cached  [x] Loaded 
Plugin#23 F11: [x] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#23      [ ] EditorInput 
Plugin#23    PluginMenuString:  1="OpenWith"
Plugin#23  PluginConfigString:  1="OpenWith"
--- Plugin#24 SimpleIndent.far-plug-wide ---
Plugin#24 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/SimpleIndent/plug/SimpleIndent.far-plug-wide
Plugin#24 Settings Name: SimpleIndent@5b2d927835714c32
Plugin#24         SysID: 0x52D8EECB
Plugin#24      [ ] Cached  [x] Loaded 
Plugin#24 F11: [ ] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#24      [x] EditorInput 
--- Plugin#25 tmppanel.far-plug-wide ---
Plugin#25 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/tmppanel/plug/tmppanel.far-plug-wide
Plugin#25 Settings Name: tmppanel@558392f6a061eb88
Plugin#25         SysID: 0xB77C964B
Plugin#25      [ ] Cached  [x] Loaded 
Plugin#25 F11: [x] Panel   [ ] Dialog  [ ] Viewer  [ ] Editor 
Plugin#25      [ ] EditorInput 
Plugin#25      DiskMenuString:  1="temporary"
Plugin#25    PluginMenuString:  1="Temporary panel"
Plugin#25  PluginConfigString:  1="Temporary panel"
Plugin#25       CommandPrefix: "tmp"
--- Plugin#26 truncate.far-plug-wide ---
Plugin#26 /nix/store/qrzsxqqwvzh8gv9mbjm8m9qzzrym6kx1-far2l-2.8.0-dd06e95/lib/far2l/Plugins/truncate/plug/truncate.far-plug-wide
Plugin#26 Settings Name: truncate@de0dffd0fd3cf0d9
Plugin#26         SysID: 0x54524354
Plugin#26      [ ] Cached  [x] Loaded 
Plugin#26 F11: [ ] Panel   [ ] Dialog  [ ] Viewer  [x] Editor 
Plugin#26      [ ] EditorInput 
Plugin#26    PluginMenuString:  1="Truncate File"

fixed in patch bellow

@tempergate

tempergate commented May 11, 2026

Copy link
Copy Markdown
Contributor
> same skip for Nix

I tried add a wayout for Nix to make it buildable
mtp-plugin-cl.patch
unfortunately I got an error in build with libusblocal.

There is an easy way to take if there is Nix or not in CMake

set(IS_NIX FALSE)

# Check common Nix indicators
if(DEFINED ENV{NIX_BUILD_TOP})
    message(STATUS "Detected Nix: NIX_BUILD_TOP is set")
    set(IS_NIX TRUE)
elseif(DEFINED ENV{NIX_STORE})
    message(STATUS "Detected Nix: NIX_STORE is set")
    set(IS_NIX TRUE)
elseif(CMAKE_PREFIX_PATH MATCHES "/nix/store/")
    message(STATUS "Detected Nix: /nix/store in CMAKE_PREFIX_PATH")
    set(IS_NIX TRUE)
elseif(CMAKE_SYSTEM_PREFIX_PATH MATCHES "/nix/store/")
    message(STATUS "Detected Nix: /nix/store in CMAKE_SYSTEM_PREFIX_PATH")
    set(IS_NIX TRUE)
endif()

but then I do not understand what to change. The revision 7488db1 was fully working, but now there is a mess i do not understand how to solve

fixed in patch bellow

@tempergate

tempergate commented May 11, 2026

Copy link
Copy Markdown
Contributor

Finally wrote a working patch
@stpork , please, add it to your branch
mtp-plugin-cl.patch
* I think libusb/CMakeLists.txt could be ignored, but ../CMakeLists.txt, CMakeLists.txt and libmtp/CMakeLists.txt are necessary

now ed3fa3d is working for Nix too
image

@stpork

stpork commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

@tempergate Thanks for the patch and the repro log.
I landed a different fix: a single CMake flag MTP_SYSTEM_LIBUSB.

  • Auto ON on FreeBSD and Nix (detected via $NIX_STORE / $NIX_BUILD_TOP / /nix/store/ in CMake prefix paths) → system-installed libusb
  • Auto OFF elsewhere → static libusb.
  • Manual override anywhere: -DMTP_SYSTEM_LIBUSB=ON or =OFF.

For your Nix derivation: keep libusb in buildInputs, no flag needed. If auto-detect fails, add -DMTP_SYSTEM_LIBUSB=ON.

When system libusb is picked, cmake prints:
MTP plugin enabled (system libusb-1.0; override with -DMTP_SYSTEM_LIBUSB=OFF)

Please check on NixOS and confirm the plugin sees your device?

Also: if you can build with -DMTP_SYSTEM_LIBUSB=OFF (forces vendored) and run with LIBUSB_DEBUG=4 I can look at why the static libusb fails on NixOS — the log you posted only shows Libusb1 init failed, which isn't enough to see the root cause.

@tempergate

Copy link
Copy Markdown
Contributor

For your Nix derivation: keep libusb in buildInputs, no flag needed. If auto-detect fails, add -DMTP_SYSTEM_LIBUSB=ON.

Thanks, it works

@akruphi

akruphi commented May 26, 2026

Copy link
Copy Markdown
Contributor

Instead, I wired libusb statically into the plugin and rebased.

IMHO static usage of external library is not good unless absolutely necessary.

For example for packaging in Debian/Ubuntu repositories we need addition restrictions. @alexmyczko or @mitya57 please explain the preferable way in such case.

@stpork

stpork commented May 26, 2026

Copy link
Copy Markdown
Contributor Author

@akruphi I've added the flag and set it as ON by default:
- MTP_SYSTEM_LIBUSB (default ON) — links system libusb-1.0. OFF switches to the vendored static.

@mitya57

mitya57 commented May 26, 2026

Copy link
Copy Markdown
Contributor

For Debian/Ubuntu, I would prefer if it could build with system MTP too (libmtp-dev package), not just system libusb. Is that possible?

@stpork

stpork commented May 26, 2026

Copy link
Copy Markdown
Contributor Author

@mitya57 , yes that is possible - there is -DMTP_SYSTEM_LIBMTP flag too. However, you will get like 10x slower enumerations on directories with > 100 files due to sub-optimal protocol implementation in standard libMTP. Still manageable for ordinary user though. If that's ok you can use for Debian something like

    dh_auto_configure -- -DMTP_SYSTEM_LIBUSB=ON -DMTP_SYSTEM_LIBMTP=ON

@mitya57

mitya57 commented May 26, 2026

Copy link
Copy Markdown
Contributor

Is it possible to forward your optimizations to upstream libMTP?

@stpork

stpork commented May 26, 2026

Copy link
Copy Markdown
Contributor Author

It is possible but there are few things I was trying to avoid:

  • I am not Linux developer, I do everything on Mac
  • libMTP upstream is slow -> last release is from Oct-2024 and it is lots of work for me to do all required tests and all devices they require (otherwise they will reject)
  • the only reason to use libMTP is their declared compatibility with tons of devices (mitigating corresponding glitches, bugs, protocol workaround etc). I completely disagree with how they (not) implemented MTP 1.0 protocol performance extensions -> they chose "slow and safe" way for the whole variety of devices, whereas my performance patches may be not working correctly on some very old mobile phones.

I would suggest that we keep it "default slow" on Debian. It is like 1-5 seconds of waiting for the user instead of instant browse, which is mitigated by cache on subsequent access of same dirs (once objects are in cache - it is instant). I will try to submit PR to libMTP when have time but have some doubts if they would consider it is as "risky" due to fact that some old Nokia phones cannot do them properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants