1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.programs.steam;
7in {
8 options.programs.steam = {
9 enable = mkEnableOption (lib.mdDoc "steam");
10
11 package = mkOption {
12 type = types.package;
13 default = pkgs.steam.override {
14 extraLibraries = pkgs: with config.hardware.opengl;
15 if pkgs.hostPlatform.is64bit
16 then [ package ] ++ extraPackages
17 else [ package32 ] ++ extraPackages32;
18 };
19 defaultText = literalExpression ''
20 pkgs.steam.override {
21 extraLibraries = pkgs: with config.hardware.opengl;
22 if pkgs.hostPlatform.is64bit
23 then [ package ] ++ extraPackages
24 else [ package32 ] ++ extraPackages32;
25 }
26 '';
27 description = lib.mdDoc ''
28 steam package to use.
29 '';
30 };
31
32 remotePlay.openFirewall = mkOption {
33 type = types.bool;
34 default = false;
35 description = lib.mdDoc ''
36 Open ports in the firewall for Steam Remote Play.
37 '';
38 };
39
40 dedicatedServer.openFirewall = mkOption {
41 type = types.bool;
42 default = false;
43 description = lib.mdDoc ''
44 Open ports in the firewall for Source Dedicated Server.
45 '';
46 };
47 };
48
49 config = mkIf cfg.enable {
50 hardware.opengl = { # this fixes the "glXChooseVisual failed" bug, context: https://github.com/NixOS/nixpkgs/issues/47932
51 enable = true;
52 driSupport = true;
53 driSupport32Bit = true;
54 };
55
56 # optionally enable 32bit pulseaudio support if pulseaudio is enabled
57 hardware.pulseaudio.support32Bit = config.hardware.pulseaudio.enable;
58
59 hardware.steam-hardware.enable = true;
60
61 environment.systemPackages = [
62 cfg.package
63 cfg.package.run
64 ];
65
66 networking.firewall = lib.mkMerge [
67 (mkIf cfg.remotePlay.openFirewall {
68 allowedTCPPorts = [ 27036 ];
69 allowedUDPPortRanges = [ { from = 27031; to = 27036; } ];
70 })
71
72 (mkIf cfg.dedicatedServer.openFirewall {
73 allowedTCPPorts = [ 27015 ]; # SRCDS Rcon port
74 allowedUDPPorts = [ 27015 ]; # Gameplay traffic
75 })
76 ];
77 };
78
79 meta.maintainers = with maintainers; [ mkg20001 ];
80}