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

steam: add extraEnv argument
This commit is contained in:
Atemu 2023-03-28 17:25:14 +02:00 committed by GitHub
commit 91f5aa3446
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 24 deletions

View file

@ -9,23 +9,36 @@ in {
enable = mkEnableOption (lib.mdDoc "steam");
package = mkOption {
type = types.package;
default = pkgs.steam.override {
extraLibraries = pkgs: with config.hardware.opengl;
if pkgs.stdenv.hostPlatform.is64bit
then [ package ] ++ extraPackages
else [ package32 ] ++ extraPackages32;
};
defaultText = literalExpression ''
pkgs.steam.override {
extraLibraries = pkgs: with config.hardware.opengl;
type = types.package;
default = pkgs.steam;
defaultText = literalExpression "pkgs.steam";
example = literalExpression ''
pkgs.steam-small.override {
extraEnv = {
MANGOHUD = true;
OBS_VKCAPTURE = true;
RADV_TEX_ANISO = 16;
};
extraLibraries = p: with p; [
atk
];
}
'';
apply = steam: steam.override (prev: {
extraLibraries = pkgs: let
prevLibs = if prev ? extraLibraries then prev.extraLibraries pkgs else [ ];
additionalLibs = with config.hardware.opengl;
if pkgs.stdenv.hostPlatform.is64bit
then [ package ] ++ extraPackages
else [ package32 ] ++ extraPackages32;
}
'';
in prevLibs ++ additionalLibs;
});
description = lib.mdDoc ''
steam package to use.
The Steam package to use. Additional libraries are added from the system
configuration to ensure graphics work properly.
Use this option to customise the Steam package rather than adding your
custom Steam to {option}`environment.systemPackages` yourself.
'';
};

View file

@ -1,6 +1,6 @@
{ stdenv, lib, buildEnv, writeText, writeShellScriptBin, pkgs, pkgsi686Linux }:
{ name, profile ? ""
args@{ name, profile ? ""
, targetPkgs ? pkgs: [], multiPkgs ? pkgs: []
, extraBuildCommands ? "", extraBuildCommandsMulti ? ""
, extraOutputsToInstall ? []
@ -216,4 +216,8 @@ in stdenv.mkDerivation {
'';
preferLocalBuild = true;
allowSubstitutes = false;
passthru = {
inherit args multiPaths targetPaths;
};
}

View file

@ -20,9 +20,9 @@ args @ {
with builtins;
let
buildFHSEnv = callPackage ./env.nix { };
buildFHSEnv = callPackage ./buildFHSEnv.nix { };
env = buildFHSEnv (removeAttrs args [
fhsenv = buildFHSEnv (removeAttrs args [
"runScript" "extraInstallCommands" "meta" "passthru" "extraBwrapArgs" "dieWithParent"
"unshareUser" "unshareCgroup" "unshareUts" "unshareNet" "unsharePid" "unshareIpc"
"version"
@ -104,7 +104,7 @@ let
ro_mounts=()
symlinks=()
etc_ignored=()
for i in ${env}/*; do
for i in ${fhsenv}/*; do
path="/''${i##*/}"
if [[ $path == '/etc' ]]; then
:
@ -117,8 +117,8 @@ let
fi
done
if [[ -d ${env}/etc ]]; then
for i in ${env}/etc/*; do
if [[ -d ${fhsenv}/etc ]]; then
for i in ${fhsenv}/etc/*; do
path="/''${i##*/}"
# NOTE: we're binding /etc/fonts and /etc/ssl/certs from the host so we
# don't want to override it with a path from the FHS environment.
@ -221,6 +221,7 @@ in runCommandLocal nameAndVersion {
echo >&2 ""
exit 1
'';
inherit args fhsenv;
};
} ''
mkdir -p $out/bin

View file

@ -1,9 +1,10 @@
{ lib, stdenv, writeScript, buildFHSUserEnv, steam, glxinfo-i686, runtimeShell
{ lib, stdenv, writeShellScript, buildFHSUserEnv, steam, glxinfo-i686
, steam-runtime-wrapped, steam-runtime-wrapped-i686 ? null
, extraPkgs ? pkgs: [ ] # extra packages to add to targetPkgs
, extraLibraries ? pkgs: [ ] # extra packages to add to multiPkgs
, extraProfile ? "" # string to append to profile
, extraArgs ? "" # arguments to always pass to steam
, extraEnv ? { } # Environment variables to pass to Steam
, withGameSpecificLibraries ? true # exclude game specific libraries
}:
@ -52,6 +53,8 @@ let
fi
'';
envScript = lib.toShellVars extraEnv;
in buildFHSUserEnv rec {
name = "steam";
@ -228,8 +231,7 @@ in buildFHSUserEnv rec {
export SDL_JOYSTICK_DISABLE_UDEV=1
'' + extraProfile;
runScript = writeScript "steam-wrapper.sh" ''
#!${runtimeShell}
runScript = writeShellScript "steam-wrapper.sh" ''
if [ -f /host/etc/NIXOS ]; then # Check only useful on NixOS
${glxinfo-i686}/bin/glxinfo >/dev/null 2>&1
# If there was an error running glxinfo, we know something is wrong with the configuration
@ -249,6 +251,9 @@ in buildFHSUserEnv rec {
${exportLDPath}
${fixBootstrap}
set -o allexport # Export the following env vars
${envScript}
exec steam ${extraArgs} "$@"
'';
@ -272,8 +277,7 @@ in buildFHSUserEnv rec {
inherit multiPkgs profile extraInstallCommands;
inherit unshareIpc unsharePid;
runScript = writeScript "steam-run" ''
#!${runtimeShell}
runScript = writeShellScript "steam-run" ''
run="$1"
if [ "$run" = "" ]; then
echo "Usage: steam-run command-to-run args..." >&2
@ -283,6 +287,9 @@ in buildFHSUserEnv rec {
${exportLDPath}
${fixBootstrap}
set -o allexport # Export the following env vars
${envScript}
exec -- "$run" "$@"
'';