{ description = "VR experiments with OpenXR, Vulkan and Zig"; inputs = { nixpkgs.url = github:NixOS/nixpkgs/master; monado-src = { url = git+https://gitlab.freedesktop.org/monado/monado.git; flake = false; }; diligent-core-src = { url = github:DiligentGraphics/DiligentCore; flake = false; }; }; outputs = { self, nixpkgs, monado-src, diligent-core-src }: rec { packages.x86_64-linux = with import nixpkgs { system = "x86_64-linux"; }; { diligent-core = stdenv.mkDerivation { name = "DiligentCore"; src = diligent-core-src; nativeBuildInputs = with pkgs; [ cmake clang vulkan-headers mesa xorg.libxcb xorg.libX11 git python3 ]; configurePhase = '' cat <BuildConfig.cmake function(custom_post_configure_target TARGET) set_target_properties(''${TARGET} PROPERTIES LINK_OPTIONS -static-libstdc++) endfunction() EOF mkdir build cd build cmake .. \ -D CMAKE_INSTALL_PREFIX=install \ -D CMAKE_BUILD_TYPE=RelWithDebInfo \ -D BUILD_CONFIGURATION_FILE=BuildConfig.cmake \ -D DILIGENT_NO_DIRECT3D11=ON \ -D DILIGENT_NO_DIRECT3D12=ON \ -D DILIGENT_NO_OPENGL=ON \ -D DILIGENT_NO_METAL=ON \ -D DILIGENT_NO_GLSLANG=ON \ -D DILIGENT_NO_HLSL=ON \ -D DILIGENT_NO_FORMAT_VALIDATION=ON ''; buildPhase = '' make -j$NIX_BUILD_CORES ''; installPhase = '' make install cp -r install/{lib,include} "$out"/ ''; }; monado = stdenv.mkDerivation { name = "monado"; src = monado-src; nativeBuildInputs = with pkgs; [ cmake clang vulkan-headers mesa libusb libudev glslang eigen openhmd wayland-protocols wayland hidapi opencv zlib pkgconfig libjpeg egl-wayland vulkan-loader python3 ]; configurePhase = '' mkdir build cd build cmake .. ''; buildPhase = '' make ''; installPhase = '' make DESTDIR=. install mkdir -p $out/etc "$out/bin" mv var/empty/local/* "$out/" mv etc/var/empty/local "$out/etc" substituteInPlace $out/lib/systemd/user/monado.service \ --replace "/var/empty/local" "$out" substituteInPlace $out/share/openxr/1/openxr_monado.json \ --replace "/var/empty/local" "$out" ''; }; openxPriments = stdenv.mkDerivation { name = "openxPriments"; src = self; buildInputs = [ packages.x86_64-linux.monado ]; nativeBuildInputs = with pkgs; [ vulkan-headers vulkan-loader openxr-loader gdb zig ]; LD_LIBRARY_PATH = with pkgs; lib.strings.makeLibraryPath [ vulkan-loader stdenv.cc.cc.lib ]; XR_RUNTIME_JSON = "${packages.x86_64-linux.monado}/share/openxr/1/openxr_monado.json"; configurePhase = ""; buildPhase = '' zig build ''; installPhase = '' mkdir -p $out/bin install -t $out/bin zig-cache/bin/openxPriments ''; }; }; defaultPackage.x86_64-linux = self.packages.x86_64-linux.openxPriments; }; }