typioca: 2.7.0 -> 2.8.0
[NixPkgs.git] / nixos / modules / programs / gamescope.nix
bloba31295e736df2b6f5283b198731751ce77527bdd
1 { config
2 , lib
3 , pkgs
4 , ...
5 }:
6 with lib; let
7   cfg = config.programs.gamescope;
9   gamescope =
10     let
11       wrapperArgs =
12         optional (cfg.args != [ ])
13           ''--add-flags "${toString cfg.args}"''
14         ++ builtins.attrValues (mapAttrs (var: val: "--set-default ${var} ${val}") cfg.env);
15     in
16     pkgs.runCommand "gamescope" { nativeBuildInputs = [ pkgs.makeBinaryWrapper ]; } ''
17       mkdir -p $out/bin
18       makeWrapper ${cfg.package}/bin/gamescope $out/bin/gamescope --inherit-argv0 \
19         ${toString wrapperArgs}
20     '';
23   options.programs.gamescope = {
24     enable = mkEnableOption (mdDoc "gamescope");
26     package = mkOption {
27       type = types.package;
28       default = pkgs.gamescope;
29       defaultText = literalExpression "pkgs.gamescope";
30       description = mdDoc ''
31         The GameScope package to use.
32       '';
33     };
35     capSysNice = mkOption {
36       type = types.bool;
37       default = false;
38       description = mdDoc ''
39         Add cap_sys_nice capability to the GameScope
40         binary so that it may renice itself.
41       '';
42     };
44     args = mkOption {
45       type = types.listOf types.str;
46       default = [ ];
47       example = [ "--rt" "--prefer-vk-device 8086:9bc4" ];
48       description = mdDoc ''
49         Arguments passed to GameScope on startup.
50       '';
51     };
53     env = mkOption {
54       type = types.attrsOf types.str;
55       default = { };
56       example = literalExpression ''
57         # for Prime render offload on Nvidia laptops.
58         # Also requires `hardware.nvidia.prime.offload.enable`.
59         {
60           __NV_PRIME_RENDER_OFFLOAD = "1";
61           __VK_LAYER_NV_optimus = "NVIDIA_only";
62           __GLX_VENDOR_LIBRARY_NAME = "nvidia";
63         }
64       '';
65       description = mdDoc ''
66         Default environment variables available to the GameScope process, overridable at runtime.
67       '';
68     };
69   };
71   config = mkIf cfg.enable {
72     security.wrappers = mkIf cfg.capSysNice {
73       gamescope = {
74         owner = "root";
75         group = "root";
76         source = "${gamescope}/bin/gamescope";
77         capabilities = "cap_sys_nice+pie";
78       };
79     };
81     environment.systemPackages = mkIf (!cfg.capSysNice) [ gamescope ];
82   };
84   meta.maintainers = with maintainers; [ nrdxp ];