6

I have two machines that one runs Ubuntu 18.04 and the other one Ubuntu 20.04. I want to use Unison to sync files between them but there are some issues. Firstly, because I sync with another machine too, I compiled from source Unison 2.48.3. Then in the Ubuntu 18.04, I installed from the Ubuntu software Unison 2.48.4 and so I did with Ubuntu 20.04. After setting them up properly, from the command line of Ubuntu 18.04 I run unison-2.48.4-gtk and try to sync. Although everything works fine, i.e. it finds the machine and the directory then I get the message: Fatal error during unmarshaling (input value:ill-formed message) possibly because client and serer have been compiled with different versions of OCaml compiler. In the 20.04, I checked the version of OCaml but apparently it returned nothing (even though I had installed unison from app store). On the 18.04 the version is 4.05.0. Any ideas on what I can do?

5 Answers 5

4

When you need to sync several computers with different operating systems, if you don't want to be compiling from source every time Unison and/or OCaml change something, there is one clean solution that should always work and is to install Unison as a snap. This way you have the very same Unison/OCaml version across all your linux computers, clients and servers. That's what snaps are meant for. The same snap should work exactly the same, regardless of the OS in which it is installed. In this case, we have unison-jz available in the Software Center. It will install Unison 2.51.2 compiled against OCaml 4.02.3

If snapd is already installed, as it is in Ubuntu, you just need to issue:

sudo snap install unison-jz

If you want to synchronize something outside of your home directory, you might have to install unison-jz in developer mode, so it can handle the needed permissions. In this case, the line you have to use in the terminal is:

sudo snap install --devmode unison-jz

There are two other things you have to do for the snap'd version of Unison to work. Those are:

  1. Once you created the Unison profile you are going to use to synchronize your files, use a text editor to add the line

     servercmd = /snap/bin/unison-jz.unison -ui text
    

    to your profile file, located in ~/snap/unison-jz/current/.unison/

    All profile files use the extension .prf

    That way, the unison in the client machine calls the snap'd version (unison-jz) in the server, which is the one that has the same Unison/OCaml versions

  2. Apparently, the version of ssh included in unison-jz does not understand the term 'Include' in the ssh's configuration file, and errors out if it finds it. So, probably, you'll also have to edit the file /etc/ssh/ssh_config

    Open it, as administrator, with the text editor of your choice. For example

     sudo nano /etc/ssh/ssh_config
    

    and comment out line 19 that looks like

     Include /etc/ssh/ssh_config.d/*.conf
    

    It should look like this

     #Include /etc/ssh/ssh_config.d/*.conf
    

I think that this is an easier way to handle the situation, since building from source is often not possible because of the dependency problems that arise when trying to compile a newer version of OCaml or Unison in an older version of Ubuntu.

More information:

http://www.xente.mundo-r.com/zasjls/other/20/unison_en.html

3

You're mixing Unison versions 2.48.3 and 2.48.4. Unison is very finicky about this since the developer changes the format of the Unison archive files even between minor versions. Anyways, the versions of Unison should match between all your machines. I would skip the app store, and compile/install 2.48.3 manually on your Ubuntu machine.

Furthermore, you've got to make sure that you're using the same version of oCaml to compile the same version of Unison on each machine ;)

2
  • 1
    You may get this problem. even it both computers are running unison 2.48.4. Here is my take on the problem:askubuntu.com/q/1234767/305040 Commented May 3, 2020 at 14:18
  • 1
    I ran into this problem between the apt version on Ubuntu vs Raspbian. I tried the suggestion to use the Snap package, but it gave problems. Compiling from source was an easy and quick solution on both machines.
    – WesH
    Commented Mar 23, 2022 at 20:59
3

An easy way to solve this is by making use of apt pinning, as described by Debian's or Ubuntu's docs, to keep the unison package on the newer host to the release of the older system.

To make debian bullseye use unison from buster please make sure /etc/apt/sources.list contains lines for both releases, and put the following in /etc/apt/preferences.d/unison:

Package: unison
Pin: release n=bullseye
Pin-Priority: -10

Package: unison
Pin: release n=buster
Pin-Priority: 900

Running apt-get install unison/buster will downgrade the package if it is already installed. Note of how the package name is suffixed with a slash and the distribution release.

Replacing bullseye with focal and buster with bionic would likely work, but I have not tested. The numbers corresponding to the release names in the question and answer are as follows:

  • Bionic Beaver is Ubuntu 18.04
  • Focal Fossa is Ubuntu 20.04
  • Buster is Debian 10
  • Bullseye is Debian 11

(Other answers advice using snap. While acceptable to some, please beware of how that software creates a ~/snap/ directory which can not practically be removed, and that no simple fix for that has been accepted for half a decade. Details at askubuntu.com/882562/.)

3

Between 18.04 and 20.04, Ubuntu bumped the OCaml version from 4.05 to 4.08—this is the package that is available in the repos, and presumably also the version used to build Unison for the respective release.

More recent Unison versions (starting with 2.40) are available as binary downloads from the project itself. Starting with 2.51.3, they even offer builds with different OCaml versions. Grab the one you want and deploy it to both of your machines, which ensures you are running the same on both ends.

Or you can downgrade the 20.04 machine to the Unison package that shipped with 18.04 (build -1ubuntu1 instead of -4ubuntu1): Grab unison-gtk_2.48.4-1ubuntu1_amd64 from the Ubuntu repos (this is the release that ships with 18.04; 20.04 has unison-gtk_2.48.4-4ubuntu1_amd64), and install it with:

sudo dpkg -i ~/Downloads/unison-gtk_2.48.4-1ubuntu1_amd64.deb

In order to prevent the updater from undoing your changes on its next run, put the package on hold:

sudo apt-mark hold unison-gtk

(If you decide to upgrade in the future, re-running this command with unhold will undo this, allowing the package to be upgraded again.)

You may have to delete your Unison cache—~/.unison/ar* and ~/.unison/fp*—on both ends.

On the long run, the team are working on getting rid of the OCaml version dependency (as I understand issue #375, the dev is just waiting for the next release to merge his changes). We might get to enjoy this as soon as version 2.52 or 2.53. They also have plans to introduce interoperability between different Unison versions, as long as the wire protocol remains unchanged (#407), but that might take a little longer.

EDIT: All version from 2.52 onwards are now fully compatible with each other. The preferred way is to upgrade both machines to at least that version. If you need backward compatibility, 2.52 can also sync with 2.48 as long the versions on both ends were built with the same OCaml version. (Best guess is to start with the OCaml version that is available from your distribution’s repositories.)

1

Instead of having to modify each profile, it might be easier to use a snap alias :

sudo snap alias unison-jz.unison unison

on both client and server side.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .