Building OpenMW-VR, runtime libegl / libuuid issues and tips

This is one of the first times I’ve spent quite a bit of time on building a package (3 days).

I’ve gotten it to build but openvr_mw (the main binary) is unable to find libEGL. export LD_LIBRARY_PATH in shell lets it find libEGL but it’s unable to find libuuid after and trying to add it to LD_LIBRARY_PATH doesn’t seem to work.

I’ve tried patchelf, runtimeDependencies, putting it in buildDependencies, etc.

I’d take any advice on how to fix this or just packaging in general, what I’ve done wrong (ex. the flake callPackage is really ugly, and i need to substituteInPlace the ${openxr-sdk} openxr.pc.in correctly instead of forking it)

Since there’s no other distro repos that have this package, I think it could benefit a lot of people outside of NixOS and even possibly introduce people to Nix.

Github for Project

default.nix:

{ pkgs
, lib
, stdenv

, cmake
, pkg-config
, python3

, fetchFromGitLab
, fetchFromGitHub

### DOCUMENTATION
, doxygen
, graphviz # Doxygen requires dot

### LIBRARIES
, boost
, bullet
, ffmpeg_6 # Please unpin this on the next OpenMW release.
, libGL
, libglvnd
, libuuid
, luajit
, lz4
, mesa
, mygui
, nvidia_x11
, openal
, openscenegraph
, openxr-loader
, recastnavigation
, SDL2
, unshield
, wrapQtAppsHook
, yaml-cpp

### MAC OS SPECIFIC
, CoreMedia
, VideoToolbox
, VideoDecodeAcceleration

### LINUX (XORG) SPECIFIC?
, xorg

}:

let

  bullet' = bullet.overrideDerivation (old: {
    cmakeFlags = (old.cmakeFlags or [ ]) ++ [
      "-Wno-dev"
      "-DOpenGL_GL_PREFERENCE=${GL}"
      "-DUSE_DOUBLE_PRECISION=ON"
      "-DBULLET2_MULTITHREADING=ON"
    ];
  });

  GL = "GLVND"; # or "LEGACY";

  mkDerivation = pkgs.libsForQt5.callPackage ({ mkDerivation }: mkDerivation) {};

  openxr-sdk = fetchFromGitHub {
    owner = "bndlfm";
    repo = "OpenXR-SDK_4_OpenMW-VR_Nix";
    rev = "d417ad122a04c1a6d191928170aa1a6368229678";
    hash = "sha256-5tbOsvMWVvWZUl48QtqBJhVqpUMk3WzDY5lhxXx7l0w=";
  };

in

  mkDerivation {
    pname = "openmw_vr";
    version = "0.48.0";

    src = fetchFromGitLab {
      owner = "madsbuvi";
      repo = "openmw";
      rev = "770584c5112e46be1a00b9e357b0b7f6b449cac5";
      hash = "sha256-C8lFjKIdbHyvRcZzJNUj8Lif9IqNvuYURwRMpb4sxiQ=";
    };

    postPatch = /*sh*/ ''
      sed '1i#include <memory>' -i components/myguiplatform/myguidatamanager.cpp ### gcc12
    '' + lib.optionalString stdenv.hostPlatform.isDarwin /* sh */ ''
      sed -i '/fixup_bundle/d' CMakeLists.txt ### Don't fix Darwin app bundle
    '';

    # If not set, OSG plugin .so files become shell scripts on Darwin.
    dontWrapQtApps = stdenv.hostPlatform.isDarwin;

    buildInputs = [
      boost
      bullet'
      doxygen
      ffmpeg_6
      graphviz
      libglvnd
      luajit
      lz4
      mesa
      mygui
      openal
      openscenegraph
      openxr-loader
      recastnavigation
      SDL2
      unshield
      yaml-cpp
    ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
      CoreMedia
      VideoDecodeAcceleration
      VideoToolbox
    ] ++ lib.optionals stdenv.hostPlatform.isLinux [
      xorg.libXdmcp
      xorg.libXrandr
      xorg.libXt
      xorg.libXxf86vm
    ];

    nativeBuildInputs = [
      cmake
      pkg-config
      python3
      wrapQtAppsHook
    ];

    runtimeDependencies = [
      libuuid
      libGL
      mesa
    ];

    enableParallelBuilding = true;

    cmakeFlags = [
      "-DOpenGL_GL_PREFERENCE=LEGACY"
      "-DOPENMW_USE_SYSTEM_RECASTNAVIGATION=1"
      "-DFETCHCONTENT_SOURCE_DIR_OPENXR=${openxr-sdk}"
      "-DCMAKE_SKIP_BUILD_RPATH=ON"
      "-DBUILD_OPENMW_VR=ON"
      "-DCMAKE_BUILD_TYPE=RELEASE"
    ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
      "-DOPENMW_OSX_DEPLOYMENT=ON"
    ];

    installPhase = /*sh*/ ''
      runHook preInstall

      # Run the default install phase provided by CMake
      cmake --build . --target install

      mkdir -p "$out/bin"

      # Copy the openmw_vr binary to the output directory.
      install -m755 ./openmw_vr $out/bin

      runHook postInstall
    '';

    #postFixup = /*sh*/ ''
    #  omwvrExe="$out/bin/openmw_vr"
    #  origRpath="$(patchelf --print-rpath "$omwvrExe")"
    #  patchelf --set-rpath "${lib.makeLibraryPath [ libGL libglvnd libuuid ]}:$origRpath" "$omwvrExe"
    #  '';

    meta = with lib; {
      description = "Unofficial VR open source engine reimplementation of the game Morrowind";
      homepage = "https://openmw.org";
      license = licenses.gpl3Plus;
      maintainers = with maintainers; [ ];
      platforms = platforms.linux ++ platforms.darwin;
    };
  }

Ugly flake.nix:

{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs = { self, nixpkgs }:
  let
    system = "x86_64-linux";
    pkgs = nixpkgs.legacyPackages.${system};
    libsForQt5 = pkgs.libsForQt5;
    xorg = pkgs.xorg;
  in {
    packages.x86_64-linux.openmw-vr = libsForQt5.callPackage ./default.nix {
        inherit pkgs;
        inherit (nixpkgs.legacyPackages.x86_64-linux) stdenv lib;
        inherit (nixpkgs.legacyPackages.x86_64-linux) fetchFromGitLab fetchFromGitHub cmake pkg-config;
        inherit (libsForQt5) wrapQtAppsHook;
        inherit (nixpkgs.legacyPackages.x86_64-linux) SDL2 boost bullet;
        ffmpeg_6 = nixpkgs.legacyPackages.x86_64-linux.ffmpeg_6;
        inherit xorg;
        #inherit (xorg) libXt;
        inherit (pkgs.linuxPackages) nvidia_x11;
        inherit (nixpkgs.legacyPackages.x86_64-linux) luajit lz4 mygui openal openscenegraph recastnavigation unshield yaml-cpp;

        ### MACOS-SPECIFIC DEPENDENCIES
        CoreMedia = if nixpkgs.legacyPackages.x86_64-linux.stdenv.isDarwin
                    then nixpkgs.legacyPackages.x86_64-linux.CoreMedia
                    else null;
        VideoToolbox = if nixpkgs.legacyPackages.x86_64-linux.stdenv.isDarwin
                       then nixpkgs.legacyPackages.x86_64-linux.VideoToolbox
                       else null;
        VideoDecodeAcceleration = if nixpkgs.legacyPackages.x86_64-linux.stdenv.isDarwin
                                  then nixpkgs.legacyPackages.x86_64-linux.VideoDecodeAcceleration
                                  else null;
    };

    packages.x86_64-linux.default = self.packages.x86_64-linux.openmw-vr;

  };
}

error msg upon launching openmw-launcher and clicking play:

Loading config file: /nix/store/wgrv7kk1jfg58ix75k2b2m2gg2ifslsi-openmw_vr-0.48.0/etc/openmw/openmw.cfg
Loading config file: /home/neko/.config/openmw/openmw.cfg
Logs dir: /home/neko/.config/openmw/
User data dir: /home/neko/.local/share/openmw/
Screenshots dir: /home/neko/.local/share/openmw/screenshots
Loading settings file: /nix/store/wgrv7kk1jfg58ix75k2b2m2gg2ifslsi-openmw_vr-0.48.0/etc/openmw/defaults.bin
Loading settings file: /home/neko/.config/openmw/settings.cfg
Loading settings file: /nix/store/wgrv7kk1jfg58ix75k2b2m2gg2ifslsi-openmw_vr-0.48.0/etc/openmw/overrides.bin
[02:19:37.958 I] OpenMW version 0.48.0
[02:19:37.958 I] Using default (English) font encoding.
[02:19:37.958 W] No such dir: "/home/neko/.local/share/openmw/data"
[02:19:37.958 I] OSG version: 3.6.5
[02:19:37.958 I] SDL version: 2.30.6
[02:19:37.959 I] Loading shader settings file: "/home/neko/.config/openmw/shaders.yaml"
[02:19:38.011 I] OpenGL Vendor: NVIDIA Corporation
[02:19:38.011 I] OpenGL Renderer: NVIDIA GeForce RTX 3070/PCIe/SSE2
[02:19:38.011 I] OpenGL Version: 4.6.0 NVIDIA 565.77
[02:19:38.011 V] Available Extensions: 
[02:19:38.012 *] Error [[02:19:38.012 *] GENERAL[02:19:38.012 *]  | [02:19:38.012 *] xrEnumerateInstanceExtensionProperties[02:19:38.012 *]  | [02:19:38.012 *] OpenXR-Loader[02:19:38.012 *] ] : [02:19:38.012 *] RuntimeInterface::LoadRuntime skipping manifest file /home/neko/.config/openxr/1/active_runtime.json, failed to load with message "libEGL.so.1: cannot open shared object file: No such file or directory"[02:19:38.012 *] 
[02:19:38.013 *] Error [[02:19:38.013 *] GENERAL[02:19:38.013 *]  | [02:19:38.013 *] xrEnumerateInstanceExtensionProperties[02:19:38.013 *]  | [02:19:38.013 *] OpenXR-Loader[02:19:38.013 *] ] : [02:19:38.013 *] RuntimeInterface::LoadRuntimes - failed to load a runtime[02:19:38.013 *] 
[02:19:38.013 *] Error [[02:19:38.013 *] GENERAL[02:19:38.013 *]  | [02:19:38.013 *] xrEnumerateInstanceExtensionProperties[02:19:38.013 *]  | [02:19:38.013 *] OpenXR-Loader[02:19:38.013 *] ] : [02:19:38.013 *] Failed to find default runtime with RuntimeInterface::LoadRuntime()[02:19:38.013 *] 
[02:19:38.013 *] Error [[02:19:38.013 *] GENERAL[02:19:38.013 *]  | [02:19:38.013 *] xrEnumerateInstanceExtensionProperties[02:19:38.013 *]  | [02:19:38.013 *] OpenXR-Loader[02:19:38.013 *] ] : [02:19:38.013 *] Failed querying extension properties[02:19:38.013 *] 
[02:19:38.013 E] /build/source/components/xr/extensions.cpp:173: OpenXR[Error: XR_ERROR_RUNTIME_UNAVAILABLE][Thread: 140688100393024]: xrEnumerateInstanceExtensionProperties(layerName, 0, &extensionCount, nullptr)
[02:19:38.014 *] Error [[02:19:38.014 *] GENERAL[02:19:38.014 *]  | [02:19:38.014 *] xrEnumerateInstanceExtensionProperties[02:19:38.014 *]  | [02:19:38.014 *] OpenXR-Loader[02:19:38.014 *] ] : [02:19:38.014 *] RuntimeInterface::LoadRuntime skipping manifest file /home/neko/.config/openxr/1/active_runtime.json, failed to load with message "libEGL.so.1: cannot open shared object file: No such file or directory"[02:19:38.014 *] 
[02:19:38.014 *] Error [[02:19:38.014 *] GENERAL[02:19:38.014 *]  | [02:19:38.014 *] xrEnumerateInstanceExtensionProperties[02:19:38.014 *]  | [02:19:38.014 *] OpenXR-Loader[02:19:38.014 *] ] : [02:19:38.014 *] RuntimeInterface::LoadRuntimes - failed to load a runtime[02:19:38.014 *] 
[02:19:38.014 *] Error [[02:19:38.014 *] GENERAL[02:19:38.014 *]  | [02:19:38.014 *] xrEnumerateInstanceExtensionProperties[02:19:38.014 *]  | [02:19:38.014 *] OpenXR-Loader[02:19:38.014 *] ] : [02:19:38.014 *] Failed to find default runtime with RuntimeInterface::LoadRuntime()[02:19:38.014 *] 
[02:19:38.014 *] Error [[02:19:38.014 *] GENERAL[02:19:38.014 *]  | [02:19:38.014 *] xrEnumerateInstanceExtensionProperties[02:19:38.014 *]  | [02:19:38.014 *] OpenXR-Loader[02:19:38.015 *] ] : [02:19:38.015 *] Failed querying extension properties[02:19:38.015 *] 
[02:19:38.015 E] /build/source/components/xr/extensions.cpp:175: OpenXR[Error: XR_ERROR_RUNTIME_UNAVAILABLE][Thread: 140688100393024]: xrEnumerateInstanceExtensionProperties(layerName, availableExtensions.size(), &extensionCount, availableExtensions.data())
[02:19:38.015 V] Available Layers: 
[02:19:38.015 V]   No layers available
[02:19:38.015 W] Warning: Failed to select OpenGL swapchains: OpenXR runtime does not support essential extension 'XR_KHR_opengl_enable'
[02:19:38.015 V] Error: No graphics API supported by OpenMW VR is supported by the OpenXR runtime.
[02:19:38.020 E] Error: Error: No graphics API supported by OpenMW VR is supported by the OpenXR runtime.