summaryrefslogtreecommitdiffstats
path: root/flake.nix
blob: c9af124ce619d611533990075405fecfe1e76484 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
{
  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 <<EOF >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;
  };
}