anchor.diff:      libpng
       librevenge
       libsigcxx
  +    libsoup
       libvisio
       libwpg
  +    libx11
       libxml2
       pango
       poppler
  -    popt
  -    xorg.libX11
  -    xorg.libXft
  +    xorgproto
       zlib
     ];
   
  -  patches = [
  -    (fetchTritonPatch {
  -      rev = "d8eca8b601a550b5ec33beced51f73ccb1ce5e51";
  -      file = "inkscape/inkscape-0.91_pre3-automagic.patch";
  -      sha256 = "100b94eee2a9f5ffacafe0732735342cb14b873296de1e982e7db24ced31124e";
  -    })
  -    (fetchTritonPatch {
  -      rev = "d8eca8b601a550b5ec33beced51f73ccb1ce5e51";
  -      file = "inkscape/inkscape-0.91_pre3-desktop.patch";
  -      sha256 = "016adfaddb1c6c509318430fab9d74ee81f5ce9f71a85ccb4b06d6dc221fff03";
  -    })
  -    (fetchTritonPatch {
  -      rev = "d8eca8b601a550b5ec33beced51f73ccb1ce5e51";
  -      file = "inkscape/inkscape-0.91_pre3-exif.patch";
  -      sha256 = "ad4295f73e386ebe89c6f86d456853ceba0b7af24a584b51348b788280145ef0";
  -    })
  -    (fetchTritonPatch {
  -      rev = "d8eca8b601a550b5ec33beced51f73ccb1ce5e51";
  -      file = "inkscape/inkscape-0.91_pre3-sk-man.patch";
  -      sha256 = "56e24d84d5217308df178d64214ec13c4b81ba59541cc6f52415f2207825a274";
  -    })
  -    (fetchTritonPatch {
  -      rev = "6fda2c885b725f8d625b85d2e39b7ef2b18e7ff2";
  -      file = "inkscape/inkscape-0.48.4-epython.patch";
  -      sha256 = "279c1dd278bf69c69f4ac2351d8d069f08aa444e45c32ccd564f6962304f3cdb";
  -    })
  -    (fetchTritonPatch {
  -      rev = "be944e6046862c9d2c0e39daf007ae8c26dc4c1e";
  -      file = "inkscape/inkscape-0.91-deprecated-scopedptr.patch";
  -      sha256 = "02c77e84c4abd8d20c7c92a02c53cf488cd6452ff2957d0d22406201a11b1cf6";
  -    })
  +  postPatch = ''
  +    grep -q 'Cairo::FORMAT_ARGB32' src/ui/dialog/ocaldialogs.cpp
  +    sed -i src/ui/dialog/ocaldialogs.cpp \
  +      -e 's/Cairo::FORMAT_ARGB32/Cairo::Surface::Format::ARGB32/'
  +    grep -q 'Cairo::FORMAT_RGB24' src/ui/widget/ink-color-wheel.cpp
  +    sed -i src/ui/widget/ink-color-wheel.cpp \
  +      -e 's/Cairo::FORMAT_RGB24/Cairo::Surface::Format::RGB24/g'
  +    grep -q 'Cairo::FILL_RULE_WINDING' src/ui/widget/preferences-widget.cpp
  +    sed -i src/ui/widget/preferences-widget.cpp \
  +      -e 's/Cairo::FILL_RULE_WINDING/Cairo::Context::FillRule::WINDING/'
  +  '' + ''
  +    patchShebangs share/extensions/
  +  '';
  +
  +  cmakeFlags = [
  +    "-DENABLE_POPPLER=OFF"  # FIXME
  +    "-DWITH_DBUS=ON"
  +    "-DWITH_IMAGE_MAGICK=OFF"  # FIXME
  +    "-DWITH_GRAPHICS_MAGICK=OFF"  # FIXME
  +    "-DWITH_JEMALLOC=ON"
     ];
   
  -  postPatch = ''
  -    patchShebangs ./share/extensions
  -  '' +
  -  /* Clang gets misdetected, so hardcode the right answer */
  -  optionalString cc.isClang ''
  -    sed -i src/ui/tool/node.h \
  -      -e 's/#if __cplusplus >= 201103L/#if true/'
  -  '' + ''
  -    sed -i src/extension/implementation/script.cpp \
  -      -e 's|@EPYTHON@|${pythonPackages.python.interpreter}|'
  +  postInstall = ''
  +    wrapProgram $out/bin/inkscape \
  +      --prefix PATH ':' '${python3}/bin'
     '';
   
  -  preConfigure = (
  -    /* Tarballs do not contain autogen.sh and unique work-arounds
  -       are required. Run all commands manually instead of using
  -       autoreconfHook as it does not handle this situation. */
  -    /* This autoreconf hack is to work around an issue with autopoint and
  -       intltool both trying to take ownership of the same file.  Autopoint
  -       is automatically invoked if AM_GNU_GETTEXT_VERSION or
  -       AM_GNU_GETTEXT_VERSION exist in configure.ac.  To fix this make
  -       autoreconf execute intltool in place of autopoint */ ''
  -      autopoint --force
  -      AUTOPOINT='intltoolize --automake --copy' autoreconf --force --install --verbose
  -    '' +
  -    /* Upstream uses a hack for intltool < 0.51.0 in 0.91 */ ''
  -      sed -i po/Makefile.in.in \
  -        -e 's/itlocaledir = $(prefix)\/$(DATADIRNAME)\/locale/itlocaledir = $(datarootdir)\/locale/'
  -    ''
  -  );
  -
  -  configureFlags = [
  -    "--enable-nls"
  -    "--enable-rpath"
  -    #"--enable-openmp"
  -    (enFlag "exif" (libexif != null) null)
  -    (enFlag "jpeg" (libjpeg != null) null)
  -    (enFlag "lcms" (lcms2 != null) null)
  -    "--enable-poppler-cairo"
  -    "--enable-wpg"
  -    (enFlag "visio" (libvisio != null) null)
  -    (enFlag "cdr" (libcdr != null) null)
  -    "--disable-localinstall"
  -    "--enable-dbusapi"
  -    (enFlag "magick" (imagemagick != null) null)
  -    "--disable-gtk3-experimental"
  -    "--enable-binreloc"
  -    "--disable-osxapp"
  -    #"--with-gnome-vfs"
  -    "--with-inkjar"
  -    (wtFlag "gtkspell" (gtkspell_2 != null) null)
  -    (wtFlag "aspell" (aspell != null) null)
  -  ];
  -
  -  makeFlags = [
  -    # Prevent inkscape from trying to install files in dbus's prefix
  -    "DBUSSERVICEDIR=\${out}/share/dbus-1/system-services"
  -  ];
  -
  -  postInstall = optionalString boxMakerPlugin ''
  -    mkdir -pv $out/share/inkscape/extensions/
  -    # boxmaker package version 0.91 in a directory called 0.85 ?!??
  -    unzip ${boxmaker}
  -    cp -v boxmake-upd-0.85/* $out/share/inkscape/extensions/
  -    rm -Rvf boxmake-upd-0.85
  -  '' +
  -  /* Make sure PyXML modules can be found at run-time. */ ''
  -    for i in "$out/bin/"* ; do
  -      wrapProgram "$i" \
  -        --prefix PYTHONPATH : "$(toPythonPath ${pythonPackages.pyxml})" \
  -        --prefix PYTHONPATH : "$(toPythonPath ${pythonPackages.lxml})" \
  -        --prefix PATH : ${pythonPackages.python}/bin
  -    done
  -    rm -v "$out/share/icons/hicolor/icon-theme.cache"
  -  '';
  -
  -  doCheck = true;
  -
  -  meta = with stdenv.lib; {
  +  meta = with lib; {
       description = "A SVG based generic vector-drawing program";
       homepage = http://www.inkscape.org;
       license = with licenses; [
  
positive.code: { stdenv
  , autoreconfHook
  , fetchTritonPatch
  , fetchurl
  , gettext
  , intltool
  , makeWrapper
  , perl
  , perlPackages
  , unzip
  
  , aspell
  , boehm-gc
  , boost
  , cairo
  , cairomm
  , dbus-glib
  , fontconfig
  , freetype
  , glib
  , glibmm
  , gsl
  , gtk2
  , gtkmm_2
  , gtkspell_2
  , imagemagick
  , lcms2
  , libcdr
  , libexif
  
negative.code: , libpng
  , librevenge
  , libsigcxx
  , libsoup
  , libvisio
  , libwpg
  , libx11
  , libxml2
  , pango
  , poppler
  , xorgproto
  , zlib
  
  , channel ? "head"
  }:
  
  let
    sources = {
      stable = {
        version = "";
        sha256 = "";
      };
      head = {
        version = "2019-07-09";
        fetchzipversion = 6;
        rev = "68a15264438469e24f1513dd3ee01376ab892a72";
        sha256 = "3f8fa4c049d32271b07d5f20cf94998e5d24b4bde31bf8f85be71015f14075f8";
      };
    };
    source = sources  ."${channel}";
  in
  
  stdenv.mkDerivation rec {
    name = "inkscape-${source.version}";
  
    src =
      if channel != "head" then
        fetchurl {
          url = "https://inkscape.global.ssl.fastly.net/media/resources/file/"
            + "${name}.tar.bz2";
          inherit (source) sha256;
        }
      else
        fetchFromGitLab {
          version = source.fetchzipversion;
          host = "https://gitlab.com";
          owner = "inkscape";
          repo = "inkscape";
          inherit (source) rev sha256;
        };
  
    nativeBuildInputs = [
      cmake
      gettext
      libxslt
      makeWrapper
      ninja
      python3
    ];
  
    buildInputs = [
      aspell
      boehm-gc
      boost
      #cairo
      cairomm
      dbus
      dbus-glib
      double-conversion
      fontconfig
      freetype
      gdl
      glib
      #glibmm
      gsl
      gtk_3
      gtkmm_3
      gtkspell_3
      harfbuzz_lib
      #imagemagick
      jemalloc
      lcms2
      libcdr
      libexif
  