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