Unity Engine update build efforts

Hi,

i am attempting to update the unity3d package to the newest 2019 LTS version myself.

After forking and changing the upstream URL, checksum and version my default.nix looks like this:

{ stdenv, lib, fetchurl, makeWrapper, file, getopt
, gtk2, gtk3, gdk-pixbuf, glib, libGL, libGLU, nss, nspr, udev, tbb
, alsaLib, GConf, cups, libcap, fontconfig, freetype, pango
, cairo, dbus, expat, zlib, libpng12, nodejs, gnutar, gcc, gcc_32bit
, libX11, libXcursor, libXdamage, libXfixes, libXrender, libXi
, libXcomposite, libXext, libXrandr, libXtst, libSM, libICE, libxcb, chromium
, libpqxx, libselinux, pciutils, libpulseaudio
}:

let
  libPath64 = lib.makeLibraryPath [
    gcc.cc gtk2 gdk-pixbuf glib libGL libGLU nss nspr
    alsaLib GConf cups libcap fontconfig freetype pango
    cairo dbus expat zlib libpng12 udev tbb
    libX11 libXcursor libXdamage libXfixes libXrender libXi
    libXcomposite libXext libXrandr libXtst libSM libICE libxcb
    libpqxx gtk3

    libselinux pciutils libpulseaudio
  ];
  libPath32 = lib.makeLibraryPath [ gcc_32bit.cc ];
  binPath = lib.makeBinPath [ nodejs gnutar ];

  ver = "2019.2.19";
  build = "f1";

in stdenv.mkDerivation {
  pname = "unity-editor";
  version = "${ver}x${build}";

  src = fetchurl {
  	url = "https://download.unity3d.com/download_unity/929ab4d01772/LinuxEditorInstaller/Unity.tar.xz";
    sha256 = "0fz7x1np0f05977i5bwn5d0q04iv9pwy2krqjggasdvvbchfzn62";
  };

  nosuidLib = ./unity-nosuid.c;

  nativeBuildInputs = [ makeWrapper file getopt ];

  outputs = [ "out" ];

  sourceRoot = ".";

  buildPhase = ''
    cd Editor

    $CC -fPIC -shared -o libunity-nosuid.so $nosuidLib -ldl
    strip libunity-nosuid.so

    cd ..
  '';

  installPhase = ''
    unitydir="$out/opt/Unity/Editor"
    mkdir -p $unitydir
    mv Editor/* $unitydir
    ln -sf /run/wrappers/bin/${chromium.sandboxExecutableName} $unitydir/chrome-sandbox

    mkdir -p $out/bin
    makeWrapper $unitydir/Unity $out/bin/unity-editor \
      --prefix LD_LIBRARY_PATH : "${libPath64}" \
      --prefix LD_PRELOAD : "$unitydir/libunity-nosuid.so" \
      --prefix PATH : "${binPath}"
  '';

  preFixup = ''
    patchFile() {
      ftype="$(file -b "$1")"
      if [[ "$ftype" =~ LSB\ .*dynamically\ linked ]]; then
        if [[ "$ftype" =~ 32-bit ]]; then
          rpath="${libPath32}"
          intp="$(cat $NIX_CC/nix-support/dynamic-linker-m32)"
        else
          rpath="${libPath64}"
          intp="$(cat $NIX_CC/nix-support/dynamic-linker)"
        fi

        # Save origin-relative parts of rpath.
        originRpath="$(patchelf --print-rpath "$1" | sed "s/:/\n/g" | grep "^\$ORIGIN" | paste -sd ":" - || echo "")"
        rpath="$originRpath:$rpath"

        patchelf --set-rpath "$rpath" "$1"
        patchelf --set-interpreter "$intp" "$1" 2> /dev/null || true
      fi
    }

    upm_linux=$unitydir/Data/Resources/PackageManager/Server/UnityPackageManager


    orig_size=$(stat --printf=%s $upm_linux)

    # Exclude PlaybackEngines to build something that can be run on FHS-compliant Linuxes
    find $unitydir -name PlaybackEngines -prune -o -type f -print | while read path; do
      patchFile "$path"
    done

    new_size=$(stat --printf=%s $upm_linux)

    ###### zeit-pkg fixing starts here.
    # we're replacing plaintext js code that looks like
    # PAYLOAD_POSITION = '1234                  ' | 0
    # [...]
    # PRELUDE_POSITION = '1234                  ' | 0
    # ^-----20-chars-----^^------22-chars------^
    # ^-- grep points here
    #
    # var_* are as described above
    # shift_by seems to be safe so long as all patchelf adjustments occur
    # before any locations pointed to by hardcoded offsets

    var_skip=20
    var_select=22
    shift_by=$(expr $new_size - $orig_size)

    function fix_offset {
      # $1 = name of variable to adjust
      location=$(grep -obUam1 "$1" $upm_linux | cut -d: -f1)
      location=$(expr $location + $var_skip)
      value=$(dd if=$upm_linux iflag=count_bytes,skip_bytes skip=$location \
                 bs=1 count=$var_select status=none)
      value=$(expr $shift_by + $value)
      echo -n $value | dd of=$upm_linux bs=1 seek=$location conv=notrunc
    }

    fix_offset PAYLOAD_POSITION
    fix_offset PRELUDE_POSITION
  '';

  dontStrip = true;
  dontPatchELF = true;

  meta = with stdenv.lib; {
    homepage = "https://unity3d.com/";
    description = "Game development tool";
    longDescription = ''
      Popular development platform for creating 2D and 3D multiplatform games
      and interactive experiences.
    '';
    license = licenses.unfree;
    platforms = [ "x86_64-linux" ];
    maintainers = with maintainers; [ tesq0 ];
  };
}

Then i built and installed the package locally.

When starting i get: /nix/store/hckbh75viicjf0nd8w1zmf88gb0nry21-unity-editor-2019.2.19xf1/opt/Unity/Editor/Unity: error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory

Missing dependency check:

ldd /nix/store/hckbh75viicjf0nd8w1zmf88gb0nry21-unity-editor-2019.2.19xf1/opt/Unity/Editor/Unity | grep not\ found

/nix/store/hckbh75viicjf0nd8w1zmf88gb0nry21-unity-editor-2019.2.19xf1/opt/Unity/Editor/Unity: /nix/store/33idnvrkvfgd5lsx2pwgwwi955adl6sk-glibc-2.31/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/hgx8cln6x7y2vhqx61vyij0acyf1w43g-glib-2.66.3/lib/libglib-2.0.so.0)
/nix/store/hckbh75viicjf0nd8w1zmf88gb0nry21-unity-editor-2019.2.19xf1/opt/Unity/Editor/Unity: /nix/store/33idnvrkvfgd5lsx2pwgwwi955adl6sk-glibc-2.31/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/savrzr6cvmdn58rblxx7g06i3c6y68xg-avahi-0.8/lib/libavahi-common.so.3)
/nix/store/hckbh75viicjf0nd8w1zmf88gb0nry21-unity-editor-2019.2.19xf1/opt/Unity/Editor/Unity: /nix/store/33idnvrkvfgd5lsx2pwgwwi955adl6sk-glibc-2.31/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/19b2j9a2k9plk17rqb92cvr5bkjsb011-systemd-247/lib/libsystemd.so.0)
/nix/store/hckbh75viicjf0nd8w1zmf88gb0nry21-unity-editor-2019.2.19xf1/opt/Unity/Editor/Unity: /nix/store/33idnvrkvfgd5lsx2pwgwwi955adl6sk-glibc-2.31/lib/libc.so.6: version `GLIBC_2.32' not found (required by /nix/store/q8iwxvjilsnd3np9bgwk5z0bglvdk384-xz-5.2.5/lib/liblzma.so.5)
  libatk-1.0.so.0 => not found

Has anyone more experience on how to resolve this?
Thanks in advance.

It was resolved by using the unityhub package to download the required version manually.

1 Like