Help to Upgrade a Package - Dependencies Failing to Build

I use MegaSync as my cloud sync, and the current version (4.9.0.0) is over a year old now, so I am trying to upgrade it to 4.12.2.0, and hoping that it’s mostly a case of updating the version number and file hash.

I have forked the nixpkgs repo, created a branch on my fork, and now I’m trying to build the existing package to test my environment before I make any changes. I am following this guide, so I added this to my config:

nixpkgs.overlays = [
    (final: prev: {
      mymegasync = prev.megasync.overrideAttrs (previousAttrs: {
        src = ../../nixpkgs/pkgs/applications/misc/megasync;
      });
    })
  ];

… and then imported mymegasync instead of megasync. Trying to build it with nixos-rebuild build I get the following errors:

building Nix...
building the system configuration...
these 16 derivations will be built:
  /nix/store/95cg6gka0d2smyfpqzb0hs3g30j4nsby-megasync-4.9.0.0.drv
  /nix/store/qc3rc8g5ypq5xfgb000xg6rsc8lfxrkv-system-path.drv
  /nix/store/zdfl1crq7fh0gsmk221iayfja6fpkhjp-dbus-1.drv
  /nix/store/r2f10bd282cnfs63rbba6hwcsiqiiyq7-X-Restart-Triggers-dbus.drv
  /nix/store/13vjkm9xircmc8q6zgnkzvj6kvy49p32-unit-dbus.service.drv
  /nix/store/3zfw99szkra4hffa3dxg5czsb6wkmyxk-etc-pam-environment.drv
  /nix/store/4vnm6m3q3gskligk6rc77ymb5n1d9isj-set-environment.drv
  /nix/store/1p5wcalhan8k8xzcyixifynrmhchbc25-X-Restart-Triggers-polkit.drv
  /nix/store/ls2l62dxajx3vsc6hdbazcnm59lglxj4-unit-polkit.service.drv
  /nix/store/v1sxa5j3x1rkn3z1zb1nkx2icw706zc8-unit-accounts-daemon.service.drv
  /nix/store/xz7dk8dhx12pb6h9294vhcr5rsr7mj7v-unit-dbus.service.drv
  /nix/store/axvlmwrzav46q2p4znnv3phkg6h6dmsj-system-units.drv
  /nix/store/knbvvpxp6qdszdwk60piybr4wm8x22j2-etc-profile.drv
  /nix/store/p0337lxkmsnxh0y46imc1l2qxj8vnfcy-user-units.drv
  /nix/store/zsj8sa7zyhm39sxfffmn5d9f3xs8qahc-etc.drv
  /nix/store/193g6cmlfarzczdgx37p8xn6sypbgqcx-nixos-system-atrius-23.11.4703.c5101e457206.drv
building '/nix/store/95cg6gka0d2smyfpqzb0hs3g30j4nsby-megasync-4.9.0.0.drv'...
Running phase: qtPreHook
Running phase: unpackPhase
unpacking source archive /nix/store/3nmy7nmdj2ql9hfi4yg3yzxn1fk057j2-megasync
source root is megasync
Running phase: patchPhase
applying patch /nix/store/qscc11iqhxsqqfs4yvwn2mw0i0s9fn2z-noinstall-distro-version.patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: source/src/MEGASync/platform/platform.pri
|===================================================================
|--- source.orig/src/MEGASync/platform/platform.pri
|+++ source/src/MEGASync/platform/platform.pri
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
error: builder for '/nix/store/95cg6gka0d2smyfpqzb0hs3g30j4nsby-megasync-4.9.0.0.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/qc3rc8g5ypq5xfgb000xg6rsc8lfxrkv-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/1p5wcalhan8k8xzcyixifynrmhchbc25-X-Restart-Triggers-polkit.drv' failed to build
error: 1 dependencies of derivation '/nix/store/zdfl1crq7fh0gsmk221iayfja6fpkhjp-dbus-1.drv' failed to build
error: 1 dependencies of derivation '/nix/store/3zfw99szkra4hffa3dxg5czsb6wkmyxk-etc-pam-environment.drv' failed to build
error: 1 dependencies of derivation '/nix/store/4vnm6m3q3gskligk6rc77ymb5n1d9isj-set-environment.drv' failed to build
error: 1 dependencies of derivation '/nix/store/v1sxa5j3x1rkn3z1zb1nkx2icw706zc8-unit-accounts-daemon.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/r2f10bd282cnfs63rbba6hwcsiqiiyq7-X-Restart-Triggers-dbus.drv' failed to build
error: 1 dependencies of derivation '/nix/store/knbvvpxp6qdszdwk60piybr4wm8x22j2-etc-profile.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ls2l62dxajx3vsc6hdbazcnm59lglxj4-unit-polkit.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/13vjkm9xircmc8q6zgnkzvj6kvy49p32-unit-dbus.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/xz7dk8dhx12pb6h9294vhcr5rsr7mj7v-unit-dbus.service.drv' failed to build
error: 3 dependencies of derivation '/nix/store/axvlmwrzav46q2p4znnv3phkg6h6dmsj-system-units.drv' failed to build
error: 1 dependencies of derivation '/nix/store/p0337lxkmsnxh0y46imc1l2qxj8vnfcy-user-units.drv' failed to build
error: 7 dependencies of derivation '/nix/store/zsj8sa7zyhm39sxfffmn5d9f3xs8qahc-etc.drv' failed to build
error: 2 dependencies of derivation '/nix/store/193g6cmlfarzczdgx37p8xn6sypbgqcx-nixos-system-atrius-23.11.4703.c5101e457206.drv' failed to build

There’s no more information about why the dependencies failed to build, but since this is based on my existing configuration, I can’t understand why it doesn’t work. I also tried starting a nix-shell with some of the dependencies, but all of the QT ones cause errors, so although this command works it still results in exactly the same error log above.
nix-shell -p autoconf automake c-ares cryptopp curl doxygen ffmpeg freeimage libmediainfo libraw libsodium libtool libuv libzen lsb-release sqlite swig unzip wget

So now I’m a bit lost. Am I following the right approach? I’d love to figure out how to help out and upgrade this package for myself and others.

Edit: I managed to get the nix-shell starting up with all of the buildInputs. The QT package paths had changed to have “libsForQt5.qt5” in front of them, so this worked to start the shell:

nix-shell -p autoconf automake doxygen libtool lsb-release pkg-config libsForQt5.qt5.qttools swig unzip c-ares cryptopp curl ffmpeg freeimage libmediainfo libraw libsodium libuv libzen libsForQt5.qt5.qtbase libsForQt5.qt5.qtx11extras sqlite wget

But the build still failed with the same error:

1 out of 1 hunk ignored
error: builder for '/nix/store/95cg6gka0d2smyfpqzb0hs3g30j4nsby-megasync-4.9.0.0.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/qc3rc8g5ypq5xfgb000xg6rsc8lfxrkv-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/1p5wcalhan8k8xzcyixifynrmhchbc25-X-Restart-Triggers-polkit.drv' failed to build
error: 1 dependencies of derivation '/nix/store/zdfl1crq7fh0gsmk221iayfja6fpkhjp-dbus-1.drv' failed to build
error: 1 dependencies of derivation '/nix/store/3zfw99szkra4hffa3dxg5czsb6wkmyxk-etc-pam-environment.drv' failed to build
error: 1 dependencies of derivation '/nix/store/4vnm6m3q3gskligk6rc77ymb5n1d9isj-set-environment.drv' failed to build
error: 1 dependencies of derivation '/nix/store/v1sxa5j3x1rkn3z1zb1nkx2icw706zc8-unit-accounts-daemon.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/r2f10bd282cnfs63rbba6hwcsiqiiyq7-X-Restart-Triggers-dbus.drv' failed to build
error: 1 dependencies of derivation '/nix/store/knbvvpxp6qdszdwk60piybr4wm8x22j2-etc-profile.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ls2l62dxajx3vsc6hdbazcnm59lglxj4-unit-polkit.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/13vjkm9xircmc8q6zgnkzvj6kvy49p32-unit-dbus.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/xz7dk8dhx12pb6h9294vhcr5rsr7mj7v-unit-dbus.service.drv' failed to build
error: 3 dependencies of derivation '/nix/store/axvlmwrzav46q2p4znnv3phkg6h6dmsj-system-units.drv' failed to build
error: 1 dependencies of derivation '/nix/store/p0337lxkmsnxh0y46imc1l2qxj8vnfcy-user-units.drv' failed to build
error: 7 dependencies of derivation '/nix/store/zsj8sa7zyhm39sxfffmn5d9f3xs8qahc-etc.drv' failed to build
error: 2 dependencies of derivation '/nix/store/193g6cmlfarzczdgx37p8xn6sypbgqcx-nixos-system-atrius-23.11.4703.c5101e457206.drv' failed to build

After a lot of headscratching it seems like my approach was the problem. Rather than trying to link to the source and do nix-rebuild, I have had some success by navigating to the megasync directory within nixpkgs and running:

nix-build -E 'with import <nixpkgs> {}; callPackage ./default.nix {}'

The build errors were similar to before, which turned out to be related to the QT libraries, which now have to be specified between libsForQt5 and qt6.

nix-build is now starting to build the module and is falling over at the ffmpeg_44 patch. So I think I have answered my original question about the method to build the module and the dependencies. I may be a little out-of-my-depth with this patch failing but I’ll give it a go.

1 Like

The problems is that the patches from nixpkgs no longer apply cleanly to the newer version of megasync you are trying to build. You can try commenting out the one that’s failing (./noinstall-distro-version.patch).

If any of those is still needed but does not apply, you will need to create a new patch file.

Thanks! Indeed, that was it. The ffmpeg_44 patch was trying to remove a line that no longer existed. I removed that patch from the build script, and it finally built: https://github.com/NixOS/nixpkgs/commit/857ce287ef78b4bb74fa6e5ccac107543dc33237

Unfortunately, once built, it wouldn’t run. I got segmentation faults shortly after starting it. I have sent the core dumps and logs to the mega support team as I suspect it’s nothing NixOS specific. It’s a shame because I learnt a lot by getting this far, and I’d love to have raised a PR to get this packaged updated!

I might have a look at the other patches and see if maybe they’re doing anything that might cause the segmentation faults, but I don’t know much about C/C++ so I’m probably way out of my depth there.

1 Like