nixpkgs/nixos/modules/programs/gamescope.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.2 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
...
2022-08-19 19:16:51 +00:00
}:
let
2022-08-19 19:16:51 +00:00
cfg = config.programs.gamescope;
gamescope =
let
wrapperArgs =
lib.optional (cfg.args != [ ]) ''--add-flags "${builtins.toString cfg.args}"''
++ builtins.attrValues (builtins.mapAttrs (var: val: "--set-default ${var} ${val}") cfg.env);
2022-08-19 19:16:51 +00:00
in
pkgs.runCommand "gamescope" { nativeBuildInputs = [ pkgs.makeBinaryWrapper ]; } ''
mkdir -p $out/bin
makeWrapper ${cfg.package}/bin/gamescope $out/bin/gamescope --inherit-argv0 \
${builtins.toString wrapperArgs}
2024-08-26 11:32:36 +00:00
ln -s ${cfg.package}/bin/gamescopectl $out/bin/gamescopectl
2022-08-19 19:16:51 +00:00
'';
in
{
options.programs.gamescope = {
enable = lib.mkEnableOption "gamescope, the SteamOS session compositing window manager";
2022-08-19 19:16:51 +00:00
package = lib.mkPackageOption pkgs "gamescope" { };
2022-08-19 19:16:51 +00:00
capSysNice = lib.mkOption {
type = lib.types.bool;
2022-08-19 19:16:51 +00:00
default = false;
description = ''
Add cap_sys_nice capability to the GameScope
binary so that it may renice itself.
2022-08-19 19:16:51 +00:00
'';
};
args = lib.mkOption {
type = lib.types.listOf lib.types.str;
2022-08-19 19:16:51 +00:00
default = [ ];
example = [
"--rt"
"--prefer-vk-device 8086:9bc4"
];
2022-08-19 19:16:51 +00:00
description = ''
Arguments passed to GameScope on startup.
'';
};
env = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
2022-08-19 19:16:51 +00:00
default = { };
example = lib.literalExpression ''
2022-08-19 19:16:51 +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";
}
'';
description = ''
Default environment variables available to the GameScope process, overridable at runtime.
'';
};
};
config = lib.mkIf cfg.enable {
security.wrappers = lib.mkIf cfg.capSysNice {
2022-08-19 19:16:51 +00:00
gamescope = {
owner = "root";
group = "root";
source = "${gamescope}/bin/gamescope";
capabilities = "cap_sys_nice+pie";
};
};
environment.systemPackages = lib.mkIf (!cfg.capSysNice) [ gamescope ];
2022-08-19 19:16:51 +00:00
};
meta.maintainers = with lib.maintainers; [ nrdxp ];
2022-08-19 19:16:51 +00:00
}