summaryrefslogtreecommitdiff
path: root/pkgs/by-name/ga/gamescope/package.nix
blob: 54b9f62619724a84adb29807467c4f5b0c0f8033 (about) (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
{
  stdenv,
  buildPackages,
  edid-decode,
  fetchFromGitHub,
  meson,
  pkg-config,
  ninja,
  cmake,
  xorg,
  libdrm,
  libei,
  vulkan-loader,
  vulkan-headers,
  wayland,
  wayland-protocols,
  wayland-scanner,
  libxkbcommon,
  glm,
  gbenchmark,
  libcap,
  libavif,
  SDL2,
  pipewire,
  pixman,
  python3,
  libinput,
  glslang,
  hwdata,
  stb,
  wlroots,
  libdecor,
  lcms,
  lib,
  luajit,
  makeBinaryWrapper,
  nix-update-script,
  enableExecutable ? true,
  enableWsi ? true,
}:
let
  frogShaders = fetchFromGitHub {
    owner = "misyltoad";
    repo = "GamescopeShaders";
    rev = "v0.1";
    hash = "sha256-gR1AeAHV/Kn4ntiEDUSPxASLMFusV6hgSGrTbMCBUZA=";
  };
in
stdenv.mkDerivation (finalAttrs: {
  pname = "gamescope";
  version = "3.16.3";

  src = fetchFromGitHub {
    owner = "ValveSoftware";
    repo = "gamescope";
    tag = finalAttrs.version;
    fetchSubmodules = true;
    hash = "sha256-4Pbyv+EAgwjabVJ4oW3jSmi0Rzpe+BxCN8mM5/beEco=";
  };

  patches = [
    # Make it look for data in the right place
    ./shaders-path.patch
    # patch relative gamescopereaper path with absolute
    ./gamescopereaper.patch
  ];

  # We can't substitute the patch itself because substituteAll is itself a derivation,
  # so `placeholder "out"` ends up pointing to the wrong place
  postPatch = ''
    substituteInPlace src/reshade_effect_manager.cpp --replace-fail "@out@" "$out"

    # Patching shebangs in the main `libdisplay-info` build
    patchShebangs subprojects/libdisplay-info/tool/gen-search-table.py

    # Replace gamescopereeaper with absolute path
    substituteInPlace src/Utils/Process.cpp --subst-var-by "gamescopereaper" "$out/bin/gamescopereaper"
    patchShebangs default_scripts_install.sh
  '';

  mesonFlags = [
    (lib.mesonBool "enable_gamescope" enableExecutable)
    (lib.mesonBool "enable_gamescope_wsi_layer" enableWsi)
  ];

  # don't install vendored vkroots etc
  mesonInstallFlags = [ "--skip-subprojects" ];

  strictDeps = true;

  depsBuildBuild = [
    pkg-config
  ];

  nativeBuildInputs =
    [
      meson
      pkg-config
      ninja
      wayland-scanner
      # For `libdisplay-info`
      python3
      hwdata
      edid-decode
      # For OpenVR
      cmake

      # calls git describe to encode its own version into the build
      (buildPackages.writeShellScriptBin "git" "echo ${finalAttrs.version}")
    ]
    ++ lib.optionals enableExecutable [
      makeBinaryWrapper
      glslang
    ];

  buildInputs =
    [
      pipewire
      hwdata
      xorg.libX11
      wayland
      wayland-protocols
      vulkan-loader
      glm
      luajit
    ]
    ++ lib.optionals enableWsi [
      vulkan-headers
    ]
    ++ lib.optionals enableExecutable (
      wlroots.buildInputs
      ++ [
        # gamescope uses a custom wlroots branch
        xorg.libXcomposite
        xorg.libXcursor
        xorg.libXdamage
        xorg.libXext
        xorg.libXi
        xorg.libXmu
        xorg.libXrender
        xorg.libXres
        xorg.libXtst
        xorg.libXxf86vm
        libavif
        libdrm
        libei
        SDL2
        libdecor
        libinput
        libxkbcommon
        gbenchmark
        pixman
        libcap
        stb
        lcms
      ]
    );

  postInstall = lib.optionalString enableExecutable ''
    # using patchelf unstable because the stable version corrupts the binary
    ${lib.getExe buildPackages.patchelfUnstable} $out/bin/gamescope \
      --add-rpath ${vulkan-loader}/lib --add-needed libvulkan.so.1

    # --debug-layers flag expects these in the path
    wrapProgram "$out/bin/gamescope" \
      --prefix PATH : ${
        with xorg;
        lib.makeBinPath [
          xprop
          xwininfo
        ]
      }

    # Install ReShade shaders
    mkdir -p $out/share/gamescope/reshade
    cp -r ${frogShaders}/* $out/share/gamescope/reshade/
  '';

  passthru.updateScript = nix-update-script { };

  meta = {
    description = "SteamOS session compositing window manager";
    homepage = "https://github.com/ValveSoftware/gamescope";
    license = lib.licenses.bsd2;
    maintainers = with lib.maintainers; [
      pedrohlc
      Scrumplex
      zhaofengli
      k900
      Gliczy
    ];
    platforms = lib.platforms.linux;
    mainProgram = "gamescope";
  };
})