How to compile Unison for a Synology NAS (DSM 6.2)

It’s been a while since I wrote an article about how to compile Unison for a Synology NAS system which required you to bootstrap your system. Back then the Synology I owned (a DS212+) was using an ARM based CPU.

Fast forwarding in time and I now own two more Synology systems. The DS716+II and a DS718+.

Both have an Intel CPU in them (x86-64) and run DSM 6.2. I do realize that both ship with Docker which made things a lot easier, especially if would like to run a Linux distro on it.

However, let’s say you don’t want to install docker on your NAS but just want to create a binary you could run on your Synology directly? Well, this guide will show you exactly how to do that.

What do we need?

Instead of trying to build Unison on our NAS, I am using my laptop to cross compile the binaries. This should be much faster and easier to do.

For this guide I’ll be using macOS (Catalina) with a little bit of help of a local Docker install (on the laptop) to keep things tidy. The process should be similar on Linux and Windows.

First download and install Docker on your machine.

Second, figure out your NAS CPU architecture. SSH into your Synology and run the following command:

$ uname -a  
Linux mynas 4.4.59+ #25423 SMP PREEMPT Tue Apr 14 14:29:10 CST 2020 **x86\_64** GNU/Linux **synology_apollolake_718+**

This means that my Synology 718+ is using a apollolake and x86_64.

For my Synology 716+II, it looks like this:

$ uname -a  
Linux othernas 3.10.105 #24922 SMP Wed Jul 3 16:34:56 CST 2019 **x86\_64** GNU/Linux **synology_braswell_716+II**

Setup a Docker container

We create and launch our container (with Ubuntu installed) with the following commands:

$ docker create -it --name synobuild ubuntu
$ docker start synobuild
$ docker exec -it synobuild bash

Next to update the container:

$ root@dfb2aa113aa3:/# apt-get update  
$ root@dfb2aa113aa3:/# apt-get install git python3 wget

Setup the Synology toolchain

Enter your home folder

cd ~

Clone the Synology scripts repository (master branch)

root@dfb2aa113aa3:/# git clone https://github.com/SynologyOpenSource/pkgscripts-ng

Next check which CPUs are supported:

root@dfb2aa113aa3:~# pkgscripts-ng/EnvDeploy -v 6.2 --list
 
Available platforms: 6281 alpine alpine4k **apollolake** armada370 armada375 armada37xx armada38x armadaxp avoton **braswell** broadwell broadwellnk bromolow cedarview comcerto2k denverton dockerx64 evansport grantley hi3535 kvmx64 monaco qoriq rtd1296 x64

We can see that apollolake is one of the options, and the one I should use for my 718+. For my 716+II I would repeat the same steps below but with braswell.

To setup the environment, you will need to run the following command:

pkgscripts-ng/EnvDeploy -v 6.2 -p <platform name>

So for me that means:

root@dfb2aa113aa3:~# pkgscripts-ng/EnvDeploy -v 6.2 -p apollolake

Downloading the files will take a while… SourceForge… is… so… slow.

Next, Chroot the environment.

chroot build\_env/ds.-<CPU Architecture>-<DSM version>

So in my case:

root@dfb2aa113aa3:~# chroot build\_env/ds.apollolake-6.2

Downloading and installing OCaml 4.08.1

In the Chrooted environment:

$ cd ~  
$ wget https://caml.inria.fr/pub/distrib/ocaml-4.08/ocaml-4.08.1.tar.gz  
$ tar xzvf ocaml-4.08.1.tar.gz  
$ cd ocaml-4.08.1/  
$ ./configure  
$ make world.opt  
$ make install  
$ make clean

Note 1: For whatever reason, I can’t seem to download with wget from https paths without specifying:

--no-check-certificate 

Proceed at own risk :).

Note 2: You should probably match your ocaml version with the one you use on your desktop.

Downloading and building Unison 2.51.2

Continue in the Chrooted environment:

$ cd ~  
$ wget https://github.com/bcpierce00/unison/archive/v2.51.2.tar.gz  
$ tar xzvf v2.51.2.tar.gz  
$ cd unison-2.51.2/  
$ wget https://github.com/bcpierce00/unison/commit/23fa1292.diff?full\_index=1  
$ mv 23fa1292.diff?full_index=1 23fa1292.diff  
$ git apply 23fa1292.diff  
$ make UISTYLE=text

Note 1: The patch is only required for OCaml 4.08 and later (see homebrew notes at the link below)

Copy the binary

Copy the Unison binary from Docker to your computer (and then to your NAS). Be sure to exit out of your chroot/docker environment first.

  • This will copy the binary from my Docker container (synobuild) to my home folder on the mac.
$ docker cp synobuild:/root/build_env/ds.apollolake-6.2/root/unison-2.51.2/src/unison /Users/lmuller
  • Next copy the file to your homedir on the Synology. (Via DSM or sftp/samba/nfs)
  • Log onto your Synology using ssh and try to run the self test to see if everything runs ok (it should):
$ unison -selftest
  • Next try to check the version:
$ unison -version  
unison version 2.51.2 (ocaml 4.08.1)

Helpful Sources:


3 responses

  1. Hello, thank you for this tutorial! I have a DS218 (so rtd1296 for me), I followed all the steps, however for some reason, docker is compiling in x86 and not ARM. any idea why please ?

    Rainmaker – May 12th, 2021
  2. Thanks for this guide. I’m trying to build for the 6281 architecture. I followed your steps but the unison executable is ELF 64-bit LSB executable, x86-64 whereas I was under the impression that should be ELF 32-bit LSB executable, ARM. I must be missing something but shouldn’t all the exectuables in the chrooted environment be ARM executables ? According to ./bin/file everything in the chrooted is also x86-64.

    Julien Cubizolles – July 9th, 2021
  3. I had to do “apt-get install xz-utils” after the “apt-get install git python3 wget” otherwise you get a TAR XZ error after the download of _env tz files…

    Jann Gobble December 11th, 2022