summaryrefslogtreecommitdiff
path: root/os/srv/gaming.nix
blob: 7e9099d785bafb76730c76fa0c3f50fbad43de15 (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
{
  config,
  lib,
  pkgs,
  username,
  inputs,
  ...
}:
let
  cfg = config.os.srv.gaming;
in
{
  options.os.srv.gaming = {
    enable = lib.mkEnableOption "enables general gaming support";

    tools.enable = lib.mkEnableOption "enables performance tools" // {
      default = cfg.enable;
    };
    launchers.enable = lib.mkEnableOption "enables 3rd party launchers" // {
      default = cfg.enable;
    };
    games.enable = lib.mkEnableOption "enables specific native games";
    steam = {
      enable = lib.mkEnableOption "enables the steam launcher";
      enableSls = lib.mkEnableOption "enables the SLS Steam library modification";
    };
    vr.enable = lib.mkEnableOption "enables vr support";
  };

  config = lib.mkMerge [
    # --- PERFORMANCE & TOOLING ---
    (lib.mkIf cfg.tools.enable {
      programs.gamescope = {
        enable = true;
        capSysNice = true;
      };

      programs.gamemode = {
        enable = true;
        enableRenice = true;
        settings = {
          general.renice = 10;
        };
      };
      environment = {
        # sets the optiscaler shortcut key to be home by default
        sessionVariables = {
          OPTISCALER_ShortcutKey = "0x24";
        };

        systemPackages = with pkgs; [
          mangohud
          theclicker
          ludusavi
          protonplus
        ];
      };
    })

    # --- EXTERNAL LAUNCHERS ---
    (lib.mkIf cfg.launchers.enable {
      environment.systemPackages = with pkgs; [
        heroic
        # (pkgs.bottles.override { removeWarningPopup = true; })
        (prismlauncher.override {
          additionalLibs = with pkgs; [ ocl-icd ];
          jdks = with pkgs; [ javaPackages.compiler.temurin-bin.jdk-25 ];
        })
      ];
    })

    # --- SPECIFIC GAMES ---
    (lib.mkIf cfg.games.enable {
      environment.systemPackages = with inputs.openmw-nix.packages.${pkgs.stdenv.hostPlatform.system}; [
        (pkgs.openttd-jgrpp)

        # OpenMW Specific
        (pkgs.openmw)
        (pkgs.tes3cmd)
        delta-plugin
        groundcoverify
        momw-configurator
        openmw-validator
        s3lightfixes
        umo
      ];
    })

    # --- STEAM ---
    (lib.mkIf cfg.steam.enable (
      lib.mkMerge [
        {
          programs.steam = {
            enable = true;
            localNetworkGameTransfers.openFirewall = true;
            dedicatedServer.openFirewall = true;
            remotePlay.openFirewall = false;
            extest.enable = true;
            protontricks.enable = true;
          };
          environment.systemPackages = with pkgs; [ steamtinkerlaunch ];
        }

        (lib.mkIf cfg.steam.enableSls {
          home-manager.users.${username} = {
            imports = [ inputs.sls-steam.homeModules.sls-steam ];

            services.sls-steam.config = {
              DisableFamilyShareLock = true;
              SafeMode = false;
            };
            home.packages = [ inputs.sls-steam.packages.${pkgs.stdenv.hostPlatform.system}.wrapped ];

            xdg.desktopEntries = {
              steam = {
                name = "Steam";
                comment = "Library modified Steam client";
                exec = "${
                  lib.getExe' inputs.sls-steam.packages.${pkgs.stdenv.hostPlatform.system}.wrapped "SLSsteam"
                } %U";
                icon = "steam";
                terminal = false;
                type = "Application";
                categories = [
                  "Game"
                  "Utility"
                ];
                mimeType = [ "x-scheme-handler/steamcmd" ];
              };
            };
          };
        })
      ]
    ))

    # --- VR SUPPORT ---
    (lib.mkIf cfg.vr.enable {
      services.wivrn = {
        enable = true;
        openFirewall = true;
        highPriority = true;
        steam.importOXRRuntimes = true;
        # defaultRuntime = true;
      };
      environment.systemPackages = [ pkgs.android-tools ];
      users.users.${username}.extraGroups = [ "adbusers" ];
    })
  ];
}