me like nix
1{ ... }: {
2 flake.modules.nixos.gaming =
3 { pkgs, lib, ... }:
4 let
5 # Steam/gamescope calls steamos-session-select when the user presses
6 # "Switch to Desktop". Without this script, the button does nothing.
7 steamos-session-select = pkgs.writeShellScriptBin "steamos-session-select" ''
8 echo "Switching session to: $1"
9 '';
10
11 # Pin gamescope to 3.14.29 — versions 3.15+ crash on NVIDIA due to
12 # a confirmed driver bug (#5701801) in Vulkan YCbCr sampler pipeline compilation.
13 gamescope_3_14 = pkgs.gamescope.overrideAttrs (old: {
14 version = "3.14.29";
15 src = pkgs.fetchFromGitHub {
16 owner = "ValveSoftware";
17 repo = "gamescope";
18 tag = "3.14.29";
19 fetchSubmodules = true;
20 hash = "sha256-q3HEbFqUeNczKYUlou+quxawCTjpM5JNLrML84tZVYE=";
21 };
22 # Do not inherit nixpkgs' current gamescope patches: they track the
23 # current upstream version and can stop applying to this 3.14 pin.
24 patches = [ ];
25 mesonFlags = builtins.filter
26 (
27 f:
28 builtins.match ".*glm_include_dir.*" f == null
29 && builtins.match ".*stb_include_dir.*" f == null
30 )
31 (old.mesonFlags or [ ]);
32 env = (old.env or { }) // {
33 CMAKE_POLICY_VERSION_MINIMUM = "3.5";
34 };
35 NIX_CFLAGS_COMPILE = (old.NIX_CFLAGS_COMPILE or "") + " -Wno-error=switch";
36 postPatch = ''
37 substituteInPlace src/reshade_effect_manager.cpp \
38 --replace-fail 'return "/usr";' 'return "'$out'";'
39
40 substituteInPlace src/Utils/Process.cpp \
41 --replace-fail 'args.push_back( (char *)"gamescopereaper" );' \
42 'args.push_back( (char *)"'$out'/bin/gamescopereaper" );'
43
44 patchShebangs subprojects/libdisplay-info/tool/gen-search-table.py
45
46 rm -rf subprojects/glm subprojects/glm.wrap subprojects/stb subprojects/stb.wrap
47 mkdir -p subprojects/glm subprojects/stb
48
49 cat > subprojects/glm/meson.build << 'GLMEOF'
50 project('glm', 'cpp', version: '1.0.0')
51 glm_dep = declare_dependency(include_directories: include_directories('${lib.getInclude pkgs.glm}/include', is_system: true))
52 meson.override_dependency('glm', glm_dep)
53 GLMEOF
54
55 cat > subprojects/stb/meson.build << 'STBEOF'
56 project('stb', 'c', version: '0.0.1')
57 stb_dep = declare_dependency(include_directories: include_directories('${lib.getInclude pkgs.stb}/include/stb', is_system: true))
58 meson.override_dependency('stb', stb_dep)
59 STBEOF
60 '';
61 });
62 in
63 {
64 # ZRAM swap to prevent OOM freezes
65 zramSwap = {
66 enable = true;
67 memoryPercent = 50;
68 };
69
70 # Kill runaway processes before the system locks up
71 services.earlyoom = {
72 enable = true;
73 freeMemThreshold = 5;
74 freeSwapThreshold = 5;
75 enableNotifications = true;
76 };
77
78 programs.steam = {
79 enable = true;
80 remotePlay.openFirewall = true;
81 gamescopeSession = {
82 enable = true;
83 args = [
84 "-r"
85 "120"
86 "-R"
87 "120"
88 ];
89 env = {
90 STEAM_DESKTOP_SESSION = "niri";
91 ENABLE_GAMESCOPE_WSI = "1";
92 };
93 };
94 extraCompatPackages = with pkgs; [
95 proton-ge-bin
96 ];
97 };
98
99 programs.gamemode.enable = true;
100
101 programs.gamescope = {
102 enable = true;
103 capSysNice = false;
104 package = gamescope_3_14;
105 };
106
107 environment.systemPackages = [
108 steamos-session-select
109 ];
110
111 boot.kernelParams = [ "split_lock_mitigate=0" ];
112
113 security.pam.loginLimits = [
114 {
115 domain = "*";
116 type = "soft";
117 item = "nofile";
118 value = "8192";
119 }
120 ];
121 };
122}