at 24.11-pre 2.2 kB view raw
1{ config 2, lib 3, pkgs 4, ... 5}: 6let 7 cfg = config.programs.gamescope; 8 9 gamescope = 10 let 11 wrapperArgs = 12 lib.optional (cfg.args != [ ]) 13 ''--add-flags "${builtins.toString cfg.args}"'' 14 ++ builtins.attrValues (builtins.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 ${builtins.toString wrapperArgs} 20 ''; 21in 22{ 23 options.programs.gamescope = { 24 enable = lib.mkEnableOption "gamescope, the SteamOS session compositing window manager"; 25 26 package = lib.mkPackageOption pkgs "gamescope" { }; 27 28 capSysNice = lib.mkOption { 29 type = lib.types.bool; 30 default = false; 31 description = '' 32 Add cap_sys_nice capability to the GameScope 33 binary so that it may renice itself. 34 ''; 35 }; 36 37 args = lib.mkOption { 38 type = lib.types.listOf lib.types.str; 39 default = [ ]; 40 example = [ "--rt" "--prefer-vk-device 8086:9bc4" ]; 41 description = '' 42 Arguments passed to GameScope on startup. 43 ''; 44 }; 45 46 env = lib.mkOption { 47 type = lib.types.attrsOf lib.types.str; 48 default = { }; 49 example = lib.literalExpression '' 50 # for Prime render offload on Nvidia laptops. 51 # Also requires `hardware.nvidia.prime.offload.enable`. 52 { 53 __NV_PRIME_RENDER_OFFLOAD = "1"; 54 __VK_LAYER_NV_optimus = "NVIDIA_only"; 55 __GLX_VENDOR_LIBRARY_NAME = "nvidia"; 56 } 57 ''; 58 description = '' 59 Default environment variables available to the GameScope process, overridable at runtime. 60 ''; 61 }; 62 }; 63 64 config = lib.mkIf cfg.enable { 65 security.wrappers = lib.mkIf cfg.capSysNice { 66 gamescope = { 67 owner = "root"; 68 group = "root"; 69 source = "${gamescope}/bin/gamescope"; 70 capabilities = "cap_sys_nice+pie"; 71 }; 72 }; 73 74 environment.systemPackages = lib.mkIf (!cfg.capSysNice) [ gamescope ]; 75 }; 76 77 meta.maintainers = with lib.maintainers; [ nrdxp ]; 78}