2023-04-29 16:46:19 +00:00
|
|
|
{ config
|
|
|
|
, lib
|
|
|
|
, pkgs
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.programs.gamescope;
|
|
|
|
|
|
|
|
gamescope =
|
|
|
|
let
|
|
|
|
wrapperArgs =
|
|
|
|
optional (cfg.args != [ ])
|
|
|
|
''--add-flags "${toString cfg.args}"''
|
|
|
|
++ builtins.attrValues (mapAttrs (var: val: "--set-default ${var} ${val}") cfg.env);
|
|
|
|
in
|
|
|
|
pkgs.runCommand "gamescope" { nativeBuildInputs = [ pkgs.makeBinaryWrapper ]; } ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
makeWrapper ${cfg.package}/bin/gamescope $out/bin/gamescope --inherit-argv0 \
|
|
|
|
${toString wrapperArgs}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.programs.gamescope = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "gamescope, the SteamOS session compositing window manager";
|
2023-04-29 16:46:19 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "gamescope" { };
|
2023-04-29 16:46:19 +00:00
|
|
|
|
|
|
|
capSysNice = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
args = mkOption {
|
2023-08-10 07:59:29 +00:00
|
|
|
type = types.listOf 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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
env = mkOption {
|
2023-08-10 07:59:29 +00:00
|
|
|
type = types.attrsOf types.str;
|
2023-04-29 16:46:19 +00:00
|
|
|
default = { };
|
|
|
|
example = literalExpression ''
|
|
|
|
# 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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
security.wrappers = mkIf cfg.capSysNice {
|
|
|
|
gamescope = {
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
|
|
|
source = "${gamescope}/bin/gamescope";
|
|
|
|
capabilities = "cap_sys_nice+pie";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = mkIf (!cfg.capSysNice) [ gamescope ];
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ nrdxp ];
|
|
|
|
}
|