2023-04-29 16:46:19 +00:00
|
|
|
{ config
|
|
|
|
, lib
|
|
|
|
, pkgs
|
|
|
|
, ...
|
|
|
|
}:
|
2024-05-15 15:35:15 +00:00
|
|
|
let
|
2023-04-29 16:46:19 +00:00
|
|
|
cfg = config.programs.gamescope;
|
|
|
|
|
|
|
|
gamescope =
|
|
|
|
let
|
|
|
|
wrapperArgs =
|
2024-05-15 15:35:15 +00:00
|
|
|
lib.optional (cfg.args != [ ])
|
|
|
|
''--add-flags "${builtins.toString cfg.args}"''
|
|
|
|
++ builtins.attrValues (builtins.mapAttrs (var: val: "--set-default ${var} ${val}") cfg.env);
|
2023-04-29 16:46:19 +00:00
|
|
|
in
|
|
|
|
pkgs.runCommand "gamescope" { nativeBuildInputs = [ pkgs.makeBinaryWrapper ]; } ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
makeWrapper ${cfg.package}/bin/gamescope $out/bin/gamescope --inherit-argv0 \
|
2024-05-15 15:35:15 +00:00
|
|
|
${builtins.toString wrapperArgs}
|
2023-04-29 16:46:19 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.programs.gamescope = {
|
2024-05-15 15:35:15 +00:00
|
|
|
enable = lib.mkEnableOption "gamescope, the SteamOS session compositing window manager";
|
2023-04-29 16:46:19 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
package = lib.mkPackageOption pkgs "gamescope" { };
|
2023-04-29 16:46:19 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
capSysNice = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2023-04-29 16:46:19 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-04-29 16:46:19 +00:00
|
|
|
Add cap_sys_nice capability to the GameScope
|
|
|
|
binary so that it may renice itself.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
args = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
2023-04-29 16:46:19 +00:00
|
|
|
default = [ ];
|
|
|
|
example = [ "--rt" "--prefer-vk-device 8086:9bc4" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-04-29 16:46:19 +00:00
|
|
|
Arguments passed to GameScope on startup.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
env = lib.mkOption {
|
|
|
|
type = lib.types.attrsOf lib.types.str;
|
2023-04-29 16:46:19 +00:00
|
|
|
default = { };
|
2024-05-15 15:35:15 +00:00
|
|
|
example = lib.literalExpression ''
|
2023-04-29 16:46:19 +00:00
|
|
|
# for Prime render offload on Nvidia laptops.
|
|
|
|
# Also requires `hardware.nvidia.prime.offload.enable`.
|
|
|
|
{
|
|
|
|
__NV_PRIME_RENDER_OFFLOAD = "1";
|
|
|
|
__VK_LAYER_NV_optimus = "NVIDIA_only";
|
|
|
|
__GLX_VENDOR_LIBRARY_NAME = "nvidia";
|
|
|
|
}
|
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-04-29 16:46:19 +00:00
|
|
|
Default environment variables available to the GameScope process, overridable at runtime.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
security.wrappers = lib.mkIf cfg.capSysNice {
|
2023-04-29 16:46:19 +00:00
|
|
|
gamescope = {
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
|
|
|
source = "${gamescope}/bin/gamescope";
|
|
|
|
capabilities = "cap_sys_nice+pie";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
environment.systemPackages = lib.mkIf (!cfg.capSysNice) [ gamescope ];
|
2023-04-29 16:46:19 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ nrdxp ];
|
2023-04-29 16:46:19 +00:00
|
|
|
}
|