Packaging 010editor with wrapQtAppsHook and autoPatchelfHook

I am trying to package the hex editor 010editor and running into some issues.
this is my derivation.nix file:

{ stdenv, autoPatchelfHook ,qt5, libgcc ,cups}:
let
  buildInputs = [
      qt5.qtbase
      stdenv.cc.cc
      cups
      libgcc
  ];
  src = builtins.fetchTarball {
    url    = "https://www.sweetscape.com/download/010EditorLinux64Installer.tar.gz";
    sha256 = "09wwpd9rjm451hhl2crbllkx2iv06nwg9872cq9mcp1dyia7bscd";
  };
in stdenv.mkDerivation {
  name = "010editor-${version}";
  system = builtins.currentSystem;
  inherit src buildInputs;
  nativeBuildInputs = [
    qt5.wrapQtAppsHook
    autoPatchelfHook
  ];
  installPhase = ''
    mkdir -p $out
    cp -av . $out
  '';

  meta =  {
    description = "010editor";
    platforms = [ builtins.currentSystem ];
  };
}

and this is my default.nix:

{ libsForQt5 ? import <nixpkgs> {} }:
libsForQt5.callPackage ./derivation.nix {}

the derivation seems to build successfully but when trying to run ./result/010editor it does not open a window (in fact it does nothing at all), the last lines of the strace show the following (tell me if you need the whole thing):

mprotect(0x7fdef05db000, 4096, PROT_READ) = 0
mprotect(0xf4d000, 1454080, PROT_READ)  = 0
mprotect(0x7fdef0612000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
futex(0x7fdeed65e6fc, FUTEX_WAKE_PRIVATE, 2147483647) = 0
getrandom("\xaa\x01\xa9\x47\x4e\xf0\xfb\xc5", 8, GRND_NONBLOCK) = 8
brk(NULL)                               = 0x2566000
brk(0x2587000)                          = 0x2587000
futex(0x257b150, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY

I have now managed to run 010editor with flatpak.
would still love it if someone knows how this can be done without.

1 Like

Took a while to do this, but here you go:

{
  lib,
  stdenv,
  autoPatchelfHook,
  makeDesktopItem,
  cups,
  libgcc,
  qt5,
  makeWrapper,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "010editor";
  version = "14.0.1";
  src = builtins.fetchTarball {
    url = "https://download.sweetscape.com/010EditorLinux64Installer${finalAttrs.version}.tar.gz";
    sha256 = "sha256:09wwpd9rjm451hhl2crbllkx2iv06nwg9872cq9mcp1dyia7bscd";
  };

  nativeBuildInputs = [
    autoPatchelfHook
    qt5.wrapQtAppsHook
  ];

  buildInputs = [
    cups
    libgcc
    qt5.qtbase
    stdenv.cc.cc
    makeWrapper
  ];

  installPhase = ''
    mkdir $out && cp -ar * $out

    # Patch executable and libs
    for file in \
      $out/010editor \
      $out/lib/*;
    do
      patchelf --set-rpath "${stdenv.cc.cc.lib}/lib:${stdenv.cc.cc.lib}/lib64" "$file"
    done

    # Don't use wrapped QT plugins since they are already included in the
    # package, else the program crashes because of the conflict.
    wrapProgram $out/010editor \
      --unset QT_PLUGIN_PATH

    mkdir $out/bin
    ln -s $out/010editor $out/bin/010editor

    # Copy the icon and generated desktop file
    install -D 010_icon_128x128.png -t $out/share/icons/hicolor/128x128/apps/
    install -D $desktopItem/share/applications/* -t $out/share/applications/
  '';

  desktopItem = makeDesktopItem {
    name = "010editor";
    exec = "010editor %f";
    icon = "010_icon_128x128";
    desktopName = "010 Editor";
    genericName = "Text and hex edtior";
    categories = [ "Development" ];
    mimeTypes = [
      "text/html"
      "text/plain"
      "text/x-c++hdr"
      "text/x-c++src"
      "text/xml"
    ];
  };

  meta = {
    description = "010editor";
    homepage = "https://www.sweetscape.com";
    license = lib.licenses.unfree;
    maintainers = with lib.maintainers; [ ];
    platforms = lib.platforms.all;
    mainProgram = "010editor";
  };
})

Don’t know if creating a desktop file is necessary, though, since it asks you if you want to do that when you first start the program.

@unimportant Would you like to contribute and maintain this in nixpkgs?

Thank you very much for the thorough response!
In regards to maintaining this in nixpkgs, I feel as though I am not yet familiar enough with nix to be able to maintain this package.

1 Like