Merge pull request #213378 from Atemu/steam-env-vars

steam: add extraEnv argument

authored by

Atemu and committed by
GitHub
91f5aa34 2e0bb262

+49 -24
+26 -13
nixos/modules/programs/steam.nix
··· 9 9 enable = mkEnableOption (lib.mdDoc "steam"); 10 10 11 11 package = mkOption { 12 - type = types.package; 13 - default = pkgs.steam.override { 14 - extraLibraries = pkgs: with config.hardware.opengl; 15 - if pkgs.stdenv.hostPlatform.is64bit 16 - then [ package ] ++ extraPackages 17 - else [ package32 ] ++ extraPackages32; 18 - }; 19 - defaultText = literalExpression '' 20 - pkgs.steam.override { 21 - extraLibraries = pkgs: with config.hardware.opengl; 12 + type = types.package; 13 + default = pkgs.steam; 14 + defaultText = literalExpression "pkgs.steam"; 15 + example = literalExpression '' 16 + pkgs.steam-small.override { 17 + extraEnv = { 18 + MANGOHUD = true; 19 + OBS_VKCAPTURE = true; 20 + RADV_TEX_ANISO = 16; 21 + }; 22 + extraLibraries = p: with p; [ 23 + atk 24 + ]; 25 + } 26 + ''; 27 + apply = steam: steam.override (prev: { 28 + extraLibraries = pkgs: let 29 + prevLibs = if prev ? extraLibraries then prev.extraLibraries pkgs else [ ]; 30 + additionalLibs = with config.hardware.opengl; 22 31 if pkgs.stdenv.hostPlatform.is64bit 23 32 then [ package ] ++ extraPackages 24 33 else [ package32 ] ++ extraPackages32; 25 - } 26 - ''; 34 + in prevLibs ++ additionalLibs; 35 + }); 27 36 description = lib.mdDoc '' 28 - steam package to use. 37 + The Steam package to use. Additional libraries are added from the system 38 + configuration to ensure graphics work properly. 39 + 40 + Use this option to customise the Steam package rather than adding your 41 + custom Steam to {option}`environment.systemPackages` yourself. 29 42 ''; 30 43 }; 31 44
+6 -5
pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix
··· 20 20 21 21 with builtins; 22 22 let 23 - buildFHSEnv = callPackage ./env.nix { }; 23 + buildFHSEnv = callPackage ./buildFHSEnv.nix { }; 24 24 25 - env = buildFHSEnv (removeAttrs args [ 25 + fhsenv = buildFHSEnv (removeAttrs args [ 26 26 "runScript" "extraInstallCommands" "meta" "passthru" "extraBwrapArgs" "dieWithParent" 27 27 "unshareUser" "unshareCgroup" "unshareUts" "unshareNet" "unsharePid" "unshareIpc" 28 28 "version" ··· 104 104 ro_mounts=() 105 105 symlinks=() 106 106 etc_ignored=() 107 - for i in ${env}/*; do 107 + for i in ${fhsenv}/*; do 108 108 path="/''${i##*/}" 109 109 if [[ $path == '/etc' ]]; then 110 110 : ··· 117 117 fi 118 118 done 119 119 120 - if [[ -d ${env}/etc ]]; then 121 - for i in ${env}/etc/*; do 120 + if [[ -d ${fhsenv}/etc ]]; then 121 + for i in ${fhsenv}/etc/*; do 122 122 path="/''${i##*/}" 123 123 # NOTE: we're binding /etc/fonts and /etc/ssl/certs from the host so we 124 124 # don't want to override it with a path from the FHS environment. ··· 221 221 echo >&2 "" 222 222 exit 1 223 223 ''; 224 + inherit args fhsenv; 224 225 }; 225 226 } '' 226 227 mkdir -p $out/bin
+5 -1
pkgs/build-support/build-fhs-userenv-bubblewrap/env.nix pkgs/build-support/build-fhs-userenv-bubblewrap/buildFHSEnv.nix
··· 1 1 { stdenv, lib, buildEnv, writeText, writeShellScriptBin, pkgs, pkgsi686Linux }: 2 2 3 - { name, profile ? "" 3 + args@{ name, profile ? "" 4 4 , targetPkgs ? pkgs: [], multiPkgs ? pkgs: [] 5 5 , extraBuildCommands ? "", extraBuildCommandsMulti ? "" 6 6 , extraOutputsToInstall ? [] ··· 216 216 ''; 217 217 preferLocalBuild = true; 218 218 allowSubstitutes = false; 219 + 220 + passthru = { 221 + inherit args multiPaths targetPaths; 222 + }; 219 223 }
+12 -5
pkgs/games/steam/fhsenv.nix
··· 1 - { lib, stdenv, writeScript, buildFHSUserEnv, steam, glxinfo-i686, runtimeShell 1 + { lib, stdenv, writeShellScript, buildFHSUserEnv, steam, glxinfo-i686 2 2 , steam-runtime-wrapped, steam-runtime-wrapped-i686 ? null 3 3 , extraPkgs ? pkgs: [ ] # extra packages to add to targetPkgs 4 4 , extraLibraries ? pkgs: [ ] # extra packages to add to multiPkgs 5 5 , extraProfile ? "" # string to append to profile 6 6 , extraArgs ? "" # arguments to always pass to steam 7 + , extraEnv ? { } # Environment variables to pass to Steam 7 8 , withGameSpecificLibraries ? true # exclude game specific libraries 8 9 }: 9 10 ··· 51 52 chmod +w $HOME/.local/share/Steam/bootstrap.tar.xz 52 53 fi 53 54 ''; 55 + 56 + envScript = lib.toShellVars extraEnv; 54 57 55 58 in buildFHSUserEnv rec { 56 59 name = "steam"; ··· 228 231 export SDL_JOYSTICK_DISABLE_UDEV=1 229 232 '' + extraProfile; 230 233 231 - runScript = writeScript "steam-wrapper.sh" '' 232 - #!${runtimeShell} 234 + runScript = writeShellScript "steam-wrapper.sh" '' 233 235 if [ -f /host/etc/NIXOS ]; then # Check only useful on NixOS 234 236 ${glxinfo-i686}/bin/glxinfo >/dev/null 2>&1 235 237 # If there was an error running glxinfo, we know something is wrong with the configuration ··· 249 251 250 252 ${exportLDPath} 251 253 ${fixBootstrap} 254 + 255 + set -o allexport # Export the following env vars 256 + ${envScript} 252 257 exec steam ${extraArgs} "$@" 253 258 ''; 254 259 ··· 272 277 inherit multiPkgs profile extraInstallCommands; 273 278 inherit unshareIpc unsharePid; 274 279 275 - runScript = writeScript "steam-run" '' 276 - #!${runtimeShell} 280 + runScript = writeShellScript "steam-run" '' 277 281 run="$1" 278 282 if [ "$run" = "" ]; then 279 283 echo "Usage: steam-run command-to-run args..." >&2 ··· 283 287 284 288 ${exportLDPath} 285 289 ${fixBootstrap} 290 + 291 + set -o allexport # Export the following env vars 292 + ${envScript} 286 293 exec -- "$run" "$@" 287 294 ''; 288 295