Issue running / packaging an AppImage

Glad to hear that we’re on the same page :slightly_smiling_face:

Thanks for the clarification, I think I got confused by the similarity of ldd and LD_....

I went ahead and removed the lib directory, but since I couldn’t find the liblog4cplusU.so.9 library in Nix packages, I kept only this one from the AppImage content. I’m now left with this in my store:

$ nix shell 'nixpkgs#tree' -c tree -d -L 2
.
├── bin
├── lib
├── resources
├── share
│   ├── applications
│   ├── icons
│   ├── kDrive_client
│   └── mime
└── translations
    └── qtwebengine_locales

While lib contains only:

-r--r--r-- 1 root root 6,7M  1 janv.  1970 liblog4cplusU.so.9

I took a look at the Qt documentation in the Nixpkgs manual and went ahead to wrap kDrive as a Qt application:

all-packages.nix

kdrive = qt6Packages.callPackage ../applications/misc/kdrive { };

kdrive/default.nix

stdenv.mkDerivation rec {
  # ...
  dontWrapQtApps = true;

  buildInputs = [ qtbase ];
  nativeBuildInputs = [ wrapQtAppsHook ];

  # ...

  postFixup = ''
    # patchelf stuff

    wrapQtApp $out/bin/kDrive
  '';
}

Full diff available here

Now, I can see the kDrive desktop entry in Gnome, but I still can’t run it somehow.

When running kDrive I see again the initial error message, alongside a Qt error:

$ kDrive
kDrive server starting
qt.qpa.plugin: Could not find the Qt platform plugin "wayland" in ""
kDrive server initialization error: Unable to open parameters database.

I can get rid of the Qt error by following what @Rigor1934 mentioned yesterday: adding QT_QPA_PLATFORM=xcb. But the server initialization error remains.

Looking at the logs, I have this:

2024-02-07 16:05:16:140 [I] (140268897102400) log.cpp:126 - Logger initialization done
2024-02-07 16:05:16:141 [I] (140268897102400) appserver.cpp:2848 - kDrive locale:[en_US] version:[3.5.7master (build 20240124)] os:[NixOS 24.05 (Uakari)]
2024-02-07 16:05:16:141 [I] (140268897102400) appserver.cpp:166 - New DB exists : /home/nicolas/.config/kDrive/.parms.db => 1
2024-02-07 16:05:16:141 [I] (140268897102400) appserver.cpp:167 - Old config exists : /home/nicolas/.config/kDrive/kDrive.cfg => 1
2024-02-07 16:05:16:141 [D] (140268897102400) db.cpp:562 - sqlite3 version=3.44.2
2024-02-07 16:05:16:141 [D] (140268897102400) db.cpp:578 - sqlite3 locking_mode=normal
2024-02-07 16:05:16:141 [D] (140268897102400) db.cpp:595 - sqlite3 journal_mode=wal
2024-02-07 16:05:16:141 [D] (140268897102400) db.cpp:615 - sqlite3 synchronous=NORMAL
2024-02-07 16:05:16:141 [D] (140268897102400) db.cpp:630 - sqlite3 case_sensitivity=ON
2024-02-07 16:05:16:141 [D] (140268897102400) db.cpp:645 - sqlite3 foreign_keys=ON
2024-02-07 16:05:16:141 [D] (140268897102400) db.cpp:348 - Check DB version
2024-02-07 16:05:16:141 [I] (140268897102400) db.cpp:441 - Prepare DB
2024-02-07 16:05:16:142 [W] (140268897102400) parmsdb.cpp:611 - Cannot open exclusion templates file sync-exclude.lst
2024-02-07 16:05:16:142 [W] (140268897102400) parmsdb.cpp:1275 - Error in updateExclusionTemplates
2024-02-07 16:05:16:142 [W] (140268897102400) parmsdb.cpp:1224 - Error in initParameters
2024-02-07 16:05:16:142 [W] (140268897102400) db.cpp:443 - Error in Db::prepare
2024-02-07 16:05:16:142 [E] (140268897102400) db.cpp:649 - Database initialisation error
2024-02-07 16:05:16:142 [D] (140268897102400) db.cpp:241 - Closing DB /home/nicolas/.config/kDrive/.parms.db
2024-02-07 16:05:16:142 [D] (140268897102400) db.cpp:472 - No database Transaction to commit

At first, I thought it was a permissions issue with the sync-exclude.lst file, so I tried to use install instead of cp to set its permissions to rw-rw-rw- but it doesn’t work (and I think this is normal since the Nix store is and should remain read-only):

installPhase = ''
  runHook preInstall

  for dir in resources translations; do
    mkdir -p $out/$dir
    cp -R ${contents}/usr/$dir/* $out/$dir
  done
  mkdir -p $out/bin
  install -m 0555 ${contents}/usr/bin/kDrive $out/bin
  install -m 0555 ${contents}/usr/bin/kDrive_client $out/bin
  install -m 0444 ${contents}/usr/bin/qt.conf $out/bin
  install -m 0666 ${contents}/usr/bin/sync-exclude.lst $out/bin
  ls -lah $out/bin
  for dir in applications icons kDrive_client mime; do
    mkdir -p $out/share/$dir
    cp -R ${contents}/usr/share/$dir/* $out/share/$dir
  done
  mkdir -p $out/lib
  cp -R ${contents}/usr/lib/liblog4cplusU.so.9 $out/lib

  runHook postInstall
'';

Here is the bin directory listing:

$ ls -lah bin
total 26M
dr-xr-xr-x 2 root root 4,0K  1 janv.  1970 .
dr-xr-xr-x 7 root root 4,0K  1 janv.  1970 ..
-r-xr-xr-x 1 root root  16K  1 janv.  1970 kDrive
-r-xr-xr-x 1 root root  12M  1 janv.  1970 kDrive_client
-r-xr-xr-x 1 root root  15M  1 janv.  1970 .kDrive-wrapped
-r--r--r-- 1 root root  108  1 janv.  1970 qt.conf
-r--r--r-- 1 root root  315  1 janv.  1970 sync-exclude.lst

No symbolic links, nothing. The sync-exclude.lst file is read-only and I suspect this to be the issue.

I’m wondering if I could place the file somewhere else where it would be writable and create a symlink in the store location. I’ll try to do that later and keep you posted.

Thanks again for your help, let me know if you have any more of your good ideas/pointers :smile:

EDIT: I found a weird thing!

If I cd in kDrive location in the Nix store, and run kDrive from the bin directory, it works! That’s so frustrating, I feel that I’m very close to make it work but I don’t fraking understand why it tries to load the file relatively from the PWD

Ok, I can now launch the application from its desktop entry and see the graphical interface.

However, the application is really slow, and I can’t see the checkboxes in the preferences window for example. I’ll have to dig deeper, but that’s a huge step!

I wouldn’t have been able to go this far without your help @Cloudef :partying_face:

EDIT

I have been able to compare the behavior from an Ubuntu VM. I can confirm that the application is working since I managed to connect to my account and synchronize some folders.

However, I found several things which are not working:

  • some graphical elements (like toggles, icons or checkboxes) are not showing at all
  • the Gnome integration is not working
  • after login, the application is just black so I cannot use it as-is

There are no errors showing in the logs, and I can’t find a way to debug the graphical part of the application.

EDIT 2

I suspect that the missing graphical elements are related to the QT_QPA_PLATFORMTHEME variable but whatever I try (gtk2, gtk3, qtc5) the application is always missing some elements.

As for the Gnome integration, I didn’t find anything related to Gnome in the files. I didn’t search anything related to that, yet. It just works OOTB in Ubuntu.

Regarding the application slowness, it’s not the whole app, only the web views are slow (really really slow). All inputs are taken right away, but the visual feedback is lagging far behind.
Example: I click on the email input, then type in my email, hit tab to switch to the password input, type in my password and I have to wait for ~30s before seeing the fields filled with my inputs.

It could be the app uses some custom Qt plugins that it needs for full functionality, so the files bundled in the AppImage might’ve been there for a reason. The app might not read from $out/share/icons which would explain missing icons. Strace is your friend again.

Bit unrelated, but I made progress with my Flatpak by copying the sync-exclude.lst to the root of the appimage folder. I now manage to start kDrive but I get this error:

user@fedora:~/flatpak$ flatpak run com.infomaniak.kdrive
kDrive server starting

(process:3): GLib-GObject-CRITICAL **: 13:23:13.440: type_add_flags_W: assertion '(flags & ~TYPE_FLAG_MASK) == 0' failed
/app/kdrive/usr/lib/libgnutls.so.30: version `GNUTLS_3_7_4' not found (required by /usr/lib/x86_64-linux-gnu/gio/modules/libgiognutls.so)
Failed to load module: /usr/lib/x86_64-linux-gnu/gio/modules/libgiognutls.so

(process:3): GLib-GObject-CRITICAL **: 13:23:13.440: type_add_flags_W: assertion '(flags & ~TYPE_FLAG_MASK) == 0' failed

and the kDrive window just shows a message “This site can’t be reached” “ERR_CERT_AUTHORITY_INVALID” (I think it’s uses QtWebEngine or another webview implementation to get to the login page).

Any ideas how to fix it?

Ok, I made it (mostly) fully work by using the whole original lib and plugins directories.

I tried getting rid of the lib directory but ended up having to keep the following libs so neither ldd nor qt complains about missing libraries:

.
├── libjbig.so.0
├── libjpeg.so.8
├── liblog4cplusU.so.9
├── libtiff.so.5
└── libwebp.so.6

But then the application wouldn’t launch its graphical interface. So I reverted my changes and stuck with the original lib and plugins directories. Everything (aside from the Gnome tray icon) was working fine, so I decided to retry the whole setup from the beginning: I logged out of my account to retry the login process.

Sadly, there are still very poor performances on the signin window (which is IMO a simple webview so I don’t quite understand)… But for now I guess it’s pretty good since I can use the app without any bugs nor performance issues when I’m logged in my account. And the two-way sync works perfectly.

I’ll try to make the Gnome tray icon work because once I close the UI I can’t relaunch it since it’s running in background and complaining that « kDrive application is already running ».


@Rigor1934 I don’t know anything about flatpak, are you trying to write a Nix derivation for flatpak?

Did you try ldd to see what are the missing libs required by your binary?

If you want to see what I have done so far, you can look at this file in my nixpkgs repository.

1 Like

I managed to make the tray icon work by adding this Gnome extension.

Now all that remains is to find why the webview is so slow… But I’m kinda stuck on this :frowning_face:

No, nothing to do with Nix, I’m just reading here because you are the only person who ever tried to repackage kDrive :smiley:

My Flatpak starts but I get the error “ERR_CERT_AUTHORITY_INVALID” in the QtWebEngine login page. I was just wondering if you had a similar problem at any point or if this is purely a Flatpak issue.

Not sure I could be of any help on this matter I’m afraid :confused:

Did you add p11-kit to your dependencies?

Hi there!
Thanks a lot for all your work, you saved me a ton of time trying to do this!

I’ve upgraded the kDrive package to the latest version, needed to change some things (they removed the mime folder, and I needed to add qt6.qtwebengine to libPath), and I got the same result as you: server working, client login really slow (but the rest is ok) and no tray icon (I’m on kde), but I’m seeing the sync notifications.

I saw that there’s a public repository with the app code, maybe it’s better to build it from source instead of extracting the AppImage?

The script to build the appimage is here, I’ll try to see if I can come up with something (not really good at c++ compilation and really new to nixOs :sweat_smile: )

1 Like

Oh my, hi!

This repository didn’t exist at the time of this post! It’s only 3 months old.

But that’s a very good news because now I can spend some time trying to build the app the right way ! I was reluctant to make a PR with the current packaging given the issues you mentioned.

However, regarding the tray icon, I do have it working after installing appindicator on my system :slightly_smiling_face:

Thanks for sharing!

2 Likes

I spent some time today looking at the repository and trying to package from source. This attempt, which is not working (yet?), can be seen here.

The main issues are with log4cplus. There’s also a warning about shared-mime-info which I haven’t got into yet.

Regarding log4cplus, first I had an issue when just using it as packaged in nixpkgs. This issue arose because the nixpkgs build of log4cplus is using Make, which doesn’t generate some files that are required for kDrive to build. Here is the error message:

CMake Error at src/libcommon/CMakeLists.txt:5 (find_package):
  By not providing "Findlog4cplus.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "log4cplus", but CMake did not find one.

  Could not find a package configuration file provided by "log4cplus"
  (requested version 2.1.0) with any of the following names:

    log4cplusConfig.cmake
    log4cplus-config.cmake

  Add the installation prefix of "log4cplus" to CMAKE_PREFIX_PATH or set
  "log4cplus_DIR" to a directory containing one of the above files.  If
  "log4cplus" provides a separate development package or SDK, be sure it has
  been installed.

I found out that when log4cplus is built with CMake, those files are generated. So, as seen in the file in my repo, I overrode log4cplus to use CMake:

(log4cplus.overrideAttrs(_: {
  nativeBuildInputs = [ cmake ];
}))

Sadly, I then encountered an error on log4cplus build (look at the mentioned GitHub issue for details):

Broken paths found in a .pc file! /nix/store/rrgmy2h6y4kljxq99dhjag4wh5zavk1r-log4cplus-2.1.1/lib/pkgconfig/log4cplus.pc
The following lines have issues (specifically '//' in paths).
3:libdir=${prefix}//nix/store/rrgmy2h6y4kljxq99dhjag4wh5zavk1r-log4cplus-2.1.1/lib
4:includedir=${prefix}//nix/store/rrgmy2h6y4kljxq99dhjag4wh5zavk1r-log4cplus-2.1.1/include
It is very likely that paths are being joined improperly.
ex: "${prefix}/@CMAKE_INSTALL_LIBDIR@" should be "@CMAKE_INSTALL_FULL_LIBDIR@"
Please see https://github.com/NixOS/nixpkgs/issues/144170 for more details.

I found two ways to fix this issue:

  • with substituteInPlace on preInstall:
preInstall = ''
  substituteInPlace ./lib/pkgconfig/log4cplus.pc --replace-fail "''${prefix}/" ""
'';
patches = [ ./log4cplus-CMakeLists.txt.patch ];

With this fix in place, kDrive does start to build but it fails around 75% with a somewhat cryptic Make error:

make[2]: *** No rule to make target '/var/empty/local/lib/liblog4cplusU.so', needed by 'bin/kDrive_client'.  Stop.
(more build logs)
make[1]: *** [CMakeFiles/Makefile2:547: src/gui/CMakeFiles/kDrive_client.dir/all] Error 2

I won’t have much time to look into this until next weekend, so if someone would like to give it a shot I’ll gladly take it :slight_smile:

I found that kDrive is using the Unicode version of log4cplus and when building via cmake you need to enable the option

(log4cplus.overrideAttrs(_: {
      nativeBuildInputs = [ cmake ];
			cmakeFlags = [
				"-DUNICODE=ON"
			];
      patches = [ ./log4cplus-CMakeLists.txt.patch ];
      /* preInstall = ''
        substituteInPlace ./lib/pkgconfig/log4cplus.pc --replace-fail "''${prefix}/" ""
      ''; */
    }));

It seems like the CmakeLists in kDrive was trying to find log4cplus and xxHash inside /usr/local/lib. So I made a patch to correct this. The build now works ! But the install fails…

error: builder for '/nix/store/6x9dj9m1rw179ywy37yp0l9vq8pgfd1h-kDrive-3.6.1.drv' failed with exit code 1;
       last 10 log lines:
       > [0/1] Install the project...
       > -- Install configuration: "Release"
       > CMake Error at cmake_install.cmake:54 (file):
       >   file cannot create directory: /kDrive.  Maybe need administrative
       >   privileges.
       >
       >
       > FAILED: CMakeFiles/install.util
       > cd /build/source/build && /nix/store/q1nssraba326p2kp6627hldd2bhg254c-cmake-3.29.2/bin/cmake -P cmake_install.cmake
       > ninja: build stopped: subcommand failed.
       For full logs, run 'nix log /nix/store/6x9dj9m1rw179ywy37yp0l9vq8pgfd1h-kDrive-3.6.1.drv'.
error: 1 dependencies of derivation '/nix/store/czr2mlyl4hhd1bs5n0gg5zywn6lyima3-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/kgx1l6cpjkdmj85fj093n4x2j4yc9nqn-nixos-system-laptop-nix-24.05.20240615.752c634.drv' failed to build

I added SYSCONF_INSTALL_DIR CMake flag to etc. So that the file is created inside the nix store

cmakeFlags = [
    "-DKDRIVE_THEME_DIR=${src}/infomaniak"
    "-DSYSCONF_INSTALL_DIR=etc"
];

It then threw an error because CMake was unable to create the binary without a bin dir

error: builder for '/nix/store/0v6xxh7wn12lbcl7y3v4i60g4mkbhqgg-kDrive-3.6.1.drv' failed with exit code 1;
       last 10 log lines:
       >   "/nix/store/dwsh67s76rblcyi1jw9av4mqacqg6hvd-kDrive-3.6.1/bin/kDrive_client":
       >   No such file or directory.
       > Call Stack (most recent call first):
       >   src/cmake_install.cmake:52 (include)
       >   cmake_install.cmake:59 (include)
       >
       >
       > FAILED: CMakeFiles/install.util
       > cd /build/source/build && /nix/store/q1nssraba326p2kp6627hldd2bhg254c-cmake-3.29.2/bin/cmake -P cmake_install.cmake
       > ninja: build stopped: subcommand failed.
       For full logs, run 'nix log /nix/store/0v6xxh7wn12lbcl7y3v4i60g4mkbhqgg-kDrive-3.6.1.drv'.
error: 1 dependencies of derivation '/nix/store/bkcvqmplaixaahzhb66dqq9vyzav6adh-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/qm17iclz48i5f0icafn4jgi0d0pv0qd7-nixos-system-laptop-nix-24.05.20240615.752c634.drv' failed to build

I created a bin directory before the preInstall

preInstall = ''
   mkdir -p $out/bin
   runHook preInstall
      ''; 

The installation now fails because of a segfault without any logs or error (even in the full logs)

error: builder for '/nix/store/pap25xbqqd2sv1hmn7mih19dg2r3xh34-kDrive-3.6.1.drv' failed due to signal 11 (Segmentation fault);
       last 10 log lines:
       > [277/283] Building CXX object src/server/CMakeFiles/kDrive.dir/__/libcommonserver/commserver.cpp.o
       > [278/283] Linking CXX executable /nix/store/lxaz8jiwkxzp3qbhbvvvrqld1ihgkzij-kDrive-3.6.1/bin/kDrive_client
       > [279/283] Building CXX object src/server/CMakeFiles/kDrive.dir/migration/migrationparams.cpp.o
       > [280/283] Building CXX object src/server/CMakeFiles/kDrive.dir/socketapi.cpp.o
       > [281/283] Building CXX object src/server/CMakeFiles/kDrive.dir/kDrive_autogen/YCDLW3T4OG/qrc_client.cpp.o
       > [282/283] Building CXX object src/server/CMakeFiles/kDrive.dir/appserver.cpp.o
       > [283/283] Linking CXX executable /nix/store/lxaz8jiwkxzp3qbhbvvvrqld1ihgkzij-kDrive-3.6.1/bin/kDrive
       > buildPhase completed in 1 minutes 27 seconds
       > Running phase: glibPreInstallPhase
       > Running phase: installPhase

I have no clue on why it does this. It’s been a while since I’m trying to package kDrive but for now i’m using owncloud since kDrive was based on this and it works.

Let me know if you find something to overcome this error (You can look at my package here).

1 Like

Sorry for the late reply, I only had a few minutes to bother with this in the last few days. However, I managed to make the build work with some shenanigans.

First of all, thanks for the pointer on log4cplus, it now builds!

I didn’t have to create the bin directory on my side, however I had to move some files around after the install process was done. Everything is here.

Here are the operations performed in the post install hook, with some explanation as to why they are needed:

# After build, there are binaries in the way that differ from the one generated by make install
rm -rf $out/bin

# Because DESTDIR is set to $out, built files end up in /nix/store/<hash>-kDrive-<version>/nix/store/<hash>-kDrive-<version>
mv $out$out/* $out
rm -rf $out/nix

# The binary fails to start if sync-exclude.lst is not located in the same directory
mv $out/etc/kDrive/sync-exclude.lst $out/bin/sync-exclude.lst

# We don’t need the libsentry and libxxhash which are generated by the install process
rm -rf $out/etc

With this version, the build works and the app runs fine, however there still are a few issues:

  • when starting kDrive from a terminal, the current working directory must be the store’s bin directory or else it can’t find the sync-exclude.lst file
  • the login webview is still very very slow and buggy (maybe more than with the AppImage)

When started from the Gnome menu, the app is running fine and doesn’t complain about not being able to find the sync-exclude.lst file.

I feel I’m very close to a pretty great solution, but all the file movements in the post install hook seem like a dirty hack… I tried to patch the CMake generated files that reference the DESTDIR variable but then the build fails.

Also, the fact that I have to choose between the bin directory or the $DESTDIR/bin directory feels weird.

And also the webview is quite unusable, so this cannot be sent to nixpkgs yet…

So, I spent some more time on this and built the application from the sources in an Ubuntu VM. I’m following the build guide from upstream and I end up in the same situation: the login webview is pretty much unusable.

However, one thing worth to note is that I’m able to run the kDrive binary no matter what is the current directory.

I’ll try to make the webview work on Ubuntu first and then copy-paste in the Nix derivation. So far I did try to install Qt from the Qt installer rather than from apt and this doesn’t change anything. I tried multiple Qt versions, without success.

Long shot, but I opened an issue on the official repository for this matter. I guess it would help if some :+1: were added to it :grimacing: