Derivation of draw.io .deb package crashes

I am running nix 2.0.4 as a single user setup on Ubuntu18.04.
This is my first try to create a nix derivation.

I am trying to create a nix derivation of the official .deb package of draw.io with the following nix file based on the official nix packaging guide:

{ 
  stdenv, fetchurl, lib, makeWrapper, 
  gtk3-x11, gnome2, atk, cairo,
  gdk_pixbuf, glib, dbus_libs, xlibs,
  nspr, nss, alsaLib, cups, fontconfig,
  expat
}:

stdenv.mkDerivation rec {
  version = "8.8.0";
  name = "draw.io-${version}";

  src = fetchurl {
    url = "https://github.com/jgraph/drawio-desktop/releases/download/v${version}/draw.io-amd64-${version}.deb";
    sha256 = "0zl4dg2hzy17gcpzdqkq5bah540r0asfvvif2h3cjjd4kc0kd887";
  };

  nativeBuildInputs = [ makeWrapper ];

  sourceRoot = ".";
  unpackCmd = ''
    ar p "$src" data.tar.xz | tar xJ
  '';

  installPhase = ''
    mkdir -p $out/bin
    cp -R usr/share opt $out/
    # fix the path in the desktop file
    substituteInPlace \
      $out/share/applications/draw.io.desktop \
      --replace /opt/ $out/opt/
    # symlink the binary to bin/
    ln -s $out/opt/draw.io/draw.io $out/bin/draw.io
  '';
  preFixup = let
    lpath = lib.makeLibraryPath [
      alsaLib
      atk
      cairo
      cups
      dbus_libs
      expat
      fontconfig
      gtk3-x11
      gnome2.GConf
      gnome2.pango
      gdk_pixbuf
      glib
      nspr
      nss
      stdenv.cc.cc.lib
      xlibs.libX11
      xlibs.libxcb
      xlibs.libXi
      xlibs.libXcursor
      xlibs.libXdamage
      xlibs.libXrandr
      xlibs.libXcomposite
      xlibs.libXext
      xlibs.libXfixes
      xlibs.libXrender
      xlibs.libXtst
      xlibs.libXScrnSaver
    ];
  in ''
    patchelf \
      --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
      --set-rpath "$out/opt/draw.io:${lpath}" \
      $out/opt/draw.io/draw.io
  '';

  meta = with stdenv.lib; {
    homepage = https://github.com/jgraph/drawio;
    description = "draw.io diagramming tool";
    license = licenses.asl20;
    platforms = platforms.linux;
    maintainers = [ maintainers.fishi0x01 ];
  };
}

The package gets built and installed without issues via:

nix-build -A draw-io
nix-env -f . -iA draw-io 

Sadly, the resulting binary crashes:

$ draw.io 
Trace/breakpoint trap (core dumped)

From the syslog I only get:

kernel: [200185.947695] traps: Chrome_IOThread[7044] trap int3 ip:267aa43 sp:7ff1c83a4450 error:0 in draw.io[1802000+3733000]

Does anybody have a pointer on how I could proceed on that one? Am i missing anything crucial in installPhase of preFixup stage?

I suspect there is some dependency that is not correct in the .deb. Since this is Java-based I would recommend either getting the JAR file or building it yourself. You should be able to use the etc/build/build.xml file with ant. You can use disnix as an example:

1 Like

8.8.0 did seem to have a dependency issue, try 9.3.1 instead.

1 Like

@david-draw-io Thank you for the hint :slight_smile: 9.3.1 indeed introduces a new lib dep libatk-bridge-2.0.so.0, which can be included via nixpkg at-spi2-atk. Sadly I am still getting a segfault

nixpkgs$ draw.io 
Trace/breakpoint trap (core dumped)

Syslog:

kernel: [95328.258335] traps: Chrome_IOThread[20731] trap int3 ip:1896ec3 sp:7f5ac006a380 error:0 in .draw.io-wrapped[100b000+3bfa000]

@matthewbauer That is an interesting idea. Will try that. Thanks a bunch :slight_smile:

@fishi0x01 if you are still looking to use draw.io on NixOS – I have created a PR for draw.io: https://github.com/NixOS/nixpkgs/pull/64109

I wrote the derivation from scratch, but also encountered a trap and had to add systemd to the runtime library path.