Tribler Development with Nix

Posted on December 1, 2016

I need to setup a development environment to work with Tribler. Unfortunately, Tribler does not work in Fedora due to some patent issues in OpenSSL (see here). It’s possible to use an Ubuntu/Debian VM, but coding over an SSH connection isn’t great either. The solution, is Nix.

The nix-shell command drops you into an interative shell with dependencies which you specify. It leaves your system packages untouched and installs everything in /nix/store. For example, running nix-shell '<nixpkgs>' -A rustc will create an environment that has all the dependencies to build Rust. Tribler is not packaged in Nixpkgs, so we need to manually specify the dependencies, that is what I did today.

with import <nixpkgs> {};

let dependencies = rec {
  _leveldb = with python27Packages; buildPythonPackage {
    name = "leveldb-0.194";
    src = fetchurl {
      # ...
    };
  };
  _libnacl = with python27Packages; buildPythonPackage {
    name = "libnacl-1.5.0";
    src = fetchurl {
      # ...
    };
  };
};
in with dependencies;

stdenv.mkDerivation rec {
  name = "tribler";
  env = buildEnv { name = name; paths = buildInputs; };
  buildInputs = [
    python27
    python27Packages.virtualenv
    python27Packages.pip
    python27Packages.apsw
    python27Packages.cryptography
    python27Packages.feedparser
    python27Packages.m2crypto
    python27Packages.netifaces
    python27Packages.pillow
    python27Packages.pyasn1
    python27Packages.twisted
    python27Packages.chardet
    python27Packages.configobj
    python27Packages.pyqt5
    python27Packages.cherrypy
    python27Packages.decorator
    vlc
    libav
    libsodium
    xorg.libX11
    libtorrentRasterbar # contains python bindings
    _libnacl
    _leveldb
  ];
  LD_LIBRARY_PATH="${libsodium}/lib:${vlc}/lib";
}

What you see above is an Nix expression, it specifies a derivation (using mkDerivation), which consist of a set of attributes (e.g. buildInput). Note that the Python libraries libnacl and leveldb are not available in Nixpkgs, so I had to build them myself (it’s surprisingly easy, just specify the URL and use buildPythonPackage).

With this, we can reliably create a Tribler development environment on any Linux distribution or macOS.

# install Nix if you haven't already
wget https://raw.githubusercontent.com/kc1212/tribler-in-nix/master/tribler.nix
nix-shell ./tribler.nix

It may be useful to move tribler.nix to the root directory of Tribler, and then rename is to default.nix.